Need help in Python automation

2014-03-21 Thread Anil Kumar A
-
Hi All,

I work for an ISP. Currently we bought few switches and routers. Python is 
available in that switches. So I would like to write some scipts which I can 
run inside switch. 

I tried module 'os, system', but It is not executing the commands in 
operational and configurational mode. Those modes' prompts are '*>' and '*#'. 

Can somebody suggest me, if there is any module which I can use to execute 
commands inside a switch.

I don't want to use 'socket' module as I am not connecting the box and 
executing commands. I am running the script inside switch.

Please give some clue to start my automation.

Thanks!

Anil Kumar A

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


Re: running python 2 vs 3

2014-03-21 Thread Mark Lawrence

On 21/03/2014 02:18, Chris Angelico wrote:

On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith  wrote:

In article <[email protected]>,
  Steven D'Aprano  wrote:


The rule of three applies here: anything you do in three different places
ought to be managed by a function.


I prefer the rule of two :-)


The way I explain it is: Three is a rule of thumb. Sometimes it's
blatantly obvious at two, and other times you need four or five
similar pieces of code before you can see which part should become the
function. If the code's absolutely identical and reasonably
long/complex, then yes, two's all you need, but how often is that?
Usually it's similar, rather than congruent... err I mean identical.
That's where the third usage comes in. Or if it's maybe 2-3 lines,
used in two places, it doesn't necessarily need to be a function.
Again, a third usage is a strong hint that it should be broken out.

The rule doesn't say that anything that *isn't* in three places yet
should *not* be broken out. :)

ChrisA



Everybody, and especially Antipodeans, knows that there is no rule 6 and 
by definition what rule 7 is :)


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: Python - Caeser Cipher Not Giving Right Output

2014-03-21 Thread Mark Lawrence

On 21/03/2014 04:23, [email protected] wrote:

Would you please access this list via 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: Need help in Python automation

2014-03-21 Thread Adnan Sadzak
Hi,
there should be manufacturer documentation or API. What switch do You use?
Any other info?

Cheers,
Adnan


On Fri, Mar 21, 2014 at 9:14 AM, Anil Kumar A <[email protected]> wrote:

> -
> Hi All,
>
> I work for an ISP. Currently we bought few switches and routers. Python is
> available in that switches. So I would like to write some scipts which I
> can run inside switch.
>
> I tried module 'os, system', but It is not executing the commands in
> operational and configurational mode. Those modes' prompts are '*>' and
> '*#'.
>
> Can somebody suggest me, if there is any module which I can use to execute
> commands inside a switch.
>
> I don't want to use 'socket' module as I am not connecting the box and
> executing commands. I am running the script inside switch.
>
> Please give some clue to start my automation.
>
> Thanks!
>
> Anil Kumar A
>
> -
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-21 Thread fiensproto
> I'm afraid it doesn't help that GoogleGroups has badly mangled the  
> 
> formatting of your code.  I'm not quite sure what to suggest since it  
> 
> isn't one of the usual problems, but you might find reading  
> 
> https://wiki.python.org/moin/GoogleGroupsPython helpful.  It will  
> 
> certainly help with the double-spacing in your quote above.

> Rhodri James *-* Wildebeest Herder to the Masses


Yep, Many thanks for help
Hum, i have find the solution, it was in "CallBack function" in help-doc.

=> 

#file fpgui-test.py
from ctypes import*

def TheProc():
fpgui.fpgFormWindowTitle(0, 'Boum')
return 0 

def TheProcBut0():
fpgui.fpgButtonSetText(0,0, 'Boum also')
return 0 

def TheProcBut1():
fpgui.fpgButtonSetText(0,1, 'Boum too')
return 0 
 
CMPFUNC = CFUNCTYPE(c_int)

TheProcF = CMPFUNC(TheProc)
TheProcB0 = CMPFUNC(TheProcBut0)
TheProcB1 = CMPFUNC(TheProcBut1)

fpgui = cdll.LoadLibrary("fpgui-32.dll")

fpgui.fpgInitialize()
fpgui.fpgSetStyle('Demo Style')
fpgui.fpgFormCreate(0, -1)
fpgui.fpgFormSetPosition(0, 300,100,400,200)
fpgui.fpgFormWindowTitle(0, 'Hello world!')

fpgui.fpgFormOnClick(0,TheProcF) 

fpgui.fpgButtonCreate(0,0,-1) ;
fpgui.fpgButtonSetPosition(0,0, 15, 10 , 150 , 40)
fpgui.fpgButtonSetText(0,0, 'BUTTON1')
fpgui.fpgButtonOnClick(0,0,TheProcB0) 

fpgui.fpgButtonCreate(0,1,-1) ;
fpgui.fpgButtonSetPosition(0,1, 15, 70 , 150, 40)
fpgui.fpgButtonSetText(0,1, 'Clickme')
fpgui.fpgButtonOnClick(0,1,TheProcB1)

fpgui.fpgFormShow(0)
fpgui.fpgRun()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: running python 2 vs 3

2014-03-21 Thread alister
On Fri, 21 Mar 2014 09:40:40 +, Mark Lawrence wrote:

> On 21/03/2014 02:18, Chris Angelico wrote:
>> On Fri, Mar 21, 2014 at 12:06 PM, Roy Smith  wrote:
>>> In article <[email protected]>,
>>>   Steven D'Aprano  wrote:
>>>
 The rule of three applies here: anything you do in three different
 places ought to be managed by a function.
>>>
>>> I prefer the rule of two :-)
>>
>> The way I explain it is: Three is a rule of thumb. Sometimes it's
>> blatantly obvious at two, and other times you need four or five similar
>> pieces of code before you can see which part should become the
>> function. If the code's absolutely identical and reasonably
>> long/complex, then yes, two's all you need, but how often is that?
>> Usually it's similar, rather than congruent... err I mean identical.
>> That's where the third usage comes in. Or if it's maybe 2-3 lines, used
>> in two places, it doesn't necessarily need to be a function. Again, a
>> third usage is a strong hint that it should be broken out.
>>
>> The rule doesn't say that anything that *isn't* in three places yet
>> should *not* be broken out. :)
>>
>> ChrisA
>>
>>
> Everybody, and especially Antipodeans, knows that there is no rule 6 and
> by definition what rule 7 is :)

Im sticking with rule 4
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-21 Thread Roy Smith
In article ,
 Cameron Simpson  wrote:

>   hg blame bin/set-x
> 
> and the output goes:
> 
> [hg/css]fleet*> hg blame bin/set-x
>  2186: #!/bin/sh
> 11359: #
> 11359: # Trace execution of a command.

There's two things hg blame doesn't do which would be useful.

First, the trivial one.  I don't want lines annotated by change number, 
I want them annotated by the name of the person who checked it in.  But, 
I'm sure that can be easily fixed with some simple post-processing 
filter, so it really falls into the bucket of "minor annoyances".

The hard thing is I don't really want to know which change most recently 
touched the line of text.  I want to know who really wrote it.  It would 
be wonderful if hg were smart enough to be able to back-track through 
the change history and ignore trivial changes like whitespace, 
refactoring a function out of one file into another, etc.  That's the 
real meat and potatoes of "blame".  I want to know who I need to hit 
over the head with a clue-by-four once I fix a bug.
-- 
https://mail.python.org/mailman/listinfo/python-list


Github down?

2014-03-21 Thread Skip Montanaro
Anybody else having trouble getting to Github? I'm trying to get to
the pythondotorg issue tracker:

https://github.com/python/pythondotorg/issues

Thx,

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


Re: Github down?

2014-03-21 Thread Larry Martell
On Fri, Mar 21, 2014 at 9:22 AM, Skip Montanaro  wrote:
> Anybody else having trouble getting to Github? I'm trying to get to
> the pythondotorg issue tracker:
>
> https://github.com/python/pythondotorg/issues

They post the status at:

https://twitter.com/githubstatus

As of 10 minutes ago it was down.
-- 
https://mail.python.org/mailman/listinfo/python-list


csv read _csv.Error: line contains NULL byte

2014-03-21 Thread chip9munk
Hi all!

I am reading from a huge csv file (> 20 Gb), so I have to read line by line:

for i, row in enumerate(input_reader):
  #  and I do something on each row

Everything works fine until i get to a row with some strange symbols "0I`00�^"
at that point I get an error: _csv.Error: line contains NULL byte

How can i skip such row and continue going, or "decipher" it in some way?

I have tried :
csvFile = open(input_file_path, 'rb')
csvFile = open(input_file_path, 'rU')
csvFile = open(input_file_path, 'r')

and nothing works.

if I do:

try:
for i, row in enumerate(input_reader):
  #  and I do something on each row
except Exception:
sys.exc_clear() 

i simply stop an that line. I would like to skip it and move on.

Please help!

Best,

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


Re: csv read _csv.Error: line contains NULL byte

2014-03-21 Thread Tim Golden
On 21/03/2014 13:29, [email protected] wrote:
> Hi all!
> 
> I am reading from a huge csv file (> 20 Gb), so I have to read line by line:
> 
> for i, row in enumerate(input_reader):
>   #  and I do something on each row
> 
> Everything works fine until i get to a row with some strange symbols "0I`00�^"
> at that point I get an error: _csv.Error: line contains NULL byte
> 
> How can i skip such row and continue going, or "decipher" it in some way?

