Formatting lost in hg-web (was Re: with ignored)

2013-04-08 Thread Chris Angelico
On Mon, Apr 8, 2013 at 4:38 PM, Barrett Lewis  wrote:
> I looked up the source to the decorator
> found here:http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py
> for anyone interested.

Strangely, line indentation seems to be swallowed in the web view of
the Mercurial tree. The code directly follows the line numbers, so it
goes ragged between (eg) lines 9 and 10. Is this a browser bug? I
tried on Chrome 26.0.1410.40 and Firefox 19.0.2 on Windows.

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


Re: Formatting lost in hg-web (was Re: with ignored)

2013-04-08 Thread Barrett Lewis
I am viewing it on Chrome Version 26.0.1410.43 m for windows and it works
perfectly for me.


On Mon, Apr 8, 2013 at 12:32 AM, Chris Angelico  wrote:

> On Mon, Apr 8, 2013 at 4:38 PM, Barrett Lewis 
> wrote:
> > I looked up the source to the decorator
> > found here:
> http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py
> > for anyone interested.
>
> Strangely, line indentation seems to be swallowed in the web view of
> the Mercurial tree. The code directly follows the line numbers, so it
> goes ragged between (eg) lines 9 and 10. Is this a browser bug? I
> tried on Chrome 26.0.1410.40 and Firefox 19.0.2 on Windows.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatting lost in hg-web (was Re: with ignored)

2013-04-08 Thread Chris Angelico
On Mon, Apr 8, 2013 at 5:36 PM, Barrett Lewis  wrote:
> I am viewing it on Chrome Version 26.0.1410.43 m for windows and it works
> perfectly for me.

Huh. Extremely weird. Ctrl-F5 fixed it, and now the source looks
different. Either someone's *right now* editing stuff (in which case
I'll shut up and let him/her do so), or there's something insanely
weird in my system. Which is possible... Windows XP, second-last
bastion of real Windows in my control...

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


How to do a Lispy-esque read?

2013-04-08 Thread zeta . convex
Suppose I want to read an object from some stream. How do I do it?

For example, if the input stream contained the text:
[1, # python should ignore this comment
2]

and I do a "read" on it, I should obtain the result
[1, 2]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to do a Lispy-esque read?

2013-04-08 Thread Barrett Lewis
> For example, if the input stream contained the text:
> [1, # python should ignore this comment
> 2]
>
> and I do a "read" on it, I should obtain the result
> [1, 2]
> --
>

I don't know much about lisp but given that input and the desired output
you can write functions like the following

def strtolist(l):
if l.startswith('['):
l = l[1:]
if l.endswith(']'):
l = l[:-1]

# treat newlines as if they are commas so we can easily split
l = l.replace('\n', ',').split(',')
# list comprehension
# strip to remove whitespace and aggregate all elements without the
comment
# you can further refine this to create ints by using the int() method
return [x for x in l if not x.strip().startswith('#')]

you would have to use input() to read the input or open a file. Either way
you can pass that value to strtolist and it will convert it to a list of
strings.
However, this implementation is not very robust and doesn't cover a lot of
edge cases (more a demo of how it might be done, I don't know your python
experience so forgive me if this is all self evident).

The real solution that I would use would be to use the json module.
Docs: http://docs.python.org/3.3/library/json.html
It allows you to take a string and turn it into a native dict or list in
python. The great part is that it is fairly robust and it has a simple
interface. You could take input() and send it to loads and it will return
an array. The downside is json doesn't allow comments.

If you really want comments, you could look into some of the yaml
libraries, a quick google search shoes PyYaml is out there. I however don't
have any knowledge of that module or other yaml modules as I find json is
enough for anything I've ever attempted.

I hope that helps
-- 
http://mail.python.org/mailman/listinfo/python-list


Interactive development in Python à la Smalltalk?

2013-04-08 Thread Bienlein
Hello,

I'm absolutely new to Python, just looked at the language description for the 
first time. The first thought that came to my mind was whether you can program  
in Python in an interactive programming style, i.e. I can change code in the 
debugger which becomes immediately effective (no edit-compile loop) and I can 
also send messages to objects visible inside the debugger. 

Then Python could become my replacemenet for my dearly missed Smalltalk, which 
to my great grief meanwhile really has become quite dead, I fear. In Smalltalk 
you can open up an inspector window (e.g. you don't have to get into debug 
mode), inspect objects in it and evaluate code in it, send messaages to 
objects. I guess this cannot be done in Python out of the box. But if changes 
made in the debugger became immediately effective, this would be interactive 
enough for my purposes.

Thanks, Bienlein
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to do a Lispy-esque read?

2013-04-08 Thread Benjamin Kaplan
There is no "read in a stream until it's a valid literal" function as
far as I know, but ast.literal_eval will turn your string into an
object.

On Mon, Apr 8, 2013 at 12:45 AM,   wrote:
> Suppose I want to read an object from some stream. How do I do it?
>
> For example, if the input stream contained the text:
> [1, # python should ignore this comment
> 2]
>
> and I do a "read" on it, I should obtain the result
> [1, 2]
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mock django cache

2013-04-08 Thread Jean-Michel Pichavant


- Original Message -
> In my settings.py , I have specified my cache as :
> CACHES = {
> 'default': {
> ..
> }
> }
> 
> In my views.py, I have
> 
> import requests
> from django.core.cache import cache, get_cache
> 
> def aview():
> #check cache
> if not get_cache('default').get('key'):
> #make request and save in cache
> result = request.get('some_url')
> get_cache('default').set('key', result)
> return result
> else:
> return get_cache('default').get('key')
> 
> 
> Now in my tests.py, I have been able to mock requests.get('aurl'), so
> that makes sure that no external requests are made.
> 
> But the test code still hits the cache and gets/sets from it. So if
> my prod has already set the cache, then test is failing because it
> gets the data from same cache. Or if I run my tests first, then the
> test case is setting the cache with test data and I see that same
> reflected when I run prod website.
> 
> How can I mock the calls to get_cache('default').set('key', result)
> and get_cache('default').get('key') so that the set call does not
> sets the real cache ( return None?) and get does not return anything
> in actual cache.
> 
> Please provide me with code sample to how to get this done.
> 
> Here is how I have mocked my requests.get
> 
> def test_get_aview(self):
> with mock.patch('requests.get') as mymock:
> mymock.side_effect = (lambda url: MOCKED_DATA[url])
> 
> What code can I put after this to make it work? I tried something
> like
> 
> 
> class MockCacheValue(mock.MagicMock):
> def get(self, key):
> print 'here'
> return None
> def set(self, key, value):
> print 'here 2'
> pass
> 
> def test_get_aview(self):
> with mock.patch('requests.get') as mymock:
> mymock.side_effect = (lambda url: MOCKED_DATA[url])
> mock.patch('django.core.cache.get_cache',
> new=MockCacheValue)
> 
> but it does not work and putting a print statement inside get/set
> above does not print anything giving me an idea that its not mocked
> properly


Having a quick look at django doc, get_cache() returns a cache which has get 
set methods, so you need get_cache to return a Mock object that mock the get 
and set method.

Try something like :

