Re: with ignored

2013-04-08 Thread Barrett Lewis

 However, ignored() is actually implemented as a generator function

with the @contextmanager decorator shortcut.  This decorator takes a
 generator function and wraps it up as a class with the necessary
 __enter__ and __exit__ methods.  The __enter__ method in this case
 calls the .next() method of the generator and returns after it yields
 once.


I looked up the source to the decorator
found here:http://hg.python.org/cpython/file/406b47c64480/Lib/contextlib.py for
anyone interested.
It appears that they are using yield so that they can call it again and
force it to throw the stop iteration exception.



 The __exit__ method calls it again -- or it calls the .throw()
 method if an exception was passed in -- and expects the generator to
 exit as a result.


And here to go with what I said above, they want to be able to use the
generators throw ability to capture any exception and throw it to the
generator, but then why do they *need* the generator to not iterate again?
Or in other words, why when they create the context manager via
_GeneratorContextManager on line 33, is there the clause in __exit__ to
have stop iteration happen or else throw a runtime error?

I am thinking this is because it needs the yield to be over so that it can
return the control flow to normal, and that subroutine will be done. But I
am new to the whole subroutine paradigm so I could be misunderstanding
this.

Also, if the value was none, why are they instantiating a new exception
with value = type()? How could there be a type for the exception without
the exception? (From what I understand type is the error type, and value is
the error object).


So from the perspective of the generator it does its context setup (in
 this case, setting up a try block) prior to the yield, and then does
 the cleanup (in this case, selectively catching and suppressing the
 exceptions) after the yield.

This part makes sense logically. And I like the simplicity. Now I just need
to make sure I understand how the yield semantics are allowing this
construct to work.

Thanks for the reply Ian!

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

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


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 musikal.fus...@gmail.com 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 ros...@gmail.com wrote:

 On Mon, Apr 8, 2013 at 4:38 PM, Barrett Lewis musikal.fus...@gmail.com
 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 musikal.fus...@gmail.com 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,  zeta.con...@gmail.com 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 module
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 l.se...@icloud.com wrote:

 then i get this error:

 Traceback (most recent call last):
   File /Users/leonardo/Documents/ex13.py, line 3, in module
 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 tampucciol...@libero.it 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 class 'arrays.c_long_Array_2'
Elements are self.element arrays.c_long_Array_2 object at 0x00AA7F80
Cols in 4
Num of Cloumns is 4
!! i is 0
sixe is 4
type is e class 'arrays.c_long_Array_4'
Elements are self.element arrays.c_long_Array_4 object at 0x00B60210
Type is  type 'int'
Traceback (most recent call last):
  File C:\Python27\Lib\array2D.py, line 53, in module
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 steve
+comp.lang.pyt...@pearwood.info 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 a...@mesha.org ha scritto:

 On Mon, Apr 8, 2013 at 11:01 AM, leonardo selmi l.se...@icloud.com wrote:
 then i get this error:
 
 Traceback (most recent call last):
   File /Users/leonardo/Documents/ex13.py, line 3, in module
 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 jldunn2...@gmail.com 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 da...@davea.name 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 al...@dpt-info.u-strasbg.fr
 wrote:

 loial jldunn2...@gmail.com 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 al...@dpt-info.u-strasbg.fr

wrote:



loial jldunn2...@gmail.com 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, 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 class 'arrays.c_long_Array_2'
 Elements are self.element arrays.c_long_Array_2 object at 0x00AA7F80
 Cols in 4
 Num of Cloumns is 4
 !! i is 0
 sixe is 4
 type is e class 'arrays.c_long_Array_4'
 Elements are self.element arrays.c_long_Array_4 object at 0x00B60210
 Type is  type 'int'
 Traceback (most recent call last):
   File C:\Python27\Lib\array2D.py, line 53, in module
 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 da...@davea.name 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 jldunn2...@gmail.com 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-listhttp://mail.python.org/mailman/listinfo/python-list



 http://docs.python.org/2/**library/subprocess.html#popen-**objectshttp://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-listhttp://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 mailman.263.1365390121.3114.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 On Mon, Apr 8, 2013 at 7:48 AM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info 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 dineshbvad...@hotmail.com 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 mailman.3484.1363662214.2939.python-l...@python.org,