Well you have several options:

Without disturbing your existing code too much, you could wrap the
input_reader in a generator which skips malformed lines. That would look
something like this:

def unfussy_reader(reader):
while True:
try:
yield next(reader)
except csv.Error:
# log the problem or whatever
continue


If you knew what to do with the malformed data, you strip it out and
carry on. Whatever works best for you.

Alternatively you could subclass the standard Reader and do something
equivalent to the above in the __next__ method.

TJG


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


Re: Github down?

2014-03-21 Thread Skip Montanaro
On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell  wrote:
> https://twitter.com/githubstatus

Thanks for the pointer. I'm an old fart and don't use social media
much (in fact, just closed my FB account a couple days ago). Does that
mean I'm a curmudgeon? :-)

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


Re: Github down?

2014-03-21 Thread Chris “Kwpolska” Warrick
On Fri, Mar 21, 2014 at 2:48 PM, Skip Montanaro  wrote:
> On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell  
> wrote:
>> https://twitter.com/githubstatus
>
> Thanks for the pointer. I'm an old fart and don't use social media
> much (in fact, just closed my FB account a couple days ago). Does that
> mean I'm a curmudgeon? :-)

If you dislike social media (or prefer a nice website with graphs and
such), then go there:

https://status.github.com/

(though GitHub could qualify as social media for some…)

-- 
Chris “Kwpolska” Warrick 
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Github down?

2014-03-21 Thread Larry Martell
On Fri, Mar 21, 2014 at 9:48 AM, Skip Montanaro  wrote:
> On Fri, Mar 21, 2014 at 8:24 AM, Larry Martell  
> wrote:
>> https://twitter.com/githubstatus
>
> Thanks for the pointer. I'm an old fart and don't use social media
> much (in fact, just closed my FB account a couple days ago). Does that
> mean I'm a curmudgeon? :-)

I don't use FB or twitter, but I do use Linkedin. But going to
https://twitter.com/githubstatus is not using twitter, it's just going
to a web site.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Wing IDE 5.0.4 released

2014-03-21 Thread Wingware

Hi,

Wingware has released version 5.0.4 of Wing IDE, our cross-platform 
integrated

development environment for the Python programming language.

Wing IDE includes a professional quality code editor with vi, emacs, 
visual studio,
and other key bindings, auto-completion, call tips, goto-definition, 
find uses, refactoring,
context-aware auto-editing, a powerful graphical debugger, version 
control, unit testing,

search, and many other features.  For details see http://wingware.com/

Changes in this minor release include:

* Support for Python 3.4 final release
* Improved Source Assistant renders PEP 287 docstrings and displays 
return value type

* Optional New Project dialog
* Improved integrated documentation display
* Improved PDF formatted documentation
* Support for recent git versions
* Fix environment used with named entry points and launch configurations
* Fix Debug Probe for Django templates
* Fix inline renaming of files in the Project tool
* Several optimizations
* About 40 other bug fixes

For details see http://wingware.com/pub/wingide/5.0.4/CHANGELOG.txt

A summary of new features in Wing 5:

* Redesigned GUI based on Qt and PySide
* Native GUI on OS X (and better overall OS-native look and feel)
* Tools and editors can be dragged around
* Toolbar and editor and Project context menus are configurable
* Optional mode that opens different sets of files in each editor split
* Sharable color palettes and syntax highlighting configurations
* Auto-editing is on by default (except some operations that have a 
learning curve)

* Named file sets
* Sharable launch configurations
* Named entry points
* More control over unit testing environment
* Lockable editor splits
* Initial preferences dialog for new users
* Support for Python 3.4
* Support for Django 1.6
* Support for matplotlib on Anaconda and with MacOSX backend
* Improved Source Assistant with PEP 287 docstring rendering and return 
types

* Improved integrated and PDF documentation

For more information on what's new in Wing 5, see 
http://wingware.com/wingide/whatsnew


Free trial: http://wingware.com/wingide/trial
Downloads: http://wingware.com/downloads
Feature list: http://wingware.com/wingide/features
Sales: http://wingware.com/store/purchase
Upgrades: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at [email protected].

Thanks,

--

Stephan Deibel
Wingware | Python IDE

The Intelligent Development Environment for Python Programmers

wingware.com

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


Re: Github down?

2014-03-21 Thread Mark Lawrence

On 21/03/2014 13:22, Skip Montanaro wrote:

Anybody else having trouble getting to Github? I'm trying to get to
the pythondotorg issue tracker:

https://github.com/python/pythondotorg/issues

Thx,

Skip



http://www.downforeveryoneorjustme.com/

--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: csv read _csv.Error: line contains NULL byte

2014-03-21 Thread chip9munk
On Friday, March 21, 2014 2:39:37 PM UTC+1, Tim Golden wrote:

> Without disturbing your existing code too much, you could wrap the
> 
> input_reader in a generator which skips malformed lines. That would look
> 
> something like this:
> 
> 
> 
> def unfussy_reader(reader):
> 
> while True:
> 
> try:
> 
> yield next(reader)
> 
> except csv.Error:
> 
> # log the problem or whatever
> 
> continue


I am sorry I do not understand how to get to each row in this way.

Please could you explain also this:
If I define this function, 
how do I change my for loop to get each row?

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


Re: csv read _csv.Error: line contains NULL byte

2014-03-21 Thread chip9munk
Ok, I have figured it out:

for i, row in enumerate(unfussy_reader(input_reader): 
  #  and I do something on each row 

Sorry, it is my first "face to face" with generators!

Thank you very much!

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


Re: csv read _csv.Error: line contains NULL byte

2014-03-21 Thread Tim Golden
On 21/03/2014 14:46, [email protected] wrote:
> I am sorry I do not understand how to get to each row in this way.
> 
> Please could you explain also this:
> If I define this function, 
> how do I change my for loop to get each row?

Does this help?


#!python3
import csv

def unfussy_reader(csv_reader):
while True:
try:
yield next(csv_reader)
except csv.Error:
# log the problem or whatever
print("Problem with some row")
continue

if __name__ == '__main__':
#
# Generate malformed csv file for
# demonstration purposes
#
with open("temp.csv", "w") as fout:
fout.write("abc,def\nghi\x00,klm\n123,456")

#
# Open the malformed file for reading, fire up a
# conventional CSV reader over it, wrap that reader
# in our "unfussy" generator and enumerate over that
# generator.
#
with open("temp.csv") as fin:
reader = unfussy_reader(csv.reader(fin))
for n, row in enumerate(reader):
print(n, "=>", row)





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


Re: csv read _csv.Error: line contains NULL byte

2014-03-21 Thread Mark Lawrence

On 21/03/2014 14:46, [email protected] wrote:

On Friday, March 21, 2014 2:39:37 PM UTC+1, Tim Golden wrote:


Without disturbing your existing code too much, you could wrap the

input_reader in a generator which skips malformed lines. That would look

something like this:



def unfussy_reader(reader):

 while True:

 try:

 yield next(reader)

 except csv.Error:

 # log the problem or whatever

 continue



I am sorry I do not understand how to get to each row in this way.

Please could you explain also this:
If I define this function,
how do I change my for loop to get each row?

Thanks!



I'm pleased to see that you have answers.  In return would you either 
use the mailing list 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Antony Joseph
Hi all,

How can i implement multiprocessing without inherit file descriptors from
my parent process?

Please help me.

regards,
Antony
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-21 Thread Mark H Harris

On 3/21/14 7:02 AM, [email protected] wrote:

Yep, Many thanks for help
Hum, i have find the solution, it was in "CallBack function" in help-doc.


   No, it was not in the "CallBack function" in help-doc ...



def TheProc(): <== you moved c_int from here ...
 fpgui.fpgFormWindowTitle(0, 'Boum')
 return 0


{snip}


CMPFUNC = CFUNCTYPE(c_int)   < and placed it here ...

TheProcF = CMPFUNC(TheProc)<== so that when you called TheProc ...



... it wasn't "expecting" exactly one parameter. So, your python 
traceback no longer warns about the parameter 'mismatch' in the defined 
function  TheProc().


   I'm not picking on you, but this error was obvious; as was it's 
solution, so I'm just wondering ?


Cheers

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


Re: Question about Source Control

2014-03-21 Thread Chris Angelico
On Fri, Mar 21, 2014 at 11:23 PM, Roy Smith  wrote:
> There's two things hg blame doesn't do which would be useful.
>
> First, the trivial one.  I don't want lines annotated by change number,
> I want them annotated by the name of the person who checked it in.  But,
> I'm sure that can be easily fixed with some simple post-processing
> filter, so it really falls into the bucket of "minor annoyances".
>
> The hard thing is I don't really want to know which change most recently
> touched the line of text.  I want to know who really wrote it.  It would
> be wonderful if hg were smart enough to be able to back-track through
> the change history and ignore trivial changes like whitespace,
> refactoring a function out of one file into another, etc.  That's the
> real meat and potatoes of "blame".  I want to know who I need to hit
> over the head with a clue-by-four once I fix a bug.

Hmm. 'git blame' can do both of those things, so I'd be very surprised
if 'hg blame' can't, at least with some extension(s). (The latter
feature is "git blame -w filename"; -w is a standard 'git diff' option
meaning "ignore whitespace".) But hey, if nothing else, you could
import your hg repo into git just to blame the file...

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