mock.patch('django.core.cache.get_cache',Mock(return_value=MockCacheValue())

JM


-- IMPORTANT NOTICE: 

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


help needed

2013-04-08 Thread leonardo selmi
hello all,

i have typed the following program from the book "learn python the hard way":

from sys import argv

script, first, second, third = argv

print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
then i get this error:

Traceback (most recent call last):
  File "/Users/leonardo/Documents/ex13.py", line 3, in 
script, first, second, third = argv
ValueError: need more than 1 value to unpack

in the book the author says that i should run the program like this:

$ python ex13.py first 2nd 3rd
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
but how can i do that?? what are the steps? where should i go?
thanks!

best regards
leonardo-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread Barrett Lewis
Do you happen to be on windows? Because if you are then you need to edit
the registry. If you are on windows let me know and I will walk you through
the fix, but if not then it would be a waste of time for me to explain it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread Adam Mesha
On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi  wrote:

> then i get this error:
>
> Traceback (most recent call last):
>   File "/Users/leonardo/Documents/ex13.py", line 3, in 
> script, first, second, third = argv
> ValueError: need more than 1 value to unpack
>

You didn't provide any arguments to the script.


> in the book the author says that i should run the program like this:
>
> $ python ex13.py first 2nd 3rdThe script is called: ex13.pyYour first 
> variable is: firstYour second variable is: 2ndYour third variable is: 3rd
>
> but how can i do that?? what are the steps? where should i go?
>

You need to open a command line terminal and type the first line (without
the dollar sign). You will need to change your directory to the directory
that contains your exercise script, probably by doing "cd
/path/to/exercise/directory". If you're on Windows it's the same idea, you
run the "cmd" program, but you would have to specify the full path to the
python interpreter instead of just "python", or follow the directions that
have been offered for fixing Windows.

Adam
www.mesha.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interactive development in Python à la Smalltalk?

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 01:33:13 -0700, Bienlein wrote:

> Hello,
> 
> I'm absolutely new to Python, just looked at the language description
> for the first time. The first thought that came to my mind was whether
> you can program  in Python in an interactive programming style, i.e. I
> can change code in the debugger which becomes immediately effective (no
> edit-compile loop) and I can also send messages to objects visible
> inside the debugger.

Out of the box, Python comes with an extremely powerful interactive 
environment. Just launch Python from the command prompt with no 
arguments, and it will open an interactive interpreter that allows you to 
enter commands, hit enter, and have them executed.

I strongly recommend you work through at least the beginning of the 
tutorial, and get used to the interactive interpreter. Here's the one for 
Python 2:

http://docs.python.org/2/tutorial/index.html

and version 3:

http://docs.python.org/3/tutorial/index.html



If that's not enough for you, there are third-party Python interpreters 
that do much more, such as BPython, IPython and DreamPie.

http://bpython-interpreter.org/screenshots/

http://ipython.org/index.html 

http://www.dreampie.org/.

IPython will be especially familiar to those used to Mathematica.


You can't quite edit code in live objects -- code is compiled to byte-
code for a virtual machine, and you cannot edit that -- but you can 
easily redefine objects, including functions and methods, on the fly.


py> class Test(object):
... def method(self, arg):
... print "argument received:", arg
... 
py> 
py> t = Test()
py> t.method(23)
argument received: 23
py> 
py> def method(self, arg):
... print "argument received:", arg+1000
... 
py> Test.method = method
py> t.method(23)
argument received: 1023



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


Re: help needed

2013-04-08 Thread leonardo

thanks barrett, but i am using a mac..



Il 08/04/2013 11.15, Barrett Lewis ha scritto:
Do you happen to be on windows? Because if you are then you need to 
edit the registry. If you are on windows let me know and I will walk 
you through the fix, but if not then it would be a waste of time for 
me to explain it.





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


How to subclass a family

2013-04-08 Thread Antoon Pardon
Here is the idea. I have a number of classes with the same interface.
Something like the following:

class Foo1:
def bar(self, ...):
work
def boo(self, ...):
do something
self.bar(...)

What I want is the equivallent of:

class Far1(Foo1):
def boo(self, ...)
do something different
if whatever:
self.bar(...)
else:
Foo1.boo(self, ...)

Now of course I could subclass every class from the original family
from Foo1 to Foon but that would mean a lot of duplicated code. Is
there a way to reduce the use of duplicated code in such circumstances?

-- 
Antoon Pardon

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


Re: help needed

2013-04-08 Thread Chris Angelico
On Mon, Apr 8, 2013 at 7:29 PM, leonardo  wrote:
> thanks barrett, but i am using a mac..

Open up Terminal - that'll give you a window with a bash prompt.
Proceed from there; it's the same as the default shell on many
Linuxes.

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


Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread bhk755
I am trying to create 2D arrays without using advanced features like numpy, for 
this I have created 2 separate modules arrays.py and array2D.py. Here's the 
code for that:

arrays.py module:
==
import ctypes

class Array:

#Creates an array with size elements.
def __init__( self, size ):
assert size > 0, "Array size must be > 0"
self._size = size
print "sixe is %s" %self._size

 # Create the array structure using the ctypes module.
PyArrayType = ctypes.c_int * size
self._elements = PyArrayType()
print "type is e", type(self._elements)
#self._elements = ctypes.c_int * size

print "Elements are self.element %s" % self._elements
# Initialize each element.
#for i in range(self._size):
#   self.clear( i )


# Returns the size of the array.
def __len__( self ):
return self._size

# Gets the contents of the index element.
def __getitem__( self, index ):
assert index >= 0 and index < len(self), "Array subscript out of range"
return self._elements[ index ]

# Puts the value in the array element at index position.
def __setitem__( self, index, value ):
assert index >= 0 and index < len(self), "Array subscript out of range"
print "Type is ", type(index)
self._elements[ index ] = value

# Clears the array by setting each element to the given value.
def clear( self, value ):
for i in range( len(self) ) :
self._elements[i] = value

# Printing the arrays:
def __str__(self):
return self._elements



array2D.py module
==


import arrays

class Array2D :
# Creates a 2-D array of size numRows x numCols.
def __init__( self, numRows, numCols ):
# Create a 1-D array to store an array reference for each row.

self._theRows = arrays.Array( numRows )
# Create the 1-D arrays for each row of the 2-D array.
print "Num of Cloumns is", numCols

for i in range( numRows ) :
self._theRows[i] = arrays.Array( numCols )

# Returns the number of rows in the 2-D array.
def numRows( self ):
return len( self._theRows )

# Returns the number of columns in the 2-D array.
def numCols( self ):
return len( self._theRows[0] )

# Clears the array by setting every element to the given value.
def clear( self, value ):
for row in range( self.numRows() ):
row.clear( value )

# Gets the contents of the element at position [i, j]
def __getitem__( self, ndxTuple ):
assert len(ndxTuple) == 2, "Invalid number of array subscripts."
row = ndxTuple[0]
col = ndxTuple[1]
assert row >= 0 and row < self.numRows() \
and col >= 0 and col < self.numCols(), \
"Array subscript out of range."
the1dArray = self._theRows[row]
return the1dArray[col]

# Sets the contents of the element at position [i,j] to value.
def __setitem__( self, ndxTuple, value ):
#assert len(ndxTuple) == 3, "Invalid number of array subscripts."
row = ndxTuple[0]
col = ndxTuple[1]
assert row >= 0 and row < self.numRows() \
and col >= 0 and col < self.numCols(), \
"Array subscript out of range."
the1dArray = self._theRows[row]
the1dArray[col] = value


arr = Array2D(2,4)

print "arr is %s" %arr


Traceback is :

sixe is 2
type is e 
Elements are self.element 
Cols in 4
Num of Cloumns is 4
!! i is 0
sixe is 4
type is e 
Elements are self.element 
Type is  
Traceback (most recent call last):
  File "C:\Python27\Lib\array2D.py", line 53, in 
arr = Array2D(2,4)
  File "C:\Python27\Lib\array2D.py", line 16, in __init__
self._theRows[i] = arrays.Array( numCols )
  File "C:\Python27\Lib\arrays.py", line 36, in __setitem__
self._elements[ index ] = value
AttributeError: Array instance has no attribute '__trunc__'
-- 
http://mail.python.org/mailman/listinfo/python-list


Displaying colours in saved script

2013-04-08 Thread Casperb
Hi all,

I'm new to Python and have a pretty basic question, explained in the following 
screendump:

http://i.imgur.com/oaCuKp5.jpg

After I save my script, the nice colours that make the code easier to read 
disappear.  How do I stop that from happening?

Any help much appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Jake D
On Apr 7, 6:36 pm, Steven D'Aprano  wrote:
> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote:
> > Actually, my current licence can be found here:
> >https://github.com/jhunter-d/im.py/blob/master/LICENCE.  Whaddaya think
> > about this, Useneters?
>
> I think you're looking for a world of pain, when somebody uses your
> software, it breaks something, and they sue you. Your licence currently
> means that you are responsible for the performance of your software.
>
> Why don't you use a recognised, tested, legally-correct licence, like the
> MIT licence, instead of trying to be clever and/or lazy with a one-liner?
>
> E.g.http://opensource.org/licenses/MIT
>
> Software licencing is a solved problem. Do you really think that people
> write three or four paragraph licences because they *like* legal
> boilerplate? Did you imagine that you were the first person to think, "I
> know! I'll write a one-liner telling people they can do whatever they
> want with my software! Nothing can possibly go wrong!"?
>
> Use a known, tested, working solution, and save yourself the pain.
>
> --
> Steven

MIT is actually the best one I've seen so far.  I'm updating LICENCE.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Displaying colours in saved script

2013-04-08 Thread Dave Angel

On 04/08/2013 06:32 AM, Casperb wrote:

Hi all,

I'm new to Python and have a pretty basic question, explained in the following 
screendump:

http://i.imgur.com/oaCuKp5.jpg

After I save my script, the nice colours that make the code easier to read 
disappear.  How do I stop that from happening?

Any help much appreciated.



Python source code is a plain text file, which has no colors.  The 
colors are used by your Python Shell only for displaying to the screen.


When Python Shell reloads Python source, it presumably reparses the text 
and shows it with colors.  My guess is that by naming the file without a 
.py extension, you convinced Python Shell that it was NOT source code, 
and therefore shouldn't be colorized.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


subprocess question re waiting

2013-04-08 Thread loial
I want to call a child process to run a shell script and wait for that script 
to finish. Will the code below wait for the script to finish? If not then how 
do I make it wait?

Any help appreciated.


import subprocess

command = "/home/john/myscript"

process = subprocess.Popen(command, 
stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
close_fds=True, shell=True)

out, err = process.communicate()
returncode = process.returncode
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread leonardo

thanks adam, but it is not clear to me yet.
if i open the terminal how do i work on it? what should i type in?

thanks


Il giorno 08/apr/2013, alle ore 11:25, Adam Mesha  ha scritto:

> On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi  wrote:
> then i get this error:
> 
> Traceback (most recent call last):
>   File "/Users/leonardo/Documents/ex13.py", line 3, in 
> script, first, second, third = argv
> ValueError: need more than 1 value to unpack
> 
> You didn't provide any arguments to the script.
>  
> in the book the author says that i should run the program like this:
> 
> $ python ex13.py first 2nd 3rd
> The script is called: ex13.py
> Your first variable is: first
> Your second variable is: 2nd
> Your third variable is: 3rd
> but how can i do that?? what are the steps? where should i go?
> 
> You need to open a command line terminal and type the first line (without the 
> dollar sign). You will need to change your directory to the directory that 
> contains your exercise script, probably by doing "cd 
> /path/to/exercise/directory". If you're on Windows it's the same idea, you 
> run the "cmd" program, but you would have to specify the full path to the 
> python interpreter instead of just "python", or follow the directions that 
> have been offered for fixing Windows.
> 
> Adam
> www.mesha.org
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Re: help needed

2013-04-08 Thread Dave Angel

On 04/08/2013 07:24 AM, leonardo wrote:


thanks adam, but it is not clear to me yet.
if i open the terminal how do i work on it? what should i type in?


Please don't top-post.  It kills off the context.

Go back to the previous message and you'll see Adam tells you exactly 
what to type at the terminal.  But to be more literal:


python ex13.py  first 2nd 3rd



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Alain Ketterlin
loial  writes:

> I want to call a child process to run a shell script and wait for that
> script to finish. Will the code below wait for the script to finish?
> If not then how do I make it wait?
[...]
> process = subprocess.Popen(command, 
> stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
> close_fds=True, shell=True)

process.wait()

-- Alain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help needed

2013-04-08 Thread rusi
On Apr 8, 4:41 pm, Dave Angel  wrote:

> Go back to the previous message and you'll see Adam tells you exactly
> what to type at the terminal.  But to be more literal:
>
> python ex13.py  first 2nd 3rd


followed by RET (also called ENTER) key
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin  wrote:

> loial  writes:
>
> > I want to call a child process to run a shell script and wait for that
> > script to finish. Will the code below wait for the script to finish?
> > If not then how do I make it wait?
> [...]
> > process = subprocess.Popen(command,
> stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE,
> close_fds=True, shell=True)
>
> process.wait()
>

Or use subprocess.call instead which does what you want.


> -- Alain.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dave Angel

On 04/08/2013 08:01 AM, Dylan Evans wrote:

On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin 
wrote:



loial  writes:


I want to call a child process to run a shell script and wait for that
script to finish. Will the code below wait for the script to finish?
If not then how do I make it wait?

[...]

process = subprocess.Popen(command,

stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True, shell=True)

process.wait()



Or use subprocess.call instead which does what you want.



-- Alain.
--
http://mail.python.org/mailman/listinfo/python-list





http://docs.python.org/2/library/subprocess.html#popen-objects

or use communicate(), which is what the OP had in the first place.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dave Angel

On 04/08/2013 07:00 AM, loial wrote:

I want to call a child process to run a shell script and wait for that script 
to finish. Will the code below wait for the script to finish? If not then how 
do I make it wait?

Any help appreciated.


import subprocess

command = "/home/john/myscript"

process = subprocess.Popen(command, 
stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
close_fds=True, shell=True)

out, err = process.communicate()
returncode = process.returncode



Yes, communicate() will block until the child process is complete.

  http://docs.python.org/2/library/subprocess.html#popen-objects

Note the phrase:  "Wait for process to terminate."  That's referring to 
the shell in your case.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Interactive development in Python à la Smalltalk?

2013-04-08 Thread Colin J. Williams

On 08/04/2013 4:33 AM, Bienlein wrote:

Hello,

I'm absolutely new to Python, just looked at the language description for the 
first time. The first thought that came to my mind was whether you can program  
in Python in an interactive programming style, i.e. I can change code in the 
debugger which becomes immediately effective (no edit-compile loop) and I can 
also send messages to objects visible inside the debugger.

Then Python could become my replacemenet for my dearly missed Smalltalk, which 
to my great grief meanwhile really has become quite dead, I fear. In Smalltalk 
you can open up an inspector window (e.g. you don't have to get into debug 
mode), inspect objects in it and evaluate code in it, send messaages to 
objects. I guess this cannot be done in Python out of the box. But if changes 
made in the debugger became immediately effective, this would be interactive 
enough for my purposes.

Thanks, Bienlein


If you are using Windows, PyScripter is a good choice.

I understand that, with Linux, it can also be used with Wine.  I haven't 
tried that.


Colin W.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 8:07 PM,  wrote:

> I am trying to create 2D arrays without using advanced features like
> numpy, for this I have created 2 separate modules arrays.py and array2D.py.
> Here's the code for that:
>
> arrays.py module:
> ==
> import ctypes
>
> class Array:
>
> #Creates an array with size elements.
> def __init__( self, size ):
> assert size > 0, "Array size must be > 0"
> self._size = size
> print "sixe is %s" %self._size
>
>  # Create the array structure using the ctypes module.
> PyArrayType = ctypes.c_int * size
> self._elements = PyArrayType()
> print "type is e", type(self._elements)
> #self._elements = ctypes.c_int * size
>
> print "Elements are self.element %s" % self._elements
> # Initialize each element.
> #for i in range(self._size):
> #   self.clear( i )
>
>
> # Returns the size of the array.
> def __len__( self ):
> return self._size
>
> # Gets the contents of the index element.
> def __getitem__( self, index ):
> assert index >= 0 and index < len(self), "Array subscript out of
> range"
> return self._elements[ index ]
>
> # Puts the value in the array element at index position.
> def __setitem__( self, index, value ):
> assert index >= 0 and index < len(self), "Array subscript out of
> range"
> print "Type is ", type(index)
> self._elements[ index ] = value
>
> # Clears the array by setting each element to the given value.
> def clear( self, value ):
> for i in range( len(self) ) :
> self._elements[i] = value
>
> # Printing the arrays:
> def __str__(self):
> return self._elements
>
>
>
> array2D.py module
> ==
>
>
> import arrays
>
> class Array2D :
> # Creates a 2-D array of size numRows x numCols.
> def __init__( self, numRows, numCols ):
> # Create a 1-D array to store an array reference for each row.
>
> self._theRows = arrays.Array( numRows )
> # Create the 1-D arrays for each row of the 2-D array.
> print "Num of Cloumns is", numCols
>
> for i in range( numRows ) :
> self._theRows[i] = arrays.Array( numCols )
>
> # Returns the number of rows in the 2-D array.
> def numRows( self ):
> return len( self._theRows )
>
> # Returns the number of columns in the 2-D array.
> def numCols( self ):
> return len( self._theRows[0] )
>
> # Clears the array by setting every element to the given value.
> def clear( self, value ):
> for row in range( self.numRows() ):
> row.clear( value )
>
> # Gets the contents of the element at position [i, j]
> def __getitem__( self, ndxTuple ):
> assert len(ndxTuple) == 2, "Invalid number of array subscripts."
> row = ndxTuple[0]
> col = ndxTuple[1]
> assert row >= 0 and row < self.numRows() \
> and col >= 0 and col < self.numCols(), \
> "Array subscript out of range."
> the1dArray = self._theRows[row]
> return the1dArray[col]
>
> # Sets the contents of the element at position [i,j] to value.
> def __setitem__( self, ndxTuple, value ):
> #assert len(ndxTuple) == 3, "Invalid number of array subscripts."
> row = ndxTuple[0]
> col = ndxTuple[1]
> assert row >= 0 and row < self.numRows() \
> and col >= 0 and col < self.numCols(), \
> "Array subscript out of range."
> the1dArray = self._theRows[row]
> the1dArray[col] = value
>
>
> arr = Array2D(2,4)
>
> print "arr is %s" %arr
>
>
> Traceback is :
>
> sixe is 2
> type is e 
> Elements are self.element 
> Cols in 4
> Num of Cloumns is 4
> !! i is 0
> sixe is 4
> type is e 
> Elements are self.element 
> Type is  
> Traceback (most recent call last):
>   File "C:\Python27\Lib\array2D.py", line 53, in 
> arr = Array2D(2,4)
>   File "C:\Python27\Lib\array2D.py", line 16, in __init__
> self._theRows[i] = arrays.Array( numCols )
>   File "C:\Python27\Lib\arrays.py", line 36, in __setitem__
> self._elements[ index ] = value
> AttributeError: Array instance has no attribute '__trunc__'
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Not sure about the __trunc__ problem but i can suggest this alternative
which is a bit simpler

def array2D(x, y, val=None):
return [[val for col in xrange(x)] for row in xrange(y)]


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess question re waiting

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 10:22 PM, Dave Angel  wrote:

> On 04/08/2013 08:01 AM, Dylan Evans wrote:
>
>> On Mon, Apr 8, 2013 at 9:48 PM, Alain Ketterlin <
>> al...@dpt-info.u-strasbg.fr
>>
>>> wrote:
>>>
>>
>>  loial  writes:
>>>
>>>  I want to call a child process to run a shell script and wait for that
 script to finish. Will the code below wait for the script to finish?
 If not then how do I make it wait?

>>> [...]
>>>
 process = subprocess.Popen(command,

>>> stdin=subprocess.PIPE,stdout=**subprocess.PIPE, stderr=subprocess.PIPE,
>>> close_fds=True, shell=True)
>>>
>>> process.wait()
>>>
>>>
>> Or use subprocess.call instead which does what you want.
>>
>>
Actually after having a look through the manual i like check_output for
this since it simplifies the code, but some extra exception handling would
be required if the output is still required when the script exits with a
non zero value, so it's a bit of a trade off.


>  -- Alain.
>>> --
>>> http://mail.python.org/**mailman/listinfo/python-list
>>>
>>>
>>
> http://docs.python.org/2/**library/subprocess.html#popen-**objects
>
> or use communicate(), which is what the OP had in the first place.
>
>
> --
> DaveA
> --
> http://mail.python.org/**mailman/listinfo/python-list
>



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread dbv
In 2.7.4, io.py shows:

import _io
import abc

from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation,
 open, FileIO, BytesIO, StringIO, BufferedReader,
 BufferedWriter, BufferedRWPair, BufferedRandom,
 IncrementalNewlineDecoder, TextIOWrapper)