Terry Reedy  tjre...@udel.edu 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@spearc.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 r...@panix.com 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
module '_io' (built-in)

alike to

 import __builtin__
 __builtin__
module '__builtin__' (built-in)

as opposed to

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


and

 import os
 os
module 'os' from 'C:\Python27\lib\os.pyc'


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 r...@panix.com 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 r...@panix.com 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 ros...@gmail.com wrote:
 On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith r...@panix.com 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,  zeta.con...@gmail.com 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 mailman.3484.1363662214.2939.python-l...@python.org,
Terry Reedy  tjre...@udel.edu 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 nob...@nowhere.com 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 invalid@invalid.invalidwrote:

 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 drobi...@gmail.com wrote:
 On Mon, Apr 8, 2013 at 11:20 AM, Grant Edwards invalid@invalid.invalidwrote:

 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 antoon.par...@rece.vub.ac.be 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 walterhu...@lavabit.com 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 nob...@nowhere.com 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 invalid@invalid.invalid wrote:
 On 2013-04-08, Walter Hurry walterhu...@lavabit.com 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 invalid@invalid.invalid
 wrote:
 On 2013-04-08, Walter Hurry walterhu...@lavabit.com 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 walterhu...@lavabit.com wrote:
 On Tue, 09 Apr 2013 08:00:06 +1000, Chris Angelico wrote:

 On Tue, Apr 9, 2013 at 7:29 AM, Grant Edwards invalid@invalid.invalid
 wrote:
 On 2013-04-08, Walter Hurry walterhu...@lavabit.com 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
steve+comp.lang.pyt...@pearwood.info 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
antoon.par...@rece.vub.ac.be 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 mailman.295.1365438635.3114.python-l...@python.org,
 Arnaud Delobelle arno...@gmail.com wrote:

 On 8 April 2013 17:20, Chris Angelico ros...@gmail.com wrote:
  On Tue, Apr 9, 2013 at 1:37 AM, Roy Smith r...@panix.com 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
steve+comp.lang.pyt...@pearwood.info 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 da...@davea.name wrote:
 On 04/08/2013 07:16 PM, Mark Janssen wrote:

 On Sun, Apr 7, 2013 at 3:36 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info 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 class 'arrays.c_long_Array_2'
 
 Elements are self.element arrays.c_long_Array_2 object at 0x00AA7F80
 
 Cols in 4
 
 Num of Cloumns is 4
 
 !! i is 0
 
 sixe is 4
 
 type is e class 'arrays.c_long_Array_4'
 
 Elements are self.element arrays.c_long_Array_4 object at 0x00B60210
 
 Type is  type 'int'
 
 Traceback (most recent call last):
 
   File C:\Python27\Lib\array2D.py, line 53, in module
 
 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/python-list


Re: I hate you all

2013-04-08 Thread rusi
On Apr 9, 7:51 am, Steven D'Aprano steve
+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'
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
steve+comp.lang.pyt...@pearwood.info 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 rustompm...@gmail.com 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 steve
 +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


[issue17659] First weekday

2013-04-08 Thread Izidor Matušov

New submission from Izidor Matušov:

There is no way how to figure out the first weekday: Does a week start with 
Monday or Saturday? (Or any other day?)

According to documentation, module locale doesn't provide this information. 
Module calendar uses European convention (Monday is the first weekday).

Purpose of this issue is to have a way how to return first weekday (Monday, 
Sunday, etc)

Known workarounds:
  * 
http://blogs.gnome.org/patrys/2008/09/29/how-to-determine-the-first-day-of-week/
  * 