Re: Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Mark H Harris

On 3/21/14 10:28 AM, Antony Joseph wrote:

How can i implement multiprocessing without inherit file descriptors
from my parent process?


I'll bite...

If what you mean by 'multiprocessing' is forking a process, to get a 
child process, which will then do some parallel processing for some 
reason, the answer is two-fold: 1) you can't, and 2) you might try using 
threads.  (there are other answers too)


When you fork a process the only differences between the child and the 
parent is 1) process number, and 2) one is the 'parent' and one is the 
'child'.  They are 'exact' copies of one another.


In socket daemons the parent always listens on a given port, then forks 
a child process to establish a secondary port(s) to handle the comm 
link;  at that point (instant) both the parent and the child ask a 
simple question, "Am I the parent?"  If so, the code goes back to 
listening... if not, the code (the child) establishes the necessary comm 
ports and handles the server request.  When finished the child notifies 
the parent and ends.


You can try parent/child arrangements (maybe use rpc, or shared memory 
segments for inter process comm), or you might try threads... which are 
a separate unit of execution (not a full process copy) but with access 
to the parent's memory.


Otherwise, you might want to tell the list some of the background of 
your difficulty, or put the difficulty in pythonic terms, or simply ask 
your python related question with as much simplified but complete detail 
as possible.


Is there a python question in there someplace?

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


Re: Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Grant Edwards
On 2014-03-21, Antony Joseph  wrote:

> How can i implement multiprocessing without inherit file descriptors from
> my parent process?

What one typically does if that is desired is to call fork() and then
in the child process close all open file descriptors before doing any
other processsing (such as exec()ing another program).

-- 
Grant Edwards   grant.b.edwardsYow! My life is a patio
  at   of fun!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Marko Rauhamaa
Antony Joseph :

> How can i implement multiprocessing without inherit file descriptors
> from my parent process?

Take a look at the subprocess module:

  http://docs.python.org/3/library/subprocess.html#popen-constructor>

It's got the optional close_fds parameter, which is True by default.

IOW, you don't need to do anything if you use subprocess.Popen() to
start your child process. Incidentally, that's the preferred way.


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


Python3 - temporarily change the file encoding

2014-03-21 Thread Helmut Jarausch
Hi,

my locale is en_US.iso88591

But now I'd like to process a restructuredtext file which is encoded in utf-8.

rst2html has

#!/usr/bin/python3.3

# $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $
# Author: David Goodger 
# Copyright: This module has been placed in the public domain.

"""
A minimal front end to the Docutils Publisher, producing HTML.
"""

try:
import locale
locale.setlocale(locale.LC_ALL, '')
except:
pass

from docutils.core import publish_cmdline, default_description


description = ('Generates (X)HTML documents from standalone reStructuredText '
   'sources.  ' + default_description)

publish_cmdline(writer_name='html', description=description)

--

Even if I comment out the part containing 'import locale' the utf-8 encoding of 
my
rst-file is not recognized.

How can I change this so that rst2html use utf-8 when reading and writing files.
Of course, I don't want to change the docutils package for that.

Many thanks for a hint,
Helmut
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-21 Thread Tim Chase
On 2014-03-22 04:23, Chris Angelico wrote:
> > The hard thing is I don't really want to know which change most
> > recently touched the line of text.  I want to know who really
> > wrote it.  It would be wonderful if hg were smart enough to be
> > able to back-track through the change history and ignore trivial
> > changes like whitespace, refactoring a function out of one file
> > into another, etc.  That's the real meat and potatoes of
> > "blame".  I want to know who I need to hit over the head with a
> > clue-by-four once I fix a bug.  
> 
> Hmm. 'git blame' can do both of those things, so I'd be very
> surprised if 'hg blame' can't, at least with some extension(s).
> (The latter feature is "git blame -w filename"; -w is a standard
> 'git diff' option meaning "ignore whitespace".)

A quick "hg -help blame" suggests that it has options to at least
show the author and control the ignoring of whitespace, as well as
tweak other elements:

 -u --userlist the author (long with -v)
 -f --filelist the filename
 -d --datelist the date (short with -q)
 -n --number  list the revision number (default)
 -c --changeset   list the changeset
 -l --line-number show line number at the first appearance
 -w --ignore-all-spaceignore white space when comparing lines
 -b --ignore-space-change ignore changes in the amount of white space
 -B --ignore-blank-lines  ignore changes whose lines are all blank

I don't see a "ignore refactoring", but I'd want to chase through
those more manually.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-21 Thread Tim Chase
On 2014-03-21 12:54, Tim Chase wrote:
> A quick "hg -help blame"

Sigh. Accidentally hit  when I meant to hit 
with  down.  That is, of course "hg help blame", formerly
written there as "hg -v help blame" and accidentally sent mid-edit.

-tkc


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


Re: Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Mark H Harris

On 3/21/14 12:42 PM, Marko Rauhamaa wrote:

   http://docs.python.org/3/library/subprocess.html#popen-constructor>



It's got the optional close_fds parameter, which is True by default.



IOW, you don't need to do anything if you use subprocess.Popen() to
start your child process. Incidentally, that's the preferred way.


hi Marko, of course this depends on the environment; if unix-like, then 
yes, elif windows well, not so much...


There are caveats about stdin, stdout, and stderr;  as well, there are 
caveats about passing fds between the two. Well, Popen() is implemented 
on unix and windows differently, so there is some study needed here if 
code is going to be run in both environments.


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


Re: Python3 - temporarily change the file encoding

2014-03-21 Thread Peter Otten
Helmut Jarausch wrote:

> Hi,
> 
> my locale is en_US.iso88591
> 
> But now I'd like to process a restructuredtext file which is encoded in
> utf-8.
> 
> rst2html has
> 
> #!/usr/bin/python3.3
> 
> # $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $
> # Author: David Goodger 
> # Copyright: This module has been placed in the public domain.
> 
> """
> A minimal front end to the Docutils Publisher, producing HTML.
> """
> 
> try:
> import locale
> locale.setlocale(locale.LC_ALL, '')
> except:
> pass
> 
> from docutils.core import publish_cmdline, default_description
> 
> 
> description = ('Generates (X)HTML documents from standalone
> reStructuredText '
>'sources.  ' + default_description)
> 
> publish_cmdline(writer_name='html', description=description)
> 
> --
> 
> Even if I comment out the part containing 'import locale' the utf-8
> encoding of my rst-file is not recognized.
> 
> How can I change this so that rst2html use utf-8 when reading and writing
> files. Of course, I don't want to change the docutils package for that.
> 
> Many thanks for a hint,

Hm, there is an --input-encoding option that should allow you to specify the 
encoding on the command line.

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


Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread vasudevram

Hi list,

Can anyone - maybe one of the Python language core team, or someone with 
knowledge of the internals of Python - can explain why this code works, and 
whether the different occurrences of the name x in the expression, are in 
different scopes or not? :

x = [[1,2], [3,4], [5,6]]
[x for x in x for x in x]

I saw this on a Hacker News thread about Python, and here is a post I wrote 
that gives more details about it, including relevant links, how I found that it 
can be extended to a triply-nested list, and my thoughts about the scope issue:

http://jugad2.blogspot.in/2014/03/flatten-list-of-lists-with-list.html

A few people commented about it, both on my blog, and on the Python Reddit 
where I also submitted my post, but I'm not sure I'm convinced of their 
reasoning or understand it, hence posting the question here.

Thanks,
Vasudev Ram
www.dancingbison.com
jugad2.blogspot.com

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 2:12:53 AM UTC+5:30, vasudevram wrote:
> Hi list,

> Can anyone - maybe one of the Python language core team, or someone with 
> knowledge of the internals of Python - can explain why this code works, and 
> whether the different occurrences of the name x in the expression, are in 
> different scopes or not? :

> x = [[1,2], [3,4], [5,6]]
> [x for x in x for x in x]

> I saw this on a Hacker News thread about Python, and here is a post I wrote 
> that gives more details about it, including relevant links, how I found that 
> it can be extended to a triply-nested list, and my thoughts about the scope 
> issue:

> http://jugad2.blogspot.in/2014/03/flatten-list-of-lists-with-list.html

> A few people commented about it, both on my blog, and on the Python Reddit 
> where I also submitted my post, but I'm not sure I'm convinced of their 
> reasoning or understand it, hence posting the question here.

Lets try without comprehending comprehensions :-) 

>>> x=[[1,2],[3,4]]
>>> for x in x:
...   for x in x:
...  print x
... 
1
2
3
4
>>> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread vasudevram
On Saturday, March 22, 2014 2:24:00 AM UTC+5:30, Rustom Mody wrote:
> Lets try without comprehending comprehensions :-) 
> >>> x=[[1,2],[3,4]]
> 
> >>> for x in x:
> 
> ...   for x in x:
> 
> ...  print x
> 
> ... 
> 
> 1
> 
> 2
> 
> 3
> 
> 4

Nice and all, thanks, but doesn't answer the question.

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 2:26:09 AM UTC+5:30, vasudevram wrote:
> On Saturday, March 22, 2014 2:24:00 AM UTC+5:30, Rustom Mody wrote:
> > Lets try without comprehending comprehensions :-) 
> > >>> x=[[1,2],[3,4]]
> > >>> for x in x:
> > ...   for x in x:
> > ...  print x
> > ... 
> > 1
> > 2
> > 3
> > 4