but, cannot find _io.py, though there is the old _pyio.py in the 
//Python27//Lib folder.

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


Re: Splitting of string at an interval

2013-04-08 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Mon, Apr 8, 2013 at 7:48 AM, Steven D'Aprano
>  wrote:
> > Like every programming problem, the solution is to break it apart into
> > small, simple steps that even a computer can follow.
> > ...
> 
> 5) Shortcut the whole thing, since the problem was underspecified, by
> using a literal.
> 
> words = ["The Sun", "rises in", "in the", "east of", "our earth"]
> 
> *dive for cover against rotten tomatoes*

Seems like the right solution to me.

For a while, I was rabidly(*) into TDD (Test Driven Development).  The 
cycle I was using was, "Write a specification of a behavior, write a 
(failing) test for that behavior, then write the least possible amount 
of code to make the test pass.  Lather, Rinse, Repeat, Ship"

The "least possible" part is important.  It makes sure the cycles stay 
short (ideally, just a few minutes), and that you don't write any code 
for which you don't have tests.  If you buy into that plan, then I see 
nothing wrong with your suggested solution.

(*) I still believe in TDD, but I don't practice it quite as 
enthusiastically as I used to.  Which probably means my code isn't as 
good as it used to be.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread Dylan Evans
On Mon, Apr 8, 2013 at 11:12 PM, dbv  wrote:

> In 2.7.4, io.py shows:
>
> import _io
> import abc
>
> from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError,
> UnsupportedOperation,
>  open, FileIO, BytesIO, StringIO, BufferedReader,
>  BufferedWriter, BufferedRWPair, BufferedRandom,
>  IncrementalNewlineDecoder, TextIOWrapper)
>
> but, cannot find _io.py, though there is the old _pyio.py in the
> //Python27//Lib folder.
>
> >>> _io.__file__
'/usr/lib/python2.7/lib-dynload/_io.so'

Looks like it's implemented in C.



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



-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread dbv
Ah, okay.  Then on Windows, _io.pyd should be in the /DLLs folder but it isn't 
there ?

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


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread dbv
_io is a builtin module
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The usage of -m option of python

2013-04-08 Thread Albert van der Horst
In article ,
Terry Reedy   wrote:
>On 3/18/2013 5:17 PM, Peng Yu wrote:
>> Hi,
>>
>> I don't quite understand how -m option is used. And it is difficult to
>> search for -m in google. Could anybody provide me with an example on
>> how to use this option?
>
>python -m test
>at a command line runs the regression tests in the test package
>python -m test -v test_difflib
>runs test.test_difflib in verbose mode.

I get for both :
"/usr/bin/python: test is a package and cannot be directly executed."

What gives?

(Official stable Debian distribution. Python 2.7)

>--
>Terry Jan Reedy
>

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 14:21, Roy Smith  wrote:

> For a while, I was rabidly(*) into TDD (Test Driven Development).  The
> cycle I was using was, "Write a specification of a behavior, write a
> (failing) test for that behavior, then write the least possible amount
> of code to make the test pass.  Lather, Rinse, Repeat, Ship"
>
> The "least possible" part is important.  It makes sure the cycles stay
> short (ideally, just a few minutes), and that you don't write any code
> for which you don't have tests.

The least amount of code is often also not the best in terms of time
or space complexity.  Does this mean you have to write tests for time
and space complexity as well?  That's interesting, but I don't know of
tools to help do that (time complexity seems easy enough, but space
complexity seems tougher to me).

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread Thomas Rachel

Am 08.04.2013 15:42 schrieb dbv:

Ah, okay.  Then on Windows, _io.pyd should be in the /DLLs folder but it isn't 
there ?