https://github.com/projecthamster/hamster/blob/master/src/hamster/lib/stuff.py#L153
  * 
http://stackoverflow.com/questions/4265697/how-to-determine-the-first-day-of-week-in-python

--
components: Library (Lib)
messages: 186280
nosy: IzidorMatusov
priority: normal
severity: normal
status: open
title: First weekday
type: enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17659
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17655] Use writev() function in the io module

2013-04-08 Thread Charles-François Natali

Charles-François Natali added the comment:

I somehow doubt that the gain is worth the trouble, vectored disk I/O is not as 
interesting as vectored read/writes to a NIC.

Actually, a quick search returned this link:
http://www.mail-archive.com/dev@httpd.apache.org/msg23763.html

Running the benchmark written by the Apache guys:
$ rm -f writev.out; sync; sleep 5; ./test
writev: 1s526601.
copy+write: 1s323405.

Doesn't really surprise me.

So I'm -1, since it's unlikely to yield any improvement, and will greatly 
complicate the code.

--
nosy: +neologix

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17655
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17502] unittest.mock: side_effect iterators ignore DEFAULT

2013-04-08 Thread Michael Foord

Michael Foord added the comment:

This was committed without NEWS entry or documentation update.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17502
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17655] Use writev() function in the io module

2013-04-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Agreed with Charles-François, it probably won't make a difference in practice.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17655
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17484] add tests for getpass

2013-04-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Did you forget to add test_getpass.py?

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17484
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17656] Python 2.7.4 breaks ZipFile extraction of zip files with unicode member paths

2013-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Yes, it's my fault. Here is a patch (with test) which fixes this regression in 
2.7. This is 2.7 only issue, in Python 3 arcnames always are unicode. Please 
test on Windows.

--
components: +Library (Lib)
keywords: +patch
priority: normal - high
stage:  - patch review
type: crash - behavior
versions:  -Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file29729/zipfile_extract_unicode.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17656
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16853] add a Selector to the select module

2013-04-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

If this goes inside the select module, it could probably help issue #17552 (add 
socket.sendfile()) a bit.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16853
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16427] Faster hash implementation

2013-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Removed file: http://bugs.python.org/file27950/fast_str_hash.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16427
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16427] Faster hash implementation

2013-04-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Removed file: http://bugs.python.org/file27947/fast_hash_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16427
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17502] unittest.mock: side_effect iterators ignore DEFAULT

2013-04-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4d8e9c5ba651 by Andrew Svetlov in branch '3.3':
Add NEWS entry for #17502: Process DEFAULT values in mock side_effect that 
returns iterator.
http://hg.python.org/cpython/rev/4d8e9c5ba651

New changeset f82fb8813407 by Andrew Svetlov in branch 'default':
Add NEWS entry for #17502: Process DEFAULT values in mock side_effect that 
returns iterator.
http://hg.python.org/cpython/rev/f82fb8813407

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17502
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17502] unittest.mock: side_effect iterators ignore DEFAULT

2013-04-08 Thread Andrew Svetlov

Andrew Svetlov added the comment:

NEWS updated, thanks.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17502
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17615] String comparison performance regression

2013-04-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

You can use a single switch instead nested switches:

switch ((kind1  3) + kind2) {
case (PyUnicode_1BYTE_KIND  3) + PyUnicode_1BYTE_KIND: {
int cmp = memcmp(data1, data2, len);
...
}
case (PyUnicode_1BYTE_KIND  3) + PyUnicode_2BYTE_KIND:
COMPARE(Py_UCS1, Py_UCS2);
break;
...
}

I don't know if there is any effect.

--
components: +Interpreter Core
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17615
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17660] mock.patch could whitelist builtins to not need create=True

2013-04-08 Thread Michael Foord

New submission from Michael Foord:

When patching builtin names (e.g. open) in a specific namespace you need to 
specify create=True or patch will refuse to create a name that doesn't exist.