> Nice and all, thanks, but doesn't answer the question.

Which is?



A 'for' introduces a scope:

>>> x = 42
>>> for x in [1,2,3]:
...   print x
... 
1
2
3

No sign of the 42 --v ie the outer x -- inside because of scope

And so we can do:

>>> x = [1,2,3]
>>> for x in x:
...   print x
... 
1
2
3

which implies that in a "for var in exp: ..."
the exp is evaluated in outer scope whereas the var has a new scope inside
the "..."

Now repeatedly apply that principle to the nested for.
Same principle for nested for in a comprehension.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Ian Kelly
On Fri, Mar 21, 2014 at 3:09 PM, Rustom Mody  wrote:
> A 'for' introduces a scope:

This is false.

 x = 42
 for x in [1,2,3]:
> ...   print x
> ...
> 1
> 2
> 3
>
> No sign of the 42 --v ie the outer x -- inside because of scope

Try printing x again *after* the for loop:

>>> x = 42
>>> for x in [1,2,3]:
... print(x)
...
1
2
3
>>> print(x)
3

Notice that it's still 3.  If the x in the for loop were really a
separately scoped variable, we would have expected to see 42 here.  In
fact the x used in the for loop and the x used outside of it are the
same x variable.

The real reason that the OP's example works is because each value that
the x variable holds happens to only need to be read once.  Start with
this code, and work through it line-by-line:

x = [[1, 2], [3, 4]]
for x in x:
for x in x:
print(x)

Initially, x is assigned the list.  Then we enter the outer for loop.
The expression x is evaluated once to be iterated over.  The first
value that the for loop iterator yields is [1, 2], which is then
assigned to x.  Now we enter the inner for loop.  The expression x is
again evaluated once to be iterated over.  It first yields 1, which is
assigned to x, and then printed.  The inner for loop iterator then
yields 2, which is also assigned to x and printed.  The inner for loop
iterator then raises StopIteration, and the inner for loop terminates.
 The outer for loop iterator then yields [3, 4], and this is assigned
to x.  The inner for loop evaluates this expression and runs as
before.  Afterward, the outer for loop iterator raises StopException,
and that for loop terminates.  The final value of x here will be 4:

>>> x = [[1, 2], [3, 4]]
>>> for x in x:
... for x in x:
... print(x)
...
1
2
3
4
>>> print(x)
4

As I hope this makes clear, no nested scopes are needed to make this
happen.  It works because nothing that is stored in x needs to remain
there after the next thing is stored in x.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-21 Thread Cameron Simpson
On 21Mar2014 08:23, Roy Smith  wrote:
> In article ,
>  Cameron Simpson  wrote:
> 
> >   hg blame bin/set-x
> > 
> > and the output goes:
> > 
> > [hg/css]fleet*> hg blame bin/set-x
> >  2186: #!/bin/sh
> > 11359: #
> > 11359: # Trace execution of a command.
> 
> There's two things hg blame doesn't do which would be useful.
> 
> First, the trivial one.  I don't want lines annotated by change number, 
> I want them annotated by the name of the person who checked it in.

>From "hg help blame":

  This command is useful for discovering when a change was made and by whom.

Look at "hg blame -u" or "hg blame -uv".

> The hard thing is I don't really want to know which change most recently 
> touched the line of text.  I want to know who really wrote it.  It would 
> be wonderful if hg were smart enough to be able to back-track through 
> the change history and ignore trivial changes like whitespace, 
> refactoring a function out of one file into another, etc.  That's the 
> real meat and potatoes of "blame".  I want to know who I need to hit 
> over the head with a clue-by-four once I fix a bug.

That would probably be not too hard to script. The tricky bit might be
identifying a particular line as the same over certain diffs.

Basicly, run "hg log" for the file, and examine each of the diffs
WRT to your target line.

Refactoring raises the bar somewhat.

Cheers,
-- 
Cameron Simpson 

I am learning that criticism is not nearly as effective as sabotage.
- Shanti Goldstein
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Gregory Ewing

Rustom Mody wrote:


A 'for' introduces a scope:


No, it doesn't!


x = 42
for x in [1,2,3]:

...   print x
... 
1

2
3

No sign of the 42 --v ie the outer x -- inside because of scope


You're right that there's no sign of the 42, but it's
*not* because of scope, as you'll see if you do one
more print:

>>> print x
3


And so we can do:



x = [1,2,3]
for x in x:

...   print x
... 
1

2
3


Again, if you print x after the loop has finished,
you'll find that it's no longer bound to the original
list. This is because Python's for-loop does *not*
introduce a new scope -- there's only one x, and
the for-loop is sharing it with the rest of the code.

The real question is why the for-loop works in *spite*
of this fact.

The answer is that the for-loop machinery keeps an
internal reference to the list being iterated over,
so once the loop has started, it doesn't matter what
x is bound to any more.

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


Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
Hi everybody,

I need to install Python 3.4 final urgently, because my IDE stopped supporting 
Python 3.4 beta2, and I need it urgently to work.

I downloaded it, but the MSI won't install. It didn't work on both of my 
computers (Windows 7 64bit).

I managed to have the MSI dump data to log, file attached.

I couldn't help but notice this line in the log:

The installer has encountered an unexpected error installing this package. 
This may indicate a problem with this package. The error code is 2726. The 
arguments are: HO_CHI~1|Ho_Chi_Minh

A Google search shows this: http://en.wikipedia.org/wiki/Ho_Chi_Minh

What the hell. Was python.org hacked by communists?

Please, I need to get back to work and I can't. 


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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
Sorry, couldn't attach the file, here's the log file:

https://gist.github.com/anonymous/9697505

On Saturday, March 22, 2014 12:05:59 AM UTC+2, cool-RR wrote:
> Hi everybody,
> 
> 
> 
> I need to install Python 3.4 final urgently, because my IDE stopped 
> supporting Python 3.4 beta2, and I need it urgently to work.
> 
> 
> 
> I downloaded it, but the MSI won't install. It didn't work on both of my 
> computers (Windows 7 64bit).
> 
> 
> 
> I managed to have the MSI dump data to log, file attached.
> 
> 
> 
> I couldn't help but notice this line in the log:
> 
> 
> 
> The installer has encountered an unexpected error installing this 
> package. This may indicate a problem with this package. The error code is 
> 2726. The arguments are: HO_CHI~1|Ho_Chi_Minh
> 
> 
> 
> A Google search shows this: http://en.wikipedia.org/wiki/Ho_Chi_Minh
> 
> 
> 
> What the hell. Was python.org hacked by communists?
> 
> 
> 
> Please, I need to get back to work and I can't. 
> 
> 
> 
> 
> 
> Thanks,
> 
> Ram.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about Source Control

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 8:32 AM, Cameron Simpson  wrote:
> Basicly, run "hg log" for the file, and examine each of the diffs
> WRT to your target line.
>
> Refactoring raises the bar somewhat.

Here's one where git and hg are a lot more different.

When I'm trying to find the origin of some line of code in a git repo,
I often make a dummy edit to it, then pull up gitk, right-click the
red "deleted" line, and hit "Show origin of this line". This will
select the commit that introduced that one line, without annotating
the whole rest of the file (often a slow job, especially on a big
file), and then I can go from the green inserted line to the
corresponding red deleted line and repeat the exercise (eg if some
trivial change was made, like renaming something). I'm trying that
workflow with "hg view", the nearest equivalent to gitk, but it's way
slower and doesn't seem to have a right-click menu at all, so I'm not
sure this is possible. Is there a convenient way to trace the origin
of one line back through a few commits?

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 9:05 AM, cool-RR  wrote:
> I downloaded it, but the MSI won't install. It didn't work on both of my 
> computers (Windows 7 64bit).
>
> What the hell. Was python.org hacked by communists?

First question: Where did you download from? What file did you get?

(First and a halfth question: When you say "won't install", exactly
what do you mean? Error message? Hard drive exploded in a fiery
inferno? Your boss tapped you on the shoulder and said "Kill that
process"?)

Secondly, do you have a tool for checking the MD5 hash of a file?
Compare the file you have against the official checksum:

https://www.python.org/downloads/release/python-340/

I'm slightly surprised the python.org installers have MD5s and not
something more cryptographically secure; there are GPG signatures, but
it takes a bit more fiddling to check those.

Finally, take the simple approach: Re-download the file, straight from
python.org, and see if it happens again.

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
I did download from python.org. I checked the md5, it was incorrect, then I 
downloaded again by using a proxy in Austria. (Which hopefully the communists 
haven't be able to infiltrate? ;)

Now it worked! Woohoo!

I'm still curious about the bad installation file... And what Ho Chi Minh is 
doing in the Python MSI. (I'm guessing it's timezone-related, but it's still 
far-fetched, because why would an obscure time zone file appear in the MSI log?)

On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote:
> On Sat, Mar 22, 2014 at 9:05 AM, cool-RR  wrote:
> 
> > I downloaded it, but the MSI won't install. It didn't work on both of my 
> > computers (Windows 7 64bit).
> 
> >
> 
> > What the hell. Was python.org hacked by communists?
> 
> 
> 
> First question: Where did you download from? What file did you get?
> 
> 
> 
> (First and a halfth question: When you say "won't install", exactly
> 
> what do you mean? Error message? Hard drive exploded in a fiery
> 
> inferno? Your boss tapped you on the shoulder and said "Kill that
> 
> process"?)
> 
> 
> 
> Secondly, do you have a tool for checking the MD5 hash of a file?
> 
> Compare the file you have against the official checksum:
> 
> 
> 
> https://www.python.org/downloads/release/python-340/
> 
> 
> 
> I'm slightly surprised the python.org installers have MD5s and not
> 
> something more cryptographically secure; there are GPG signatures, but
> 
> it takes a bit more fiddling to check those.
> 
> 
> 
> Finally, take the simple approach: Re-download the file, straight from
> 
> python.org, and see if it happens again.
> 
> 
> 
> ChrisA

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
Here's the offending MSI, if anyone wants to investigate: 
https://dl.dropboxusercontent.com/u/1927707/python-3.4.0.amd64.msi


On Saturday, March 22, 2014 12:34:06 AM UTC+2, cool-RR wrote:
> I did download from python.org. I checked the md5, it was incorrect, then I 
> downloaded again by using a proxy in Austria. (Which hopefully the communists 
> haven't be able to infiltrate? ;)
> 
> 
> 
> Now it worked! Woohoo!
> 
> 
> 
> I'm still curious about the bad installation file... And what Ho Chi Minh is 
> doing in the Python MSI. (I'm guessing it's timezone-related, but it's still 
> far-fetched, because why would an obscure time zone file appear in the MSI 
> log?)
> 
> 
> 
> On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote:
> 
> > On Sat, Mar 22, 2014 at 9:05 AM, cool-RR  wrote:
> 
> > 
> 
> > > I downloaded it, but the MSI won't install. It didn't work on both of my 
> > > computers (Windows 7 64bit).
> 
> > 
> 
> > >
> 
> > 
> 
> > > What the hell. Was python.org hacked by communists?
> 
> > 
> 
> > 
> 
> > 
> 
> > First question: Where did you download from? What file did you get?
> 
> > 
> 
> > 
> 
> > 
> 
> > (First and a halfth question: When you say "won't install", exactly
> 
> > 
> 
> > what do you mean? Error message? Hard drive exploded in a fiery
> 
> > 
> 
> > inferno? Your boss tapped you on the shoulder and said "Kill that
> 
> > 
> 
> > process"?)
> 
> > 
> 
> > 
> 
> > 
> 
> > Secondly, do you have a tool for checking the MD5 hash of a file?
> 
> > 
> 
> > Compare the file you have against the official checksum:
> 
> > 
> 
> > 
> 
> > 
> 
> > https://www.python.org/downloads/release/python-340/
> 
> > 
> 
> > 
> 
> > 
> 
> > I'm slightly surprised the python.org installers have MD5s and not
> 
> > 
> 
> > something more cryptographically secure; there are GPG signatures, but
> 
> > 
> 
> > it takes a bit more fiddling to check those.
> 
> > 
> 
> > 
> 
> > 
> 
> > Finally, take the simple approach: Re-download the file, straight from
> 
> > 
> 
> > python.org, and see if it happens again.
> 
> > 
> 
> > 
> 
> > 
> 
> > ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 9:34 AM, cool-RR  wrote:
> I did download from python.org. I checked the md5, it was incorrect, then I 
> downloaded again by using a proxy in Austria. (Which hopefully the communists 
> haven't be able to infiltrate? ;)
>

I think you should follow the internet version of Hanlon's Razor here:
Damaged transmission before deliberate tampering. :) It's far more
likely something simply got misdownloaded, and your guess about
timezones is the most likely one - the Asia/Ho_Chi_Minh timezone [1],
and I believe Python Windows installers include a full zoneinfo
database.

ChrisA

[1] See https://en.wikipedia.org/wiki/Ho_Chi_Minh_City
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Mark Lawrence

On 21/03/2014 22:34, cool-RR wrote:

I'm pleased to see that you have answers.  In return would you either 
use the mailing list 
https://mail.python.org/mailman/listinfo/python-list or read and action 
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us 
seeing double line spacing and single line paragraphs, thanks.


--
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.


Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


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


Re: Implement multiprocessing without inheriting parent file handle

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 5:16 AM, Mark H Harris  wrote:
> On 3/21/14 12:42 PM, Marko Rauhamaa wrote:
>>
>>http://docs.python.org/3/library/subprocess.html#popen-constructor>
>
>
>> It's got the optional close_fds parameter, which is True by default.
>
>
>> IOW, you don't need to do anything if you use subprocess.Popen() to
>> start your child process. Incidentally, that's the preferred way.
>
>
> hi Marko, of course this depends on the environment; if unix-like, then yes,
> elif windows well, not so much...
>
> There are caveats about stdin, stdout, and stderr;  as well, there are
> caveats about passing fds between the two. Well, Popen() is implemented on
> unix and windows differently, so there is some study needed here if code is
> going to be run in both environments.

There were some recent changes, though, including making CLOEXEC the
default, which means that fork/exec on Unix will retain only the fds
you actually want.

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
On Saturday, March 22, 2014 12:42:56 AM UTC+2, Chris Angelico wrote:
> I think you should follow the internet version of Hanlon's Razor here:
> Damaged transmission before deliberate tampering. :) It's far more
> likely something simply got misdownloaded, and your guess about
> timezones is the most likely one - the Asia/Ho_Chi_Minh timezone [1],
> and I believe Python Windows installers include a full zoneinfo
> database.


The thing is, I then tried other versions of Python 3.4, like b2, and the 32 
bit version, and they didn't work either... So damaged transmission of 3 
separate files? I'm not seeing any other damaged files when surfing using this 
connection.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread cool-RR
On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote:
> (First and a halfth question: When you say "won't install", exactly
> what do you mean?

For completeness, I'll answer this question I forgot to answer, in case someone 
still wants to investigate: It just showed the first dialog (Something like 
"Preparing to install..."), after a few seconds it disappeared and then nothing.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CallBack function in C Libraries.

2014-03-21 Thread fiensproto
Le vendredi 21 mars 2014 16:50:18 UTC, Mark H. Harris a écrit :
> > def TheProc(): <== you moved c_int from here ...
> 
> >  fpgui.fpgFormWindowTitle(0, 'Boum')
> 
> >  return 0

> > CMPFUNC = CFUNCTYPE(c_int)   < and placed it here ...

> 
> 
> ... it wasn't "expecting" exactly one parameter. So, your python 
> 
> traceback no longer warns about the parameter 'mismatch' in the defined 
> 
> function  TheProc().
> 
> 
> 
> I'm not picking on you, but this error was obvious; as was it's 
> 
> solution, so I'm just wondering ?
> 

Hello and thanks for answer.

Hum, i do not understand why, but the code is working ... ;-)

Some remarks :

> def TheProc():   
>  fpgui.fpgFormWindowTitle(0, 'Boum')
>  return 0<== that does the trick...


And 

> > CMPFUNC = CFUNCTYPE(c_int)   < 1 argument minimum..

It seems that CFUNCTYPE() want minimum 1 argument, even if TheProc() is a 
simple procedure, without argument...

Hum, it is my really first program in Python and im impressed how easy it was 
to do my Pascal (fpc) library work!
Im busy to try to do it work for java programs but it is not so easy.

By the way, is it possible to hide the terminal-window ?

That library is a complete graphic widget set (from Form to Stringgrid and 
more).
So, i will prefer that the console was hided...

And last question, how to retrieve the directory of the main Python application 
?

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


Re: Github down?

2014-03-21 Thread Dan Sommers
On Fri, 21 Mar 2014 14:51:54 +0100, Chris “Kwpolska” Warrick wrote:

> (though GitHub could qualify as social media for some…)

+1 QOTW
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Terry Reedy

On 3/21/2014 6:55 PM, cool-RR wrote:

On Saturday, March 22, 2014 12:25:03 AM UTC+2, Chris Angelico wrote:

(First and a halfth question: When you say "won't install", exactly
what do you mean?


For completeness, I'll answer this question I forgot to answer, in case someone still 
wants to investigate: It just showed the first dialog (Something like "Preparing to 
install..."), after a few seconds it disappeared and then nothing.


Does your .b2 install work? Can you delete it thru the programs list?

--
Terry Jan Reedy

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 3:00:10 AM UTC+5:30, Ian wrote:
> On Fri, Mar 21, 2014 at 3:09 PM, Rustom Mody  wrote:
> > A 'for' introduces a scope:

> This is false.


And 

On Saturday, March 22, 2014 3:04:48 AM UTC+5:30, Gregory Ewing wrote:

> > A 'for' introduces a scope:

> No, it doesn't!


Ha -- funny that *I* missed that one. Thanks both Ian and Gregory

In fact one of my grumbles against python is that list comprehension's
are a poor imitation of haskell's comprehensions.

And then I promptly forgot about it!

Actually there are two leakages in python 2, one of which is corrected
in python 3.

One: a comprehension variable leaks outside after the comprehension
This is corrected in python3.  
Two: A comprehension variable is not bound but reassigned across the
comprehension. This problem remains in python3 and causes weird behavior when
lambdas are put in a comprehension

>>> fl = [lambda y : x+y for x in [1,2,3]]
>>> [fl[i](2) for i in [0,1,2]]
[5, 5, 5]

The same in haskell:

Prelude> let fl = [\ y -> x + y | x <- [1,2,3]]
Prelude> [(fl!!i) 0 | i<- [0,1,2]]
[1,2,3]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 1:06 PM, Rustom Mody  wrote:
> Two: A comprehension variable is not bound but reassigned across the
> comprehension. This problem remains in python3 and causes weird behavior when
> lambdas are put in a comprehension
>
 fl = [lambda y : x+y for x in [1,2,3]]
 [fl[i](2) for i in [0,1,2]]
> [5, 5, 5]

To clarify, what you're saying here is that x in the first
comprehension's closures should be bound to separate values for x,
yes?

I'm not sure how that ought to be done. Having closures that can
reference and modify each other's variables is important.

def func_pair():
x = 0
def inc():
nonlocal x; x+=1
return x
def dec():
nonlocal x; x-=1
return x
return inc, dec

fooup, foodn = func_pair()
barup, bardn = func_pair()
>>> fooup(), fooup(), fooup(), foodn()
(1, 2, 3, 2)
>>> barup(), barup(), bardn(), bardn()
(1, 2, 1, 0)

Those functions are fundamentally linked. Very useful with callbacks.
A nice alternative to doing everything with bound methods.

So if that's not going to be broken, how is this fundamentally different?

def func_loop():
for x in 1,2,3:
yield (lambda: x)

one, two, three = func_loop()
one(), one(), two(), two(), three(), three()

This one does NOT work the way the names imply, and I can see that
you'd like to fix it. But I can't pinpoint a significant difference
between them. How do you distinguish?

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


Re: Question about Source Control

2014-03-21 Thread Cameron Simpson
On 22Mar2014 09:17, Chris Angelico  wrote:
> On Sat, Mar 22, 2014 at 8:32 AM, Cameron Simpson  wrote:
> > Basicly, run "hg log" for the file, and examine each of the diffs
> > WRT to your target line.
> >
> > Refactoring raises the bar somewhat.
> 
> Here's one where git and hg are a lot more different.

You might find it is just a matter of knowing what tool to use.

> When I'm trying to find the origin of some line of code in a git repo,
> I often make a dummy edit to it, then pull up gitk, right-click the
> red "deleted" line, and hit "Show origin of this line". This will
> select the commit that introduced that one line, without annotating
> the whole rest of the file (often a slow job, especially on a big
> file), and then I can go from the green inserted line to the
> corresponding red deleted line and repeat the exercise (eg if some
> trivial change was made, like renaming something). I'm trying that
> workflow with "hg view", the nearest equivalent to gitk, but it's way
> slower and doesn't seem to have a right-click menu at all, so I'm not
> sure this is possible. Is there a convenient way to trace the origin
> of one line back through a few commits?

I don't know.

You might do better to ask this kind of question on the mercurial list:

  http://selenic.com/mailman/listinfo/mercurial

Someone there is bound to have wanted to do this kind of thing, and
may know if there's a tool or extension that makes it easy. There's
a whole expression syntax for getting mercurial to select from the
revision tree, for example; I do not know if it is applicable in
this case.

Cheers,
-- 
Cameron Simpson 

Do what you think is interesting, do something that you think is fun
and worthwhile, because otherwise you won't do it well anyway.
- Brian Kernighan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installing ssdeep on Portable Python /advice

2014-03-21 Thread Mark H Harris

On 3/20/14 7:16 PM, [email protected] wrote:


 $ tar -zxvf ssdeep-2.10.tar.gz
 $ cd ssdeep-2.10&&  ./configure&&  make&&  sudo make install



I need install it on PortablePython for Windows, so it's not
clear how to make this: where should be placed ssdeep Windows
binary files, that Python application can found it?


It is strongly recommended that ssdeep be run on windows from 
precompiled binaries.  Building from sources is not recommended because 
of dependencies and environment...


Google is our frined;

http://ssdeep.sourceforge.net/usage.html


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


Re: Question about Source Control

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 1:49 PM, Cameron Simpson  wrote:
> You might do better to ask this kind of question on the mercurial list:
>
>   http://selenic.com/mailman/listinfo/mercurial
>
> Someone there is bound to have wanted to do this kind of thing, and
> may know if there's a tool or extension that makes it easy.

I don't personally need it, because all my code is stored in git (as
are most of the other big projects that I'm involved in); was mainly
wondering if someone happened to know, such that Frank could make use
of it. But it's a suggested workflow, and if it appeals to someone,
they can raise the issue on Mercurial's list.

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


Re: Installing ssdeep on Portable Python /advice

2014-03-21 Thread Mark H Harris

On 3/21/14 9:51 PM, Mark H Harris wrote:

On 3/20/14 7:16 PM, [email protected] wrote:



$ tar -zxvf ssdeep-2.10.tar.gz
$ cd ssdeep-2.10&& ./configure&& make&& sudo make install



I need install it on PortablePython for Windows, so it's not
clear how to make this: where should be placed ssdeep Windows
binary files, that Python application can found it?



It is strongly recommended that ssdeep be run on windows from
precompiled binaries. Building from sources is not recommended because
of dependencies and environment...



Google is our frined;



http://ssdeep.sourceforge.net/usage.html



Actually, I restated that wrong. The doc says that building from sources 
on windows is NOT supported.


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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Mark H Harris

On 3/21/14 5:44 PM, Mark Lawrence wrote:

I'm pleased to see that you have answers. In return would you either use
the mailing list https://mail.python.org/mailman/listinfo/python-list or
read and action this https://wiki.python.org/moin/GoogleGroupsPython to
prevent us seeing double line spacing and single line paragraphs, thanks.


I perceive that this is your singular pet peeve, or, you were elected by 
the python community some time ago to police the line-end problem ?


I notice (since moving my stuff to Thunderbird two weeks back) the 
double spacing you keep squawking about, but I don't find it the big 
nuisance you're talking about; ok, so we have to scroll a bit further.


I am honestly convinced that this might even be a python problem.  More 
likely than not, gg is written in python, and this is the goofy line-end 
character problem we have to deal with when we read lines in python.


Why do we suck in the new-line character as though it were part of the 
line?  This is asinine behavior.  The new-line is a "file" delimiter 
character and NOT intended to be part of the line.


Thinking this through a bit I've noticed that a blank line comes back 
with a '\n'  which differentiates it from file end which comes back 
"without" the new-line.  So, it appears that python is using the 
new-line character (or lack there-of) to have meaning which the new=line 
in a unix file was never suppose to carry.


If python would just return EOF like every other language at file end, 
and a test line without '\n' tacked to the end of it, this little snag 
with gg would probably go away.  What say you?


Of course, that does not alleviate all of the rest of gg's short 
comings!   


marcus

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 2:58 PM, Mark H Harris  wrote:
> On 3/21/14 5:44 PM, Mark Lawrence wrote:
>>
>> I'm pleased to see that you have answers. In return would you either use
>> the mailing list https://mail.python.org/mailman/listinfo/python-list or
>> read and action this https://wiki.python.org/moin/GoogleGroupsPython to
>> prevent us seeing double line spacing and single line paragraphs, thanks.
>
>
> I perceive that this is your singular pet peeve, or, you were elected by the
> python community some time ago to police the line-end problem ?

Communities maintain standards by policing them. If nobody cares
enough to post, the problem will remain. He happens to be one of the
most frequent commenters on this particular issue, but believe you me,
he is not the only one to wish it were solved; I used to speak up too,
but became tired of saying it (and of the blowback), and now I ignore
all double-spaced junk. If I can't figure out what's going on without
the context, I'll just move on to the next post.

> I notice (since moving my stuff to Thunderbird two weeks back) the double
> spacing you keep squawking about, but I don't find it the big nuisance
> you're talking about; ok, so we have to scroll a bit further.

It compounds. One reply makes for double spacing... two makes
quadruple, three means we have seven wasted lines between every pair
of real lines. That gets pretty annoying. And considering that most
people who reply without cleaning up the lines also keep the entire
quoted text (and usually top-post as well), this gets big fast.

> I am honestly convinced that this might even be a python problem.  More
> likely than not, gg is written in python, and this is the goofy line-end
> character problem we have to deal with when we read lines in python.

No idea why you should think this; it's more likely to be based on
HTML parsing (newline -> paragraph -> double newline), especially
since the original text is usually unwrapped.

> Why do we suck in the new-line character as though it were part of the line?
> This is asinine behavior.  The new-line is a "file" delimiter character and
> NOT intended to be part of the line.
>
> Thinking this through a bit I've noticed that a blank line comes back with a
> '\n'  which differentiates it from file end which comes back "without" the
> new-line.  So, it appears that python is using the new-line character (or
> lack there-of) to have meaning which the new=line in a unix file was never
> suppose to carry.
>
> If python would just return EOF like every other language at file end, and a
> test line without '\n' tacked to the end of it, this little snag with gg
> would probably go away.  What say you?

Personally, I think that iterating over the lines in a file (in the
most obvious way) should strip delimiters. There should be a
less-obvious way to iterate over the "lines complete with their line
ends", which can then be used to distinguish between the different
line endings (including the absence of one at the end of the file),
but most of the time you want to just treat a file as a series of
lines, and don't care about the distinctions. However, that ship has
sailed; it's way WAY too late to make any such change.

And changing it would not fix the Google Groups problem unless it also
broke a whole pile of other code out there.

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Mark H Harris

On 3/21/14 11:15 PM, Chris Angelico wrote:

It compounds. One reply makes for double spacing... two makes
quadruple, three means we have seven wasted lines between every pair
of real lines. That gets pretty annoying. And considering that most
people who reply without cleaning up the lines also keep the entire
quoted text (and usually top-post as well), this gets big fast.


   Yes, I can see that readily/  I get it, it just seems that fixing it 
at the source (gg) is the answer; because there will always be someone 
new to the list who is using gg because its part of their suite and 
because its convenient (I mean, that's why I tried to use it). I think 
we need to be beating up on the gg people so they get their stuff working.



Personally, I think that iterating over the lines in a file (in the
most obvious way) should strip delimiters.


   agreed.


most of the time you want to just treat a file as a series of
lines, and don't care about the distinctions. However, that ship has
sailed; it's way WAY too late to make any such change.


   agreed again, on both counts.


And changing it would not fix the Google Groups problem unless it also
broke a whole pile of other code out there.


   No doubt.  Well, I don't mind dealing with it/  and frankly, I don't 
really think its a python problem anyway at the root. All files should 
have standard delimiters.  What I used to call flat-text files should 
have standard line-end delimiters, and standard file-end EOF markers. 
All OS's should comply with the standard... for instance, there should 
not be a windows x'0a' x'0d' line ending, and a unix  x'0d' line ending.


   Well, and now that I'm thinking about this again, since we have 
unicode, maybe we should have an entire set of standard "file" 
delimiters for flat-files.


   But the bottom line (pun intended) is that I just want to suck the 
lines in, and I only want the system to have to handle the delimiters; 
I'm not asking for any changes mind you (at this point) just thinking 
out-loud.


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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Mark H Harris

On 3/21/14 11:30 PM, Mark H Harris wrote:

All OS's should comply with the standard... for instance, there should
not be a windows x'0a' x'0d' line ending, and a unix x'0d' line ending.



whoops...  I meant  unix  x'0a' line ending...;-)


'\n'

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 8:11:27 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Mar 22, 2014 at 1:06 PM, Rustom Mody wrote:
> > Two: A comprehension variable is not bound but reassigned across the
> > comprehension. This problem remains in python3 and causes weird behavior 
> > when
> > lambdas are put in a comprehension
>  fl = [lambda y : x+y for x in [1,2,3]]
>  [fl[i](2) for i in [0,1,2]]
> > [5, 5, 5]

> To clarify, what you're saying here is that x in the first
> comprehension's closures should be bound to separate values for x,
> yes?

Yes

> I'm not sure how that ought to be done.

Thats an implementation question -- see below.

> Having closures that can
> reference and modify each other's variables is important.

Yes

> def func_pair():
> x = 0
> def inc():
> nonlocal x; x+=1
> return x
> def dec():
> nonlocal x; x-=1
> return x
> return inc, dec

> fooup, foodn = func_pair()
> barup, bardn = func_pair()
> >>> fooup(), fooup(), fooup(), foodn()
> (1, 2, 3, 2)
> >>> barup(), barup(), bardn(), bardn()
> (1, 2, 1, 0)

> Those functions are fundamentally linked. Very useful with callbacks.
> A nice alternative to doing everything with bound methods.

Yes

> So if that's not going to be broken, how is this fundamentally different?

> def func_loop():
> for x in 1,2,3:
> yield (lambda: x)

Thats using a for-loop
A 'for' in a comprehension carries a different intention, the matching names
being merely coincidental.

This 'pun' causes cognitive dissonance in all these questions, including
my gaffe above

> one, two, three = func_loop()
> one(), one(), two(), two(), three(), three()

> This one does NOT work the way the names imply, and I can see that
> you'd like to fix it. But I can't pinpoint a significant difference
> between them. How do you distinguish?

Using closures for carrying state is a different question

As for comprehensions, the appropriate *intention* would be like this:

Given

fl = [lambda y : x+y for x in [1,2,3]] 

It means:

def rec(l):
   if not l: return []
   else:
 x,ll = l[0],l[1:]
 return [lambda y: x + y] + rec(ll)

followed by
fl = rec([1,2,3])

Naturally a reasonable *implementation* would carry this *intention* more
efficiently with standard techniques like
1. Using list extend/append methods
2. Using lambda y, x=x: x+y

Inside an implementation this is fine
Forcing such tricks as kosher on a programmer is not (IMHO)

[But then I find Lisp and much of basic haskell natural and most of C++ not,
so my views are likely prejudiced :-)

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 3:30 PM, Mark H Harris  wrote:
> All files should have standard delimiters.  What I used to call flat-text
> files should have standard line-end delimiters, and standard file-end EOF
> markers. All OS's should comply with the standard... for instance, there
> should not be a windows x'0a' x'0d' line ending, and a unix  x'0d' line
> ending.

(Side point: You have your 0d and your 0a backwards; the Unix line
ending is U+000A, and the Windows default is U+000D U+000A.)

How are you going to make people change? What are you going to make
them change to? Who controls this standard, and how do you convince
all OSes to comply with it?

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Steven D'Aprano
On Fri, 21 Mar 2014 19:06:06 -0700, Rustom Mody wrote:

> Two: A comprehension variable is not bound but reassigned across the
> comprehension. This problem remains in python3 and causes weird behavior
> when lambdas are put in a comprehension

I don't know why you say the behaviour in Python is a problem. It's 
somewhat unexpected if you don't think about what's going on, but it's 
actually quite logical. On the contrary, I find the Haskell version weird.


 fl = [lambda y : x+y for x in [1,2,3]] 
 [fl[i](2) for i in [0,1,2]]
> [5, 5, 5]

This makes perfect sense: by the time you call the functions, the name x 
has been rebound to the value 3. If x were a global, or if comprehensions 
leaked their variable, that would be obvious: you could print x and see 
exactly what value it has. But visible or not, that's exactly what 
happens. Since x is 3, you're adding 3+2 and should get 5 no matter which 
function you call.

Unroll the first comprehension, and it's obvious what is going on:

def unrolled():
fl = []
x = 0
def lambda_(y):
return x + y
fl.append(lambda_)
x = 1
def lambda_(y):
return x + y
fl.append(lambda_)
x = 2
def lambda_(y):
return x + y
fl.append(lambda_)
return [f(2) for f in fl]

Don't be fooled by the coincidence that the three "lambda_" functions 
have the same name and body. They could have different names and 
different bodies, Either way, it is completely natural that they all 
closures over the same x -- that's how you wrote them.


But the Haskell version, on the other hand, is just weird:

> The same in haskell:
> 
> Prelude> let fl = [\ y -> x + y | x <- [1,2,3]] 
> Prelude> [(fl!!i) 0 | i<- [0,1,2]]
> [1,2,3]

For this to be the case, the functions in fl have to somehow "look back 
in time" to see the value of x, not as it is *now* when the function is 
called, but how it *was* when it was created. That's very weird indeed. 
If x were a global, it would be astonishing. The fact that x comes from a 
closure instead makes it no less surprising. Unroll the loop, and the 
magic is obvious.

Now I'm not sure precisely how Haskell implements this trick, but it 
suggests to me that it creates a different closure each time around the 
loop of the comprehension. That could end up being very expensive.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody  wrote:
>> So if that's not going to be broken, how is this fundamentally different?
>
>> def func_loop():
>> for x in 1,2,3:
>> yield (lambda: x)
>
> Thats using a for-loop
> A 'for' in a comprehension carries a different intention, the matching names
> being merely coincidental.

So what you're saying is that these two are fundamentally different:

def unrolled():
x = 1
yield (lambda: x)
x = 2
yield (lambda: x)
x = 3
yield (lambda: x)

def loop():
for x in 1,2,3:
yield (lambda: x)

In other words, a loop should be implemented as a separate binding
each time, not a rebinding. That's an interesting point, and it does
make some sense; effectively, what you want is for the body of a for
loop to be a new scope, a unique scope every iteration of the loop,
and one that automatically closes over all variables in the parent
scope (including for assignments) except for the loop
iteration/counter variable.

That does make some sense, but it doesn't really fit Python's concept.
It would, however, fit a more C-like language, where locals are
declared (in Python, you'd have to put a whole lot of implicit
'nonlocal' statements at the top of the loop).

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Mark H Harris

On 3/21/14 11:39 PM, Rustom Mody wrote:

Given



fl = [lambda y : x+y for x in [1,2,3]]



It means:



def rec(l):
if not l: return []
else:
  x,ll = l[0],l[1:]
  return [lambda y: x + y] + rec(ll)

followed by
fl = rec([1,2,3])



Naturally a reasonable *implementation* would carry this *intention*

{snip}

[But then I find Lisp and much of basic haskell natural and most of C++ not,
so my views are likely prejudiced :-)



This discussion (the entire thread) comes up again and again over the 
years because python tries to be all things to all people, without much 
reason behind the motivation. I'm speaking of Lambda (filter, map, reduce).


Python is not Lisp. (I love Lisp too). Python is not Haskell (I love 
Haskell too).


Lambda is a problem, if only because it causes confusion. What's the 
problem?  Glad you asked. The constructs DO NOT work the way most people 
would expect them to, having limited knowledge of python!  I ran into 
this thing about seven years ago (when I was studying Haskell, and 
Scheme) and I wanted to see how "pure functional" python was (well, not 
at all really).


I can see uses for python's lambda.  But, honestly, I think python could 
deprecate its use and in five years just remove it from the language; 
along with filter, map, and reduce !


I'm just saying;

marcus

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Mark H Harris

On 3/21/14 11:46 PM, Chris Angelico wrote:

(Side point: You have your 0d and your 0a backwards; the Unix line
ending is U+000A, and the Windows default is U+000D U+000A.)


   Yeah, I know... smart apple.


How are you going to make people change? What are you going to make
them change to? Who controls this standard, and how do you convince
all OSes to comply with it?


   Well, we're already doing this to some extent; baby steps.  Well, we 
have open document standards (evolving) and we have a really good sense 
for unicode (and python is being a genuine leader there) and the 
flat-file is just another open document (very simple no doubt), not 
different from a standards viewpoint than rft, odt, {whatever}; txt?


   My idea is that as we are morphing open document standards we need 
to keep the "flat-file" in mind too.  The ASCII ship has sailed too. 
Unicode is in, ASCII is out (for all intents and purposes) except at 
Microsoft---and its time to rethink what a "flat" unicode text file 
really is. That's all.


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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 3:47 PM, Steven D'Aprano
 wrote:
> Now I'm not sure precisely how Haskell implements this trick, but it
> suggests to me that it creates a different closure each time around the
> loop of the comprehension. That could end up being very expensive.

It needn't be terribly expensive, if you make a "scope stack" or
"scope chain". Imagine, if you will, a system of scopes like this:

current_scope = None
class Scope:
def __init__(self, *a, **kw):
self.names = dict(*a, **kw)
global current_scope
self.parent = current_scope
current_scope = self
def __getitem__(self, name):
try:
return self.names[name]
except KeyError:
if self.parent is None: raise
return self.parent[name]
def __setitem__(self, name, value):
self.names[name] = value
def exit_scope():
global current_scope
current_scope = current_scope.parent

Creating a new scope would be fairly cheap (and a lot more so if this
were implemented in C without the object overhead, of course). Lookups
would scan up through a series of namespaces, same as they currently
do (local, module, builtins), there'd just be more of them. And the
compiler could be smart enough to skip creating a scope if there are
no assignments. There'd need to be some handling in there for the
'nonlocal' keyword, but my expectation is that 'global' is handled by
retaining a reference to the current_scope at module level, and
starting the search there for a LOAD_GLOBAL.

Each iteration of the loop could begin with Scope() and end with
exit_scope(), and there you are, each iteration in its own closable
scope.

I'm not saying it would be a good thing to do - and it'd be a bad fit
for Python, I think, as I said in my other post - but it could be
done.

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


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Terry Reedy

On 3/22/2014 12:30 AM, Mark H Harris wrote:

On 3/21/14 11:15 PM, Chris Angelico wrote:

It compounds. One reply makes for double spacing... two makes
quadruple, three means we have seven wasted lines between every pair
of real lines. That gets pretty annoying. And considering that most
people who reply without cleaning up the lines also keep the entire
quoted text (and usually top-post as well), this gets big fast.


Before Mark started asking people adjust to the foibles of gg, we used 
to get such posts. I refused to read them. I have not seen one lately, 
say maybe his nudging has had some positive effect.



Yes, I can see that readily/  I get it, it just seems that fixing it
at the source (gg) is the answer;


I completely agree. However, Google seems immune to suggestions, 
including requests that it try to stop being a major source of spam posts.


> because there will always be someone

new to the list who is using gg because its part of their suite and
because its convenient (I mean, that's why I tried to use it).


If I were in charge of the software used for this list, I would replace 
Mark with a custom addition to return mis-formated posts (more blank 
lines than not) with instructions on how to fix them. But I am not.


--
Terry Jan Reedy

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 10:21:13 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody wrote:
> >> So if that's not going to be broken, how is this fundamentally different?
> >> def func_loop():
> >> for x in 1,2,3:
> >> yield (lambda: x)
> > Thats using a for-loop
> > A 'for' in a comprehension carries a different intention, the matching names
> > being merely coincidental.

> So what you're saying is that these two are fundamentally different:

> def unrolled():
> x = 1
> yield (lambda: x)
> x = 2
> yield (lambda: x)
> x = 3
> yield (lambda: x)

> def loop():
> for x in 1,2,3:
> yield (lambda: x)

Well almost...

Except that the 'loop' I am talking of is one of

def loop():
 return [yield (lambda: x) for x in [1,2,3]]
or 
 return (yield (lambda: x) for x in [1,2,3])  
or just plain ol
 (lambda x:  for x in [1,2,3])

IOW loop is an imperative construct, comprehensions are declarative

Progressing through a loop in a sequential order is natural and to
be expected

Comprehensions being declarative, progressing through them
in some order is incidental.


> In other words, a loop should be implemented as a separate binding
> each time, not a rebinding. That's an interesting point, and it does
> make some sense; effectively, what you want is for the body of a for
> loop to be a new scope, a unique scope every iteration of the loop,
> and one that automatically closes over all variables in the parent
> scope (including for assignments) except for the loop
> iteration/counter variable.

> That does make some sense, but it doesn't really fit Python's concept.

Yes it does not fit in with imperative programming.

Its good to remember the history.
Haskell did not invent comprehensions

In programming, they started with Miranda where they were called
'ZF-expressions' after the Zermelo/Fraenkel of axiomatic set theory.

Because Russell's paradox had shaken the (intended) foundations of mathematics,
the way out (actually the one chosen by Zermelo and Fraenkel) was to
add a *comprehension axiom*

http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory#3._Axiom_schema_of_specification_.28also_called_the_axiom_schema_of_separation_or_of_restricted_comprehension.29

What this basically mandates is that set constructions like
{x | Pred(x) } are disqualified (called unrestricted comprehension)

Only
{x ∈ S | Pred(x) } is a valid.

IOW sets cannot be concocted out of the blue but only out of other sets.

Fast forward 50 years and what David Turner – inventor of Miranda –- realized 
is that if the programming language is sufficiently mathematical – ie no
imperative constructs plus lazy evaluation, then comprehensions are
actually constructive enough to make make into programming constructs.

However as Mark Harris points out imperative and functional thinking styles
remain somewhat inconsistent with each other.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python MSI not installing, log file showing name of a Viatnemese communist revolutionary

2014-03-21 Thread Chris Angelico
On Sat, Mar 22, 2014 at 4:24 PM, Terry Reedy  wrote:
> If I were in charge of the software used for this list, I would replace Mark
> with a custom addition to return mis-formated posts (more blank lines than
> not) with instructions on how to fix them. But I am not.

I love how this makes it sound as if Mark is part of Mailman...

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


Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

2014-03-21 Thread Rustom Mody
On Saturday, March 22, 2014 10:21:13 AM UTC+5:30, Chris Angelico wrote:
> On Sat, Mar 22, 2014 at 3:39 PM, Rustom Mody  wrote:
> >> So if that's not going to be broken, how is this fundamentally different?
> >> def func_loop():
> >> for x in 1,2,3:
> >> yield (lambda: x)
> > Thats using a for-loop
> > A 'for' in a comprehension carries a different intention, the matching names
> > being merely coincidental.

> So what you're saying is that these two are fundamentally different:



> def unrolled():
> x = 1
> yield (lambda: x)
> x = 2
> yield (lambda: x)
> x = 3
> yield (lambda: x)

> def loop():
> for x in 1,2,3:
> yield (lambda: x)

Well almost
Except that the 'loop' I am talking of is one of

def loop():
 return [yield (lambda: x) for x in [1,2,3]]
or 
 return (yield (lambda: x) for x in [1,2,3])  
or just plain ol
 (lambda x:  for x in [1,2,3])

IOW loops is an imperative construct, comprehensions are declarative

Progressing through a loop in a sequential order is natural and to
be expected

Comprehensions being declarative, progressing through them
in some order is incidental.



> In other words, a loop should be implemented as a separate binding
> each time, not a rebinding. That's an interesting point, and it does
> make some sense; effectively, what you want is for the body of a for
> loop to be a new scope, a unique scope every iteration of the loop,
> and one that automatically closes over all variables in the parent
> scope (including for assignments) except for the loop
> iteration/counter variable.

> That does make some sense, but it doesn't really fit Python's concept.

Yes it does not fit in with imperative programming.

Its good to remember the history.
Haskell did not invent comprehensions

In programming, they started with Miranda where they were called
'ZF-expressions' after the Zermelo/Fraenkel of axiomatic set theory.

Because Russell's paradox had shaken the (intended) foundations of mathematics,
the way out (actually the one chosen by Zermelo and Fraenkel) was to
add a *comprehension axiom*

http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory#3._Axiom_schema_of_specification_.28also_called_the_axiom_schema_of_separation_or_of_restricted_comprehension.29

What this basically mandates is that set constructions like
{x | Pred(x) } are disqualified (called unrestricted comprehension)

Only
{x ∈ S | Pred(x) } is a valid.

IOW sets cannot be concoted out of the blue but only out of other sets.

FF 50 years and what David Turner – inventor of Miranda –- realized is that
if the programming language is sufficiently mathematical – ie no
imperative constructs plus lazy evaluation, then comprehensions are
actually constructive enough to make make into programming constructs.

However as Mark Harris points out imperative and functional thinking styles
remain confusingly inconsistent.
-- 
https://mail.python.org/mailman/listinfo/python-list