It seems to be a built-in module:

>>> import _io
>>> _io


alike to

>>> import __builtin__
>>> __builtin__


as opposed to

>>> import win32ui
>>> win32ui
'C:\Python27\lib\site-packages\Pythonwin\win32ui.pyd'>


and

>>> import os
>>> os



Thomas
--
http://mail.python.org/mailman/listinfo/python-list


USBLock : lock/unlock your computer with a USB key

2013-04-08 Thread Sven
I've been working on a little project and have a working Linux
implementation so far. Basically it allows a user to use any USB stick as a
key to lock and unlock their computer. More info in the repo or PyPi
https://pypi.python.org/pypi/USBLock

Basically run the program with -a to add a device (added once you insert
it), then run it without any arguments. Insert the key again, and when you
remove it your computer will lock. Insert the key again and it will unlock.
It's not intended to provide military grade security, it's more of a
convenience tool to launch built in screen locking software.

Currently it locks a Linux box with xlock, pending a better solution.

I wrote it as an exercise in playing around with USB media and events, and
also because I needed a use for these old USB keys I have lying around :)

Always looking for contributions, suggestions and improvements. Especially
OS X and Win support.

Repo:
https://github.com/Svenito/usblock

Thanks for your time.

-- 
./Sven
-- 
http://mail.python.org/mailman/listinfo/python-list


Interactrive Python under Cygwin in Win7

2013-04-08 Thread Grant Edwards
I just installed ActiveState 2.7 64-bit on a Windows 7 machine running
a current version of Cygwin.  While python programs (both GUI and
text-mode) run fine, I'm unable to use Python interactively from
either the Cygwin terminal or in an ssh session.  I tried adding the
"-u" option, but that makes no difference.  Interactive C-Python just
hangs on startup.

Is this bug specific to ActiveState Python, or is it also present in
the vanilla C-Python build for Windows?

-- 
Grant Edwards   grant.b.edwardsYow! I want you to MEMORIZE
  at   the collected poems of
  gmail.comEDNA ST VINCENT MILLAY
   ... BACKWARDS!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting of string at an interval

2013-04-08 Thread Roy Smith

On Apr 8, 2013, at 11:10 AM, Arnaud Delobelle wrote:

> On 8 April 2013 14:21, Roy Smith  wrote:
> 
>> For a while, I was rabidly(*) into TDD (Test Driven Development).  The
>> cycle I was using was, "Write a specification of a behavior, write a
>> (failing) test for that behavior, then write the least possible amount
>> of code to make the test pass.  Lather, Rinse, Repeat, Ship"
>> 
>> The "least possible" part is important.  It makes sure the cycles stay
>> short (ideally, just a few minutes), and that you don't write any code
>> for which you don't have tests.
> 
> The least amount of code is often also not the best in terms of time
> or space complexity.  Does this mean you have to write tests for time
> and space complexity as well?  That's interesting, but I don't know of
> tools to help do that (time complexity seems easy enough, but space
> complexity seems tougher to me).


If space and time complexity are important, then you need to write a test for 
those things.  If you have no test for them, then it's not important and you 
shouldn't worry about it.  At least according to the TDD catechism :-)

>From a somewhat less radical point of view, the first thing you want to do is 
>get the code to produce correct results.  Once you've got that (and a fully 
>comprehensive test suite to prove it), then you can move on to making it more 
>efficient, and your test suite serves as protection against behavior 
>regressions.

And, yes, I agree that testing for time and space complexity are not trivial, 
because making accurate, repeatable, and isolated measurements of those things 
is often surprisingly complicated.  I can't help point out, however, that if 
your initial implementation is to have your code return a constant, it's pretty 
likely to be an optimum solution in both time and space :-)

---
Roy Smith
r...@panix.com

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


Re: Splitting of string at an interval

2013-04-08 Thread Chris Angelico
On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith  wrote:
> I can't help point out, however, that if your initial implementation is to 
> have your code return a constant, it's pretty likely to be an optimum 
> solution in both time and space :-)

Likely, but not certain.

# 1
def fifty_stars():
  return "**"

# 2
fifty_stars=lambda "*"*50

Okay, that's just getting 2AM stupid now. :)

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


Re: Splitting of string at an interval

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 17:20, Chris Angelico  wrote:
> On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith  wrote:
>> I can't help point out, however, that if your initial implementation is to 
>> have your code return a constant, it's pretty likely to be an optimum 
>> solution in both time and space :-)
>
> Likely, but not certain.
>
> # 1
> def fifty_stars():
>   return "**"
>
> # 2
> fifty_stars=lambda "*"*50

There's a whole competition about writing the smallest program which
outputs the song "99 bottles of beer":

http://codegolf.com/99-bottles-of-beer

Cheers,

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to do a Lispy-esque read?

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 08:45,   wrote:
> Suppose I want to read an object from some stream. How do I do it?
>
> For example, if the input stream contained the text:
> [1, # python should ignore this comment
> 2]
>
> and I do a "read" on it, I should obtain the result
> [1, 2]

You might be interested in code.compile_command()
(http://docs.python.org/2/library/code.html)

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-08 Thread Nobody
On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:

> Am I the only one here who has used a typewriter?
> 
> Tab stops were set manually, to a physical distance into the page, using 
> a mechanical stop. This long predates the "rule" that tab stops are every 
> 8 characters.

And your point is?

Typewriters don't have a tab "character". The information regarding tab
stops is conveyed out-of-band from the typist to the typewriter, and
doesn't need to persist beyond the time taken to type the document.

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


Re: The usage of -m option of python

2013-04-08 Thread Terry Jan Reedy

On 4/8/2013 10:50 AM, Albert van der Horst wrote:

In article ,
Terry Reedy   wrote:

On 3/18/2013 5:17 PM, Peng Yu wrote:

Hi,

I don't quite understand how -m option is used. And it is difficult to
search for -m in google. Could anybody provide me with an example on
how to use this option?


python -m test
at a command line runs the regression tests in the test package
python -m test -v test_difflib
runs test.test_difflib in verbose mode.


I get for both :
"/usr/bin/python: test is a package and cannot be directly executed."

What gives?

(Official stable Debian distribution. Python 2.7)


For me, 3.3 is default Python.

Look in the 2.7 doc for 'test' and I believe it will tell you that you 
need to write 'test.regrtest'.


tjr



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


Re: Interactive development in Python à la Smalltalk?

2013-04-08 Thread Terry Jan Reedy

On 4/8/2013 4:33 AM, Bienlein wrote:

Hello,

I'm absolutely new to Python, just looked at the language description
for the first time. The first thought that came to my mind was
whether you can program  in Python in an interactive programming
style, i.e. I can change code in the debugger which becomes
immediately effective (no edit-compile loop) and I can also send
messages to objects visible inside the debugger.


The CPython interpreter has both a 'batch' mode (run code in a file) and 
an interactive mode (run code typed in response to a prompt). It also 
has a '-i' option to run code in batch mode and then switch to 
interactive mode so one can interrogate visible objects and call functions.


The Idle IDE has editor windows linked to an interactive shell. When you 
run code in the editor window, it saves and runs it with the -i option 
so you can interactive with the results in the Shell. Compiling edited 
text to bytecode is typically so fast (well under a second) as to not be 
an issue.



Then Python could become my replacemenet for my dearly missed
Smalltalk, which to my great grief meanwhile really has become quite
dead, I fear. In Smalltalk you can open up an inspector window (e.g.
you don't have to get into debug mode), inspect objects in it and
evaluate code in it, send messaages to objects. I guess this cannot
be done in Python out of the box. But if changes made in the debugger
became immediately effective, this would be interactive enough for my
purposes.


Idle also has a debugger window that does some of that, though it works 
better on non-Windows OSes. I have never actually used it.


---
Terry Jan Reedy


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


Re: I hate you all

2013-04-08 Thread Grant Edwards
On 2013-04-08, Nobody  wrote:
> On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:
>
>> Am I the only one here who has used a typewriter?
>> 
>> Tab stops were set manually, to a physical distance into the page, using 
>> a mechanical stop. This long predates the "rule" that tab stops are every 
>> 8 characters.
>
> And your point is?

The point is that there is little historical precedent for assuming
that tab stops are evenly and equally spaced across the page (let
alone one particular fixed, even spacing) -- and people who mix spaces
and tabs based on such false assumptions are responsible for their own
bleeding foot.

> Typewriters don't have a tab "character". The information regarding tab
> stops is conveyed out-of-band from the typist to the typewriter, and
> doesn't need to persist beyond the time taken to type the document.

And the same is true when you don't mix tabs and spaces when indenting
Python code.  If you use tabs alone when indenting Python code it
doesn't matter where the tabs are set -- they don't even have to be
equally spaced -- the meaning of the source file is unambiguous.

If you mix tabs and spaces, then you've got to provide out-of-band
information regarding the position of the tab stops in order to make
the source code unambiguous.  Since there's no mechanism to provide
that OOB tab stop info, mixed tabs and spaces isn't accepted.

-- 
Grant Edwards   grant.b.edwardsYow! I am covered with
  at   pure vegetable oil and I am
  gmail.comwriting a best seller!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interactrive Python under Cygwin in Win7

2013-04-08 Thread David Robinow
On Mon, Apr 8, 2013 at 11:20 AM, Grant Edwards wrote:

> I just installed ActiveState 2.7 64-bit on a Windows 7 machine running
> a current version of Cygwin.  While python programs (both GUI and
> text-mode) run fine, I'm unable to use Python interactively from
> either the Cygwin terminal or in an ssh session.  I tried adding the
> "-u" option, but that makes no difference.  Interactive C-Python just
> hangs on startup.
>
> Is this bug specific to ActiveState Python, or is it also present in
> the vanilla C-Python build for Windows?
>
>
It's present in the "vanilla" build. I assume you're running mintty as I
do.
I just use the cygwin build for fooling around with python, and [WARNING:
hold your nose] the cmd shell when I need Windows Python.
You can also use the (old-fashioned?) cygwin.bat do start cygwin which
doesn't give you as nice a terminal but does allow you to run bash and
"/c/Python27/Python" interactively.

Another option, which I just discovered, is bash under msys. It's been a
while since I've used it so I can't remember the pro and con but you can
run an interactive Windows python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interactrive Python under Cygwin in Win7

2013-04-08 Thread Grant Edwards
On 2013-04-08, David Robinow  wrote:
> On Mon, Apr 8, 2013 at 11:20 AM, Grant Edwards wrote:
>
>> I just installed ActiveState 2.7 64-bit on a Windows 7 machine running
>> a current version of Cygwin.  While python programs (both GUI and
>> text-mode) run fine, I'm unable to use Python interactively from
>> either the Cygwin terminal or in an ssh session.  I tried adding the
>> "-u" option, but that makes no difference.  Interactive C-Python just
>> hangs on startup.
>>
>> Is this bug specific to ActiveState Python, or is it also present in
>> the vanilla C-Python build for Windows?
>
> It's present in the "vanilla" build. I assume you're running mintty
> as I do.

That's what I usually run when I'm not ssh'ed in.

> I just use the cygwin build for fooling around with python, and
> [WARNING: hold your nose] the cmd shell when I need Windows Python.

Yea, that's what I finally fell back on.  At least it has command line
recall/editing, so it could be worse.  I do almost all of my
development on Linux and rarely do anything interactive under
Windows, but once in a while it would be handy.

> You can also use the (old-fashioned?) cygwin.bat do start cygwin
> which doesn't give you as nice a terminal but does allow you to run
> bash and "/c/Python27/Python" interactively.
>
> Another option, which I just discovered, is bash under msys. It's been a
> while since I've used it so I can't remember the pro and con but you can
> run an interactive Windows python.

Oh yea, I had forgotten about msys.

-- 
Grant Edwards   grant.b.edwardsYow! I'm having an
  at   emotional outburst!!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to subclass a family

2013-04-08 Thread Arnaud Delobelle
On 8 April 2013 10:44, Antoon Pardon  wrote:
> Here is the idea. I have a number of classes with the same interface.
> Something like the following:
>
> class Foo1:
> def bar(self, ...):
> work
> def boo(self, ...):
> do something
> self.bar(...)
>
> What I want is the equivallent of:
>
> class Far1(Foo1):
> def boo(self, ...)
> do something different
> if whatever:
> self.bar(...)
> else:
> Foo1.boo(self, ...)
>
> Now of course I could subclass every class from the original family
> from Foo1 to Foon but that would mean a lot of duplicated code. Is
> there a way to reduce the use of duplicated code in such circumstances?
>

(Python 3)
--
class Foo1:
def bar(self):
print('Foo1.bar')
def boo(self, whatever):
print('Foo1.boo', whatever)
self.bar()

# class Foo2: ...(I'll let you define this one)

class DifferentBoo:
def boo(self, whatever):
print('DifferentBoo.boo', whatever)
if whatever:
self.bar()
else:
super().boo(whatever)

class Far1(DifferentBoo, Foo1): pass
# class Far2(DifferentBoo, Foo2): pass

--
>>> foo = Foo1()
>>> foo.bar()
Foo1.bar
>>> foo.boo(1)
Foo1.boo 1
Foo1.bar
>>> far = Far1()
>>> far.bar()
Foo1.bar
>>> far.boo(0)
DifferentBoo.boo 0
Foo1.boo 0
Foo1.bar
>>> far.boo(1)
DifferentBoo.boo 1
Foo1.bar

HTH,

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-08 Thread Grant Edwards
On 2013-04-08, Walter Hurry  wrote:

> Personally I have always used 4 spaces. I use it in SQL, shell
> scripts and Python. It makes code simple to read, and unambiguous.

Same here -- mostly because that's what the emacs "Python-mode" does
by default, and it seems to be commonly accepted "right way".  All
things being equal, I'd pobably pick 2 or 3, but 4 is fine.

> The fact of Python enforcing it (or all tabs; a poor second choice)
> is *a good thing*, easy and natural IMHO. No need for "end if" or
> "end loop" or "fi". One wonders whether OP is simply trolling.  

If he was trolling, he certainly deserves a prize.

-- 
Grant Edwards   grant.b.edwardsYow! Here we are in America
  at   ... when do we collect
  gmail.comunemployment?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-08 Thread Walter Hurry
On Mon, 08 Apr 2013 19:48:58 +, Grant Edwards wrote:

> On 2013-04-08, Nobody  wrote:
>> On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:
>>
>>> Am I the only one here who has used a typewriter?
>>> 
>>> Tab stops were set manually, to a physical distance into the page,
>>> using a mechanical stop. This long predates the "rule" that tab stops
>>> are every 8 characters.
>>
>> And your point is?
> 
> The point is that there is little historical precedent for assuming that
> tab stops are evenly and equally spaced across the page (let alone one
> particular fixed, even spacing) -- and people who mix spaces and tabs
> based on such false assumptions are responsible for their own bleeding
> foot.
> 
>> Typewriters don't have a tab "character". The information regarding tab
>> stops is conveyed out-of-band from the typist to the typewriter, and
>> doesn't need to persist beyond the time taken to type the document.
> 
> And the same is true when you don't mix tabs and spaces when indenting
> Python code.  If you use tabs alone when indenting Python code it
> doesn't matter where the tabs are set -- they don't even have to be
> equally spaced -- the meaning of the source file is unambiguous.
> 
> If you mix tabs and spaces, then you've got to provide out-of-band
> information regarding the position of the tab stops in order to make the
> source code unambiguous.  Since there's no mechanism to provide that OOB
> tab stop info, mixed tabs and spaces isn't accepted.

Personally I have always used 4 spaces. I use it in SQL, shell scripts 
and Python. It makes code simple to read, and unambiguous.

The fact of Python enforcing it (or all tabs; a poor second choice) is *a 
good thing*, easy and natural IMHO. No need for "end if" or "end loop" or 
"fi". One wonders whether OP is simply trolling.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-08 Thread Chris Angelico
On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards  wrote:
> On 2013-04-08, Walter Hurry  wrote:
>> The fact of Python enforcing it (or all tabs; a poor second choice)
>> is *a good thing*, easy and natural IMHO. No need for "end if" or
>> "end loop" or "fi". One wonders whether OP is simply trolling.
>
> If he was trolling, he certainly deserves a prize.

I don't think he was trolling. It was a classic-model rant: "I
upgraded my dependency to a newer version and all my stuff broke".
Commonly provokes anger, largely because many such upgrades do NOT
break stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now,
I doubt anything would break, and my code would be able to use the new
iterator syntax in c++11 - pity 4.7 isn't packaged for Debian
Squeeze). The OP upgraded across an openly-non-backward-compatible
boundary, and got angry over one particular aspect of backward compat
that wasn't there.

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


Re: I hate you all

2013-04-08 Thread Walter Hurry
On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote:

> On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards 
> wrote:
>> On 2013-04-08, Walter Hurry  wrote:
>>> The fact of Python enforcing it (or all tabs; a poor second choice)
>>> is *a good thing*, easy and natural IMHO. No need for "end if" or "end
>>> loop" or "fi". One wonders whether OP is simply trolling.
>>
>> If he was trolling, he certainly deserves a prize.
> 
> I don't think he was trolling. It was a classic-model rant: "I upgraded
> my dependency to a newer version and all my stuff broke".
> Commonly provokes anger, largely because many such upgrades do NOT break
> stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now,
> I doubt anything would break, and my code would be able to use the new
> iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze).
> The OP upgraded across an openly-non-backward-compatible boundary, and
> got angry over one particular aspect of backward compat that wasn't
> there.

But wouldn't it have been easier simply to do do a quick sed or whatever 
rather than to spend hours here arguing?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I hate you all

2013-04-08 Thread Chris Angelico
On Tue, Apr 9, 2013 at 8:51 AM, Walter Hurry  wrote:
> On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote:
>
>> On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards 
>> wrote:
>>> On 2013-04-08, Walter Hurry  wrote:
 The fact of Python enforcing it (or all tabs; a poor second choice)
 is *a good thing*, easy and natural IMHO. No need for "end if" or "end
 loop" or "fi". One wonders whether OP is simply trolling.
>>>
>>> If he was trolling, he certainly deserves a prize.
>>
>> I don't think he was trolling. It was a classic-model rant: "I upgraded
>> my dependency to a newer version and all my stuff broke".
>> Commonly provokes anger, largely because many such upgrades do NOT break
>> stuff (eg if I were to switch from gcc 4.5 to gcc 4.7 right now,
>> I doubt anything would break, and my code would be able to use the new
>> iterator syntax in c++11 - pity 4.7 isn't packaged for Debian Squeeze).
>> The OP upgraded across an openly-non-backward-compatible boundary, and
>> got angry over one particular aspect of backward compat that wasn't
>> there.
>
> But wouldn't it have been easier simply to do do a quick sed or whatever
> rather than to spend hours here arguing?

Probably. I don't profess to understand the OP's brain *that* much!

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


Re: im.py: a python communications tool

2013-04-08 Thread Mark Janssen
On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano
 wrote:
> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote:
>
>> Actually, my current licence can be found here:
>> https://github.com/jhunter-d/im.py/blob/master/LICENCE.  Whaddaya think
>> about this, Useneters?
>
>
> I think you're looking for a world of pain, when somebody uses your
> software, it breaks something, and they sue you. Your licence currently
> means that you are responsible for the performance of your software.

Steven, they can't sue you for something they didn't pay for, because
they never entered into an agreement, not did you.

Mark Janssen
Tacoma, Washington.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to subclass a family

2013-04-08 Thread Devin Jeanpierre
On Mon, Apr 8, 2013 at 5:44 AM, Antoon Pardon
 wrote:
> Now of course I could subclass every class from the original family
> from Foo1 to Foon but that would mean a lot of duplicated code. Is
> there a way to reduce the use of duplicated code in such circumstances?

As a rule, if there's duplicate code you can stuff it in a function.

def create_subclass(Foo):
class Far(Foo):
def boo(self, ...)
do something different
if whatever:
self.bar(...)
else:
super(Far, self).boo(self, ...)
return Far

Far1 = create_subclass(Foo1)
Far2 = create_subclass(Foo2)
...

Of course, this doesn't preserve the names of the subclasses properly.
To do that you can add a parameter, for the name, although this is a
little repetitive. Alternatively you can subclass yet again, as in:

class Far1(create_subclass(Foo1)): pass

Or you can even change the approach to a class decorator that adds a method:

def add_method(cls):
def boo(self, ...):
do something different
if whatever:
self.bar(...)
else:
super(cls, self).boo(...)

@add_method
class Far1(Foo1): pass

@add_method
class Far2(Foo2): pass

As a wise man once said, TIMTOWTDI. :(

-- Devin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is "_io.py" missing from 2.7.4 ?

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 06:12:02 -0700, dbv wrote:

> In 2.7.4, io.py shows:
> 
> import _io
> import abc
> 
> from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError,
> UnsupportedOperation,
>  open, FileIO, BytesIO, StringIO, BufferedReader,
>  BufferedWriter, BufferedRWPair, BufferedRandom,
>  IncrementalNewlineDecoder, TextIOWrapper)
> 
> but, cannot find _io.py, though there is the old _pyio.py in the
> //Python27//Lib folder.


If "from _io import ..." succeeds with no error, then it is physically 
impossible for it to be missing.

To find where the _io module lives, at the interactive interpreter run 
this:

import _io
_io.__file__


Under Linux, you should get something like this:

'/usr/local/lib/python2.7/lib-dynload/_io.so'


and the equivalent under Windows.

Note that in Python 3.3, the _io module is now built-in into the 
compiler, so _io.__file__ no longer exists.


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


Re: Splitting of string at an interval

2013-04-08 Thread Roy Smith
In article ,
 Arnaud Delobelle  wrote:

> On 8 April 2013 17:20, Chris Angelico  wrote:
> > On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith  wrote:
> >> I can't help point out, however, that if your initial implementation is to 
> >> have your code return a constant, it's pretty likely to be an optimum 
> >> solution in both time and space :-)
> >
> > Likely, but not certain.
> >
> > # 1
> > def fifty_stars():
> >   return "**"
> >
> > # 2
> > fifty_stars=lambda "*"*50
> 
> There's a whole competition about writing the smallest program which
> outputs the song "99 bottles of beer":
> 
> http://codegolf.com/99-bottles-of-beer

I see the top 10 entries are all written in Perl.  I suppose this says 
something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting of string at an interval

2013-04-08 Thread Tim Chase
On 2013-04-08 21:09, Roy Smith wrote:
>> http://codegolf.com/99-bottles-of-beer
> 
> I see the top 10 entries are all written in Perl.  I suppose this
> says something.

About the capabilities of Perl for writing such code, or about the
drinking habits of Perl programmers? :-)

Or-about-how-perl-drives-you-to-drink'ly yours,

-tkc


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


Re: im.py: a python communications tool

2013-04-08 Thread Dave Angel

On 04/08/2013 07:16 PM, Mark Janssen wrote:

On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano
 wrote:

On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote:


Actually, my current licence can be found here:
https://github.com/jhunter-d/im.py/blob/master/LICENCE.  Whaddaya think
about this, Useneters?



I think you're looking for a world of pain, when somebody uses your
software, it breaks something, and they sue you. Your licence currently
means that you are responsible for the performance of your software.


Steven, they can't sue you for something they didn't pay for, because
they never entered into an agreement, not did you.



That's a common misconception.  No prior agreement is necessary to 
institute a lawsuit, at least in the United States.  I'm not a lawyer, 
but I've been advised that the best you can hope for is to minimize the 
likelihood that a lawsuit will be successful, not to somehow guarantee 
that a lawsuit cannot be filed and prosecuted.


Besides, an open-ended license might be acted on anywhere in the world, 
and who knows what some other jurisdictions might permit/require.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting of string at an interval

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote:

>> There's a whole competition about writing the smallest program which
>> outputs the song "99 bottles of beer":
>> 
>> http://codegolf.com/99-bottles-of-beer
> 
> I see the top 10 entries are all written in Perl.  I suppose this says
> something.


When I write my own programming language, it will include a one-character 
built-in command to perform 99 bottles of beer, just so my language will 
always be the winner.

In fact, I may make it a bare . so that not only will it be the shortest 
program, but also the smallest program in terms of number of non-white 
pixels.



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


Re: I hate you all

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote:

> On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:
> 
>> Am I the only one here who has used a typewriter?
>> 
>> Tab stops were set manually, to a physical distance into the page,
>> using a mechanical stop. This long predates the "rule" that tab stops
>> are every 8 characters.
> 
> And your point is?
> 
> Typewriters don't have a tab "character". The information regarding tab
> stops is conveyed out-of-band from the typist to the typewriter, and
> doesn't need to persist beyond the time taken to type the document.

Both text editors and typewriters encode information about tab settings 
out of band. Editors encode that information in some combination of 
program configuration, command-line switches, environment variables, and 
embedded mode lines in the document itself. Typewriters encode that 
information in the typists' memory, or failing that, in the actual 
physical space left on the page. That's a difference that makes no 
difference.

My point is that there were well-established semantics for what a tab 
should do, and the "8 character tab" is not that. Pressing the tab key on 
a keyboard while entering text ought to instruct the editor to advance to 
a specified tab stop capable of being set anywhere on the page. Word 
processors use that model: the word processor stores the positions of the 
tab stops out of band, usually in the "paragraph formatting" or "style 
sheet", but in principle they could keep the position of the tab stops 
global to the document or even global to the application.

Good text editors also support this model. Some versions of Vim, for 
example, include a feature called "variable tabstops". Emacs includes a 
variable called tab-stop-list which can set variable tab stops[1]. Even 
the Linux command "less" supports variable width tabs, with the -x option.

In case you think this is only for Unix editors, the Windows "Boxer Text 
Editor" also supports variable tab stops.

There may, or may not be, good reasons for an eight character default 
setting for tab stops. But eight characters is not, and never has been, 
the One True Way of setting tab stops.




[1] Although what happens when you press the tab key in Emacs is so 
complicated that only three people in the world have ever understood it 
fully. The first is Richard Stallman, then second is dead, and the third 
has gone mad.


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


Re: Splitting of string at an interval

2013-04-08 Thread Andrew Berg
On 2013.04.08 21:38, Steven D'Aprano wrote:
> In fact, I may make it a bare . so that not only will it be the shortest 
> program, but also the smallest program in terms of number of non-white 
> pixels.
Until someone implements it in Whitespace.
-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to subclass a family

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 11:44:51 +0200, Antoon Pardon wrote:

> Here is the idea. I have a number of classes with the same interface.
> Something like the following:
> 
> class Foo1:
> def bar(self, ...):
> work
> def boo(self, ...):
> do something
> self.bar(...)
> 
> What I want is the equivallent of:
> 
> class Far1(Foo1):
> def boo(self, ...)
> do something different
> if whatever:
> self.bar(...)
> else:
> Foo1.boo(self, ...)


What do you mean, "the equivalent of"? What's wrong with the code as 
given?



> Now of course I could subclass every class from the original family from
> Foo1 to Foon but that would mean a lot of duplicated code. Is there a
> way to reduce the use of duplicated code in such circumstances?


I don't understand your question. The reason for using inheritance is to 
reduce the amount of duplicated code. If you're ending up with more code, 
you're doing something wrong. You're probably badly designing your 
methods, or your classes, or both. If you give a less contrived example, 
perhaps we can help.



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


Re: im.py: a python communications tool

2013-04-08 Thread Mark Janssen
On Mon, Apr 8, 2013 at 7:05 PM, Dave Angel  wrote:
> On 04/08/2013 07:16 PM, Mark Janssen wrote:
>>
>> On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano
>>  wrote:
>>>
>>> On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote:
>>>
 Actually, my current licence can be found here:
 https://github.com/jhunter-d/im.py/blob/master/LICENCE.  Whaddaya think
 about this, Useneters?
>>>
>>>
>>>
>>> I think you're looking for a world of pain, when somebody uses your
>>> software, it breaks something, and they sue you. Your licence currently
>>> means that you are responsible for the performance of your software.
>>
>>
>> Steven, they can't sue you for something they didn't pay for, because
>> they never entered into an agreement, not did you.
>>
>
> That's a common misconception.  No prior agreement is necessary to institute
> a lawsuit, at least in the United States.  I'm not a lawyer, but I've been
> advised that the best you can hope for is to minimize the likelihood that a
> lawsuit will be successful, not to somehow guarantee that a lawsuit cannot
> be filed and prosecuted.

Clearly anyone can file a lawsuit, I could file one against you for
offending me, for example.  The issue I was poorly raising is whether
such a case would have merit.  In the case of free (libre) open source
software, such a case would have no merit, because such software never
promises anyone *anything*.  But someone would have to make the case
and "train" the court.  The court simply has not become appraised of
what free, libre, open source software is.  Really, one shouldn't be
so afraid of such things and intimidated of our own system of law --
this is why the republic has degraded to lawyers, not representatives
of the People.  If a hospital takes your open source code and someone
dies, the hospital must be held responsible, because the open source
developer is not posing as an expert of anything, nor has she made it
for some explicit purpose for you like in a commercial agreement.

Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread bhk755
On Monday, April 8, 2013 3:37:38 PM UTC+5:30, bhk...@gmail.com wrote:
> I am trying to create 2D arrays without using advanced features like numpy, 
> for this I have created 2 separate modules arrays.py and array2D.py. Here's 
> the code for that:
> 
> 
> 
> arrays.py module:
> 
> ==
> 
> import ctypes
> 
> 
> 
> class Array:
> 
> 
> 
> #Creates an array with size elements.
> 
> def __init__( self, size ):
> 
> assert size > 0, "Array size must be > 0"
> 
>   self._size = size
> 
>   print "sixe is %s" %self._size
> 
>   
> 
>  # Create the array structure using the ctypes module.
> 
>   PyArrayType = ctypes.c_int * size
> 
>   self._elements = PyArrayType()
> 
>   print "type is e", type(self._elements)
> 
>   #self._elements = ctypes.c_int * size
> 
>   
> 
>   print "Elements are self.element %s" % self._elements
> 
> # Initialize each element.
> 
>   #for i in range(self._size):
> 
>   #   self.clear( i )
> 
>   
> 
>   
> 
> # Returns the size of the array.
> 
> def __len__( self ):
> 
> return self._size
> 
> 
> 
> # Gets the contents of the index element.
> 
> def __getitem__( self, index ):
> 
> assert index >= 0 and index < len(self), "Array subscript out of 
> range"
> 
>   return self._elements[ index ]
> 
> 
> 
> # Puts the value in the array element at index position.
> 
> def __setitem__( self, index, value ):
> 
> assert index >= 0 and index < len(self), "Array subscript out of 
> range"
> 
>   print "Type is ", type(index)
> 
>   self._elements[ index ] = value
> 
> 
> 
> # Clears the array by setting each element to the given value.
> 
> def clear( self, value ):
> 
> for i in range( len(self) ) :
> 
>   self._elements[i] = value
> 
> 
> 
> # Printing the arrays:
> 
> def __str__(self):
> 
> return self._elements
> 
> 
> 
>   
> 
>   
> 
> array2D.py module
> 
> ==
> 
> 
> 
>   
> 
> import arrays
> 
> 
> 
> class Array2D :
> 
> # Creates a 2-D array of size numRows x numCols.
> 
> def __init__( self, numRows, numCols ):
> 
> # Create a 1-D array to store an array reference for each row.
> 
>   
> 
> self._theRows = arrays.Array( numRows )
> 
>   # Create the 1-D arrays for each row of the 2-D array.
> 
>   print "Num of Cloumns is", numCols
> 
>   
> 
>   for i in range( numRows ) :
> 
>   self._theRows[i] = arrays.Array( numCols )
> 
> 
> 
> # Returns the number of rows in the 2-D array.
> 
> def numRows( self ):
> 
> return len( self._theRows )
> 
> 
> 
> # Returns the number of columns in the 2-D array.
> 
> def numCols( self ):
> 
> return len( self._theRows[0] )
> 
> 
> 
> # Clears the array by setting every element to the given value.
> 
> def clear( self, value ):
> 
> for row in range( self.numRows() ):
> 
> row.clear( value )
> 
> 
> 
> # Gets the contents of the element at position [i, j]
> 
> def __getitem__( self, ndxTuple ):
> 
> assert len(ndxTuple) == 2, "Invalid number of array subscripts."
> 
> row = ndxTuple[0]
> 
> col = ndxTuple[1]
> 
> assert row >= 0 and row < self.numRows() \
> 
> and col >= 0 and col < self.numCols(), \
> 
> "Array subscript out of range."
> 
> the1dArray = self._theRows[row]
> 
> return the1dArray[col]
> 
> 
> 
> # Sets the contents of the element at position [i,j] to value.
> 
> def __setitem__( self, ndxTuple, value ):
> 
> #assert len(ndxTuple) == 3, "Invalid number of array subscripts."
> 
> row = ndxTuple[0]
> 
> col = ndxTuple[1]
> 
> assert row >= 0 and row < self.numRows() \
> 
> and col >= 0 and col < self.numCols(), \
> 
> "Array subscript out of range."
> 
> the1dArray = self._theRows[row]
> 
> the1dArray[col] = value
> 
>   
> 
>   
> 
> arr = Array2D(2,4)
> 
> 
> 
> print "arr is %s" %arr
> 
> 
> 
> 
> 
> Traceback is :
> 
> 
> 
> sixe is 2
> 
> type is e 
> 
> Elements are self.element 
> 
> Cols in 4
> 
> Num of Cloumns is 4
> 
> !! i is 0
> 
> sixe is 4
> 
> type is e 
> 
> Elements are self.element 
> 
> Type is  
> 
> Traceback (most recent call last):
> 
>   File "C:\Python27\Lib\array2D.py", line 53, in 
> 
> arr = Array2D(2,4)
> 
>   File "C:\Python27\Lib\array2D.py", line 16, in __init__
> 
> self._theRows[i] = arrays.Array( numCols )
> 
>   File "C:\Python27\Lib\arrays.py", line 36, in __setitem__
> 
> self._elements[ index ] = value
> 
> AttributeError: Array instance has no attribute '__trunc__'


Hi Dylan,

Thank you for the alternative solution. I will look into that. 
-- 
http://mail.python.org/mailman/listinfo/pyt

Re: I hate you all

2013-04-08 Thread rusi
On Apr 9, 7:51 am, Steven D'Aprano  wrote:
> On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote:
> > On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:
>
> >> Am I the only one here who has used a typewriter?
>
> >> Tab stops were set manually, to a physical distance into the page,
> >> using a mechanical stop. This long predates the "rule" that tab stops
> >> are every 8 characters.
>
> > And your point is?
>
> > Typewriters don't have a tab "character". The information regarding tab
> > stops is conveyed out-of-band from the typist to the typewriter, and
> > doesn't need to persist beyond the time taken to type the document.
>
> Both text editors and typewriters encode information about tab settings
> out of band. Editors encode that information in some combination of
> program configuration, command-line switches, environment variables, and
> embedded mode lines in the document itself. Typewriters encode that
> information in the typists' memory, or failing that, in the actual
> physical space left on the page. That's a difference that makes no
> difference.
>
> My point is that there were well-established semantics for what a tab
> should do, and the "8 character tab" is not that. Pressing the tab key on
> a keyboard while entering text ought to instruct the editor to advance to
> a specified tab stop capable of being set anywhere on the page. Word
> processors use that model: the word processor stores the positions of the
> tab stops out of band, usually in the "paragraph formatting" or "style
> sheet", but in principle they could keep the position of the tab stops
> global to the document or even global to the application.

Dunno what you mean by 'out-of-band'
If I set tabstops for a para to say 4-13-25-36 in a wordprocessor,
save the file and look inside, I will find the tuple (4,13,25,36) in
some encoded form.
For a typewritten page, if the margin seems to be at 11th col, the
reader cannot know from the page alone whether the typist
1. set the tab at 11
2. set the tab at 8 and pressed TAB followed by 3 SPC
3. Started with 2 and switched to 1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting of string at an interval

2013-04-08 Thread Chris Angelico
On Tue, Apr 9, 2013 at 12:38 PM, Steven D'Aprano
 wrote:
> On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote:
>
>>> There's a whole competition about writing the smallest program which
>>> outputs the song "99 bottles of beer":
>>>
>>> http://codegolf.com/99-bottles-of-beer
>>
>> I see the top 10 entries are all written in Perl.  I suppose this says
>> something.
>
>
> When I write my own programming language, it will include a one-character
> built-in command to perform 99 bottles of beer, just so my language will
> always be the winner.
>
> In fact, I may make it a bare . so that not only will it be the shortest
> program, but also the smallest program in terms of number of non-white
> pixels.

Don't be too specific, Steven. Also include a one-character built-in
to emit the program's own source, and another to echo "hello, world"
to standard output. And one to increment the accumulator, just for
completeness.

Who knows, it might already exist!

http://esolangs.org/wiki/Cliff_L._Biffle

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


Re: I hate you all

2013-04-08 Thread rusi
On Apr 9, 9:06 am, rusi  wrote:
> Dunno what you mean by 'out-of-band'
> If I set tabstops for a para to say 4-13-25-36 in a wordprocessor,
> save the file and look inside, I will find the tuple (4,13,25,36) in
> some encoded form.

To make this conform to current practices, I should use some length-
unit not characters which I had in mind.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 21:01:04 -0700, bhk755 wrote:


[snip over 260 lines of unnecessary quoted text]
> Hi Dylan,
> 
> Thank you for the alternative solution. I will look into that.


Please trim your replies. There's absolutely no reason to expect people 
to scroll through almost FOUR PAGES of quoted text just to get to a two 
line response.

Thank you.


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


Re: I hate you all

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 21:06:42 -0700, rusi wrote:

> On Apr 9, 7:51 am, Steven D'Aprano  +comp.lang.pyt...@pearwood.info> wrote:
>> On Mon, 08 Apr 2013 19:43:51 +0100, Nobody wrote:
>> > On Sun, 07 Apr 2013 01:30:45 +, Steven D'Aprano wrote:
>>
>> >> Am I the only one here who has used a typewriter?
>>
>> >> Tab stops were set manually, to a physical distance into the page,
>> >> using a mechanical stop. This long predates the "rule" that tab
>> >> stops are every 8 characters.
>>
>> > And your point is?
>>
>> > Typewriters don't have a tab "character". The information regarding
>> > tab stops is conveyed out-of-band from the typist to the typewriter,
>> > and doesn't need to persist beyond the time taken to type the
>> > document.
>>
>> Both text editors and typewriters encode information about tab settings
>> out of band. Editors encode that information in some combination of
>> program configuration, command-line switches, environment variables,
>> and embedded mode lines in the document itself. Typewriters encode that
>> information in the typists' memory, or failing that, in the actual
>> physical space left on the page. That's a difference that makes no
>> difference.
>>
>> My point is that there were well-established semantics for what a tab
>> should do, and the "8 character tab" is not that. Pressing the tab key
>> on a keyboard while entering text ought to instruct the editor to
>> advance to a specified tab stop capable of being set anywhere on the
>> page. Word processors use that model: the word processor stores the
>> positions of the tab stops out of band, usually in the "paragraph
>> formatting" or "style sheet", but in principle they could keep the
>> position of the tab stops global to the document or even global to the
>> application.
> 
> Dunno what you mean by 'out-of-band'

I mean that the information about the tab stops are not inherent to the 
tab itself.


> If I set tabstops for a para to say 4-13-25-36 in a wordprocessor, save
> the file and look inside, I will find the tuple (4,13,25,36) in some
> encoded form.

There's nothing about the *tab character itself* that says "jump to 
column 25". That information is metadata, stored external to the tab. 
That doesn't necessarily mean external to the file. A word-processing 
file carries a lot of metadata about the document.

A plain text file is a better example. If I type up a document in (say) 
OpenOffice and use tabs to align a table, I might manually set the tabs 
to 4cm, 9cm, 18cm. When I hit tab, the cursor will jump to (say) 18cm, 
but if I save the document as plain text, that information is not stored 
anywhere in the document. It may be encoded in the OpenOffice config, 
e.g. in the "Normal" stylesheet.

The same applies for documents created in a text editor, say Vim or 
Emacs. They may store the metadata about tab settings as mode lines in 
the document, or in an environment variable, or in a config file, or 
perhaps nowhere at all. Just like a typewriter.


> For a typewritten page, if the margin seems to be at 11th col, the
> reader cannot know from the page alone whether the typist 1. set the tab
> at 11
> 2. set the tab at 8 and pressed TAB followed by 3 SPC 3. Started with 2
> and switched to 1

Very true. Manual typewriters are not identical to text editors. 
Typewriters can do both more *and* less than text editors. E.g. you can 
compose extra symbols by backspacing and overtyping, but you cannot 
usually distinguish between space-tab and space-space-tab.

But from the perspective of "duplicate what you see on the page", the 
difference between space-tab and space-space-tab does not matter. What 
matters is where you end up, not how you get there.



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


classes and sub classes?

2013-04-08 Thread Morten Guldager
'Aloha Friends!

I'm about to write an API against a huge propitiatory Oracle based network
inventory database. The database have many different concepts stored in
it's tables, can one concept can span over multiple tables.

I would like to write a class for accessing each concept, but only have a
single database connection throughout the whole program.

I imagine some code along these lines, but cant figure out how to declare
the classes that will make it work:

# create a connection to the database and perform come basic login and
initialization
nib = NwInvDb("scott/tiger@ora")
# find a device by ip
interesting_device = nib.Device.lookup_by_ip("192.168.1.1")

In this example I access the concept Device.

Should I make the Device class inherit from NwInvDb? Or should I keep them
separate? Later on I think I will even have to make some sort of
sub-concepts, but lets postpone that game until I really have really seen
the need!


-- 
/Morten %-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Dave Angel

On 04/08/2013 11:37 PM, Mark Janssen wrote:

On Mon, Apr 8, 2013 at 7:05 PM, Dave Angel  wrote:

On 04/08/2013 07:16 PM, Mark Janssen wrote:


On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano
 wrote:


On Sun, 07 Apr 2013 14:47:11 -0700, jhunter.dunefsky wrote:


Actually, my current licence can be found here:
https://github.com/jhunter-d/im.py/blob/master/LICENCE.  Whaddaya think
about this, Useneters?




I think you're looking for a world of pain, when somebody uses your
software, it breaks something, and they sue you. Your licence currently
means that you are responsible for the performance of your software.



Steven, they can't sue you for something they didn't pay for, because
they never entered into an agreement, not did you.



That's a common misconception.  No prior agreement is necessary to institute
a lawsuit, at least in the United States.  I'm not a lawyer, but I've been
advised that the best you can hope for is to minimize the likelihood that a
lawsuit will be successful, not to somehow guarantee that a lawsuit cannot
be filed and prosecuted.


Clearly anyone can file a lawsuit, I could file one against you for
offending me, for example.  The issue I was poorly raising is whether
such a case would have merit.  In the case of free (libre) open source
software, such a case would have no merit, because such software never
promises anyone *anything*.


I'm not a lawyer, and I suspect you're not either.  If a burglar climbs 
up my trellis to try to attain a second floor window, and comes crashing 
to the ground, he may very well successfully sue me for not having a 
warning sign.  Especially if "I" am a company.  And especially if I have 
an "attractive nuisance" around.  There are lots of implied agreements 
that have been successfully used by the opposing lawyers.


  But someone would have to make the case

and "train" the court.  The court simply has not become appraised of
what free, libre, open source software is.


Now you're assuming that there is such a definition, and that the court 
could be convinced to follow your interpretation.  I claim that no 
amateur should try to word his own agreement.  Either get an expert to 
help, or refer to an agreement that was prepared by such experts.  Don't 
make the assumption that because something is free, it's somehow immune 
from liability.


I expect it's safer to have no agreement at all, than to have one that 
gives away privileges without explicitly declaring or disclaiming any 
responsibilities.



 Really, one shouldn't be
so afraid of such things and intimidated of our own system of law --
this is why the republic has degraded to lawyers, not representatives
of the People.  If a hospital takes your open source code and someone
dies, the hospital must be


No, *should* *be*


held responsible, because the open source
developer is not posing as an expert of anything, nor has she made it
for some explicit purpose for you like in a commercial agreement.

Mark





--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread bhk755
Hi Dylan, 

Thank you for the alternative solution. I will look into that. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can anyone please help me in resolving the error => AttributeError: Array instance has no attribute '__trunc__'

2013-04-08 Thread bhk755
Thanks Steven for pointing that out. This is my first topic in Google Groups. 
So, I did not notice that the previous contents will also be taken in the new 
post. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Mark Janssen
> I'm not a lawyer, and I suspect you're not either.  If a burglar climbs up
> my trellis to try to attain a second floor window, and comes crashing to the
> ground, he may very well successfully sue me for not having a warning sign.

No, I understand these cases are common lore, but it's this bullshit
which is ruining everything that was balanced by the Constitution.  By
propagating such ideas, it continues the idea that we're all victims
to our own system of law, but we are the tacit *creators* of it by our
own negligence, and frankly, pessimism.

This is a system of, by and for the People -- those are the words of
the Constitution of the United States which is the highest law of the
land.  People need to fight this "enabler" creep, that allows it to
continually be co-opted by fear-story, like the one that was being
propagated earlier.  We're not victims here.  The story of a burglar
suing a homeowner is either urban myth and a hoax, or a gross default
somewhere in the judicial system.  It should not be considered case
history or "de facto" law and left at that.

>>   If a hospital takes your open source code and someone
>> dies, the hospital must be
>
> No, *should* *be*
>
>> held responsible, because the open source
>> developer is not posing as an expert of anything, nor has she made it
>> for some explicit purpose for you like in a commercial agreement.

(re: must vs. should) Legally, you are right, but I was speaking from
the point of view of a judge, rather than a lawyer.  Like the sheriff
says:  "I make the law around here!"  lol.

Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting of string at an interval

2013-04-08 Thread Dave Angel

On 04/08/2013 10:38 PM, Steven D'Aprano wrote:

On Mon, 08 Apr 2013 21:09:08 -0400, Roy Smith wrote:


There's a whole competition about writing the smallest program which
outputs the song "99 bottles of beer":

http://codegolf.com/99-bottles-of-beer


I see the top 10 entries are all written in Perl.  I suppose this says
something.



When I write my own programming language, it will include a one-character
built-in command to perform 99 bottles of beer, just so my language will
always be the winner.

In fact, I may make it a bare . so that not only will it be the shortest
program, but also the smallest program in terms of number of non-white
pixels.



But do we need a shebang line?  If so, then make sure the interpreter 
name is also one character long.


I expect there's a character with fewer pixels than the period, but the 
utf-8 version of it would be more than one byte long.  But you could 
define your language with a default encoding that happens to map said 
character to a single byte.


The Wang word processor (proprietary hardware and OS) used a single 
pixel for \x20, and the no pixels for the \xff.  This way spaces were 
"visible" with a faint dot, more or less in the middle of the cell 
block.  It defined other symbols for other control characters like tab 
and newline.  I'm still looking for a similar feature for emacs (on 
Ubuntu), but so far I've been disappointed by the results.


Libreoffice has a similar feature, enabled by 
View->NonPrintingCharacters, but the dotted space is way too bold, 
basically a period that's higher in its cell.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Demian Brecht
We're /definitely/ on topic for this list.

Just saying.

On Mon, Apr 8, 2013 at 11:20 PM, Mark Janssen  wrote:
>> I'm not a lawyer, and I suspect you're not either.  If a burglar climbs up
>> my trellis to try to attain a second floor window, and comes crashing to the
>> ground, he may very well successfully sue me for not having a warning sign.
>
> No, I understand these cases are common lore, but it's this bullshit
> which is ruining everything that was balanced by the Constitution.  By
> propagating such ideas, it continues the idea that we're all victims
> to our own system of law, but we are the tacit *creators* of it by our
> own negligence, and frankly, pessimism.
>
> This is a system of, by and for the People -- those are the words of
> the Constitution of the United States which is the highest law of the
> land.  People need to fight this "enabler" creep, that allows it to
> continually be co-opted by fear-story, like the one that was being
> propagated earlier.  We're not victims here.  The story of a burglar
> suing a homeowner is either urban myth and a hoax, or a gross default
> somewhere in the judicial system.  It should not be considered case
> history or "de facto" law and left at that.
>
>>>   If a hospital takes your open source code and someone
>>> dies, the hospital must be
>>
>> No, *should* *be*
>>
>>> held responsible, because the open source
>>> developer is not posing as an expert of anything, nor has she made it
>>> for some explicit purpose for you like in a commercial agreement.
>
> (re: must vs. should) Legally, you are right, but I was speaking from
> the point of view of a judge, rather than a lawyer.  Like the sheriff
> says:  "I make the law around here!"  lol.
>
> Mark
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Demian Brecht
http://demianbrecht.github.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Dave Angel

On 04/09/2013 02:20 AM, Mark Janssen wrote:

I'm not a lawyer, and I suspect you're not either.  If a burglar climbs up
my trellis to try to attain a second floor window, and comes crashing to the
ground, he may very well successfully sue me for not having a warning sign.


No, I understand these cases are common lore, but it's this bullshit
which is ruining everything that was balanced by the Constitution.  By
propagating such ideas, it continues the idea that we're all victims
to our own system of law, but we are the tacit *creators* of it by our
own negligence, and frankly, pessimism.


I like to be pessimistic when signing the documents that might ruin my 
own future.  In my last job, I told the company lawyers I would not 
accept the NDA as they supplied it, and they claimed I was the first one 
to successfully force a new version.  As HR put it, most people don't 
even read it, they figure it's a requirement to work.




This is a system of, by and for the People -- those are the words of
the Constitution of the United States which is the highest law of the
land.  People need to fight this "enabler" creep, that allows it to
continually be co-opted by fear-story, like the one that was being
propagated earlier.  We're not victims here.  The story of a burglar
suing a homeowner is either urban myth and a hoax, or a gross default
somewhere in the judicial system.  It should not be considered case
history or "de facto" law and left at that.


   If a hospital takes your open source code and someone
dies, the hospital must be


No, *should* *be*


held responsible, because the open source
developer is not posing as an expert of anything, nor has she made it
for some explicit purpose for you like in a commercial agreement.


(re: must vs. should) Legally, you are right, but I was speaking from
the point of view of a judge, rather than a lawyer.  Like the sheriff
says:  "I make the law around here!"  lol.



I can't really argue your points, and once a challenge is made, I'm 
thoroughly in agreement.  But it's much easier to keep things clear from 
the beginning, and I've been assuming our job here was to advise the OP 
on whether his plan for a license agreement is good.   Years ago I 
managed to get our company lawyers to approve the use of "free" software 
for internal use, but getting the custom license agreement past them was 
like pulling teeth.



--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: im.py: a python communications tool

2013-04-08 Thread Steven D'Aprano
On Mon, 08 Apr 2013 23:20:54 -0700, Mark Janssen wrote:

>> I'm not a lawyer, and I suspect you're not either.  If a burglar climbs
>> up my trellis to try to attain a second floor window, and comes
>> crashing to the ground, he may very well successfully sue me for not
>> having a warning sign.
> 
> No, I understand these cases are common lore, but it's this bullshit
> which is ruining everything that was balanced by the Constitution.

Which Constitution is that? The Russian Constitution? Italian? Japanese? 
Brazilian? New Zealand? Serbian? South African?


> By
> propagating such ideas, it continues the idea that we're all victims to
> our own system of law, but we are the tacit *creators* of it by our own
> negligence, and frankly, pessimism.
> 
> This is a system of, by and for the People -- those are the words of the
> Constitution of the United States which is the highest law of the land. 

Speak for yourself. Not everyone here is a Yankie.


> People need to fight this "enabler" creep, that allows it to continually
> be co-opted by fear-story, like the one that was being propagated
> earlier.  We're not victims here.  The story of a burglar suing a
> homeowner is either urban myth and a hoax, 

Maybe, maybe not, but it's irrelevant. We're not talking about somebody 
breaking into your home to steal your DVD, and on the way in, being 
injured by your software. We're talking about somebody using your 
software, *with your explicit permission*, and then having it cause them 
harm by being unfit for the purpose advertised.

If you don't disclaim warranty, and even sometimes if you do, there is an 
implicit warranty that your goods will be fit for their purpose in many 
jurisdictions. In some places that may only apply if money changes hands; 
in other places it will apply regardless.


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