patch could whitelist the builtin names, when the patch target is a module 
object, to not require the create=True.

--
assignee: michael.foord
components: Library (Lib)
keywords: easy
messages: 186290
nosy: michael.foord
priority: normal
severity: normal
stage: needs patch
status: open
title: mock.patch could whitelist builtins to not need create=True
type: behavior
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17660] mock.patch could whitelist builtins to not need create=True

2013-04-08 Thread Kushal Das

Kushal Das added the comment:

Working on this.

--
nosy: +kushaldas

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17661] documentation of '%r' links to the wrong repr

2013-04-08 Thread Thomas Wouters

New submission from Thomas Wouters:

The documentation of '%r' in 
http://docs.python.org/2/library/stdtypes.html#string-formatting-operations 
links to the wrong repr, the module 
(http://docs.python.org/2/library/repr.html#module-repr) instead of the builtin 
function (http://docs.python.org/2/library/functions.html#func-repr).

--
assignee: docs@python
components: Documentation
keywords: easy
messages: 186292
nosy: docs@python, twouters
priority: normal
severity: normal
status: open
title: documentation of '%r' links to the wrong repr
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17661
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17615] String comparison performance regression

2013-04-08 Thread Neil Hodgson

Neil Hodgson added the comment:

A quick rewrite showed the single level case slightly faster (1%) on average 
but its less readable/maintainable. Perhaps taking a systematic approach to 
naming would allow Py_UCS1 to be deduced from PyUnicode_1BYTE_KIND and so avoid 
repeating the information in the case selector and macro invocation.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17615
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17484] add tests for getpass

2013-04-08 Thread R. David Murray

R. David Murray added the comment:

Indeed I did.  That's what I get for staging it one day and committing it the 
next...I forgot I hadn't done the add command.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17484
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17484] add tests for getpass

2013-04-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 113ff45c3f11 by R David Murray in branch 'default':
#17484: Actually add the getpass tests this time.
http://hg.python.org/cpython/rev/113ff45c3f11

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17484
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17484] add tests for getpass

2013-04-08 Thread R. David Murray

R. David Murray added the comment:

Thanks, Thomas.

--
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17484
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17659] First weekday

2013-04-08 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
nosy: +r.david.murray
stage:  - needs patch
versions: +Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17659
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17615] String comparison performance regression

2013-04-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 You can use a single switch instead nested switches:
 
 switch ((kind1  3) + kind2) {
 case (PyUnicode_1BYTE_KIND  3) + PyUnicode_1BYTE_KIND: {
 int cmp = memcmp(data1, data2, len);
 ...
 }

Please let's not add this kind of optifuscation unless it has a large positive 
effect.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17615
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17662] socketmodule raises on import when compiled using Setup.dist on 2.7.4

2013-04-08 Thread Bohuslav Slavek Kabrda

New submission from Bohuslav Slavek Kabrda:

When building extension modules of Python 2.7.4 through Modules/Setup.dist, the 
socketmodule gets built badly, as it also needs to be compiled with 
timemodule.c (see the attached patch).
This was caused by commit 8ec39bfd1f01, which introduced usage of 
_PyTime_floattime() without fixing Setup.dist (note, that this is ok when 
compiling through setup.py, as it has:

exts.append( Extension('_socket', ['socketmodule.c', 'timemodule.c'],

--
components: Build
files: python-2.7.4-properly-compile-socketmodule-by-Setupdist.patch
keywords: patch
messages: 186298
nosy: bkabrda
priority: normal
severity: normal
status: open
title: socketmodule raises on import when compiled using Setup.dist on 2.7.4
type: crash
versions: Python 2.7
Added file: 
http://bugs.python.org/file29730/python-2.7.4-properly-compile-socketmodule-by-Setupdist.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17662
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17658] pythonw.exe crashes on opening IDLE

2013-04-08 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Hum, do you have any environment variable that refer to Python27?
In a terminal window (cmd.exe), try the following command:
  set | findstr /i python

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17658
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17663] re.sub not replacing all

2013-04-08 Thread z06steve

New submission from z06steve:

fails to replace last occurrence of string v_wofstgvw, reproduced in 3.2.3, 
3.2.4 and 3.3.1

a='''

-- V_INT_CTRC_ENTRY_DATE

REPLACE VIEW V_WOFSTGVW.V_INT_CTRC_ENTRY_DATE AS LOCKING ROW FOR ACCESS
SELECT
 D.DY DY,   
 D.DW_CRRT_FL CURRENT_FLAG,   
 D.MTH CURRENT_MTH, 
(CAST(D.DY AS DATE) - EXTRACT(DAY FROM (CAST( D.DY AS DATE)))+1)  
CURRENT_MTH_BEG_DT,  
   ADD_MONTHS ((CAST(D.DY AS DATE) - EXTRACT(DAY FROM (CAST( D.DY AS 
DATE)))+1) , 1) - 1 CURRENT_MTH_END_DT,
D.WOFC_MTH_END_FLG CURRENT_MTH_END_FLG,
 D.WOFC_QTR_END_FLG CURRENT_QTR_END_FL, 
 D.YR CURRENT_YEAR, 
 ((D.YR||'01/01')(DATE)) CURRENT_YEAR_BEG_DT , 
  ((D.YR||'12/31')(DATE)) CURRENT_YEAR_END_DT ,   
 D.WOFC_YR_END_FLG CURRENT_YEAR_END_FL, 
 D.HDAY_FLG HOLIDAY_FLG,
   CAST(ADD_MONTHS (CASE WOFC_MTH_END_FLG
   WHEN 'Y'
  THEN WOFCO_FRST_DY_MTH
   ELSE WOFCO_BEGIN_MTH_DT
END,
-1)AS CHAR(7)) PREV_REP_MTH,
 ADD_MONTHS (CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN WOFCO_FRST_DY_MTH   
ELSE WOFCO_BEGIN_MTH_DT 
 END,   
-1
) PREV_REP_MTH_BEG_DT,  
ADD_MONTHS (CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN D.DY
ELSE D.WOFCO_MTH_END_DT 
 END,   
-1
) PREV_REP_MTH_END_DT  
 ,
 D.PREV_MTH PRIOR_MTH,  
 PSETM.PRIOR_SET_CURRENT_MTH,   
 PSETM.PRIOR_SET_CURRENT_MTH_BGN_DT,  
 PSETM.PRIOR_SET_CURRENT_MTH_END_DT,
 PREPSETM.PRIOR_SET_REP_MTH,  
 PREPSETM.PRIOR_SET_REP_MTH_BGN_DT, 
 PREPSETM.PRIOR_SET_REP_MTH_END_DT,   
 CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN MTH 
ELSE PREV_MTH   
 END REP_MTH,   
 CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN WOFCO_FRST_DY_MTH   
ELSE WOFCO_BEGIN_MTH_DT 
 END REP_MTH_BEG_DT,
 CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN D.DY
ELSE D.WOFCO_MTH_END_DT 
 END REP_MTH_END_DT,
 CASE WOFC_MTH_END_FLG  
WHEN 'Y'
   THEN ADD_MONTHS (D.WOFCO_FRST_DY_MTH,
12
   )
ELSE ADD_MONTHS (D.WOFCO_BEGIN_MTH_DT, 12)  
 END REP_MTH_NEXT_YEAR_BEG_DT,  
 CASE WOFC_MTH_END_FLG

[issue17660] mock.patch could whitelist builtins to not need create=True

2013-04-08 Thread Kushal Das

Kushal Das added the comment:

Initial patchset along with documentation and tests update.

--
keywords: +patch
Added file: http://bugs.python.org/file29731/issue17660.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17660
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >