CodeInvestigator version 1.5.0 was released on April 21.

2011-04-22 Thread hans moleman
CodeInvestigator version 1.5.0 was released on April 21.

Changes:

   - A lot of UI changes. Backgrounds, code blocks and menu.
   - Print statements can now be clicked. The entire printout shows
and what was contributed by the print statement.
   - Browser collection of runtime data is faster: Clicking a
different iteration for example, gives faster results.

Bug fixes:

   - For Windows users: The command window needed to be visible again
to stop it flashing up.
   - There were a few bugs in the searches.

CodeInvestigator is a tracing tool for Python programs.

Running a program through CodeInvestigator creates a recording.
Program flow, function calls, variable values and conditions are all
stored for every line the program executes.
The recording is then viewed with an interface consisting of the code.
The code can be clicked: A clicked variable displays its value, a
clicked loop displays its iterations.
You read code, and have at your disposal all the run time details of
that code. A computerized desk check tool and another way to learn
about your program.

http://sourceforge.net/projects/cde-investigatr/files/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Teaching Python

2011-04-22 Thread harrismh777

Westley Martínez wrote:

But really, hack

 has always been a negative term.  It's original definition is chopping,
 breaking down, kind of like chopping down the security on someone elses
 computer.  Now I don't know where the term originally came from, but the
 definition the media uses is quite a fair use.



Not so much...

... the term hacker was coined at the MIT lab back in the days of the 
PDP-10 /11.   We can thank RMS, and friends.



http://stallman.org/cgi-bin/showpage.cgi?path=/articles/on-hacking.htmlterm=hackingtype=normcase=0


RMS coined the term Cracker for the pejorative use.

Hackers cause no harm; ever.   Hackers are elegant ethical people who 
love the craft for the sake of the craft and the beauty of their art.


Hackers do have a disdain for Herbert, (if you're a Trek-ie you know 
what I mean)...and hackers love to taunt Herbert...


Herbert...!  Herbert...!  Herbert...!

 /\
/  \


Hackers are free and insist on freedom. Hackers would rather count on 
their fingers than be forced to use proprietary closed systems and 
software.  Hackers have no use for IBM, nor Microsoft.  (nor google)



I am and forever will be a joyful hacker   :)




PS   The media is clueless...   (Herbert... Herbert... Herbert...)




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


Input() in Python3

2011-04-22 Thread harrismh777
My interactive scripts are giving errors on the input(). I discovered 
another fairly significant change in Python3, as discussed in PEP 3111.


I was a little flabbergasted to discover that input() was proposed to be 
removed 'totally' from 3000. Of course I agree with PEP 3111 and am 
thankful that input() is still a built-in.  doh.


The problem is that the behavior was significantly changed, again, 
causing existing code to break un-necessarily. So, input() used to be 
equivalent to:


   eval(raw_input(prompt)) -- value


now we get this for input():


   raw_input(prompt) -- string


I'm not whining or anything, just wondering why? Could someone enlighten 
me please?


Anyway, it looks like the best fix for 2.x -- 3.x  code changes:

change:a = input(enter a number  )

to:a = eval(input(enter a number  ))


Again, this is just another example where leaving the advertised 
interface alone would have made more sense... unless of course, I'm 
missing something important here.


kind regards,
m harris

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


Re: dictionary size changed during iteration

2011-04-22 Thread John Nagle

On 4/20/2011 5:52 AM, Laszlo Nagy wrote:

Given this iterator:

class SomeIterableObject(object):



def __iter__(self):
ukeys = self.updates.keys()
for key in ukeys:
if self.updates.has_key(key):
yield self.updates[key]
for rec in self.inserts:
yield rec



How can I get this exception:

RuntimeError: dictionary changed size during iteration


It is true that self.updates is being changed during the iteration. But
I have created the ukeys variable solely to prevent this kind of
error. Here is a proof of correctness:


   I think we need to see some more code here.

   Also, what version of Python are you running?

http://docs.python.org/library/stdtypes.html

says keys()
Return a copy of the dictionary’s list of keys.

So ukeys should be a unique list, not some part of
self.updates or a generator.

At least in Python 2.6, keys() does return a unique list.  Each
call to keys() returns a new list object unconnected to the
dictionary from which the keys were extracted.  But someone may
have decided in a later version to return a generator, as
an optimization.  Did that happen?

John Nagle


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


Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread harrismh777

Heiko Wundram wrote:

The difference between strong typing and weak typing is best described by:

Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type help, copyright, credits or license for more information.

  1+'2'

Traceback (most recent call last):
   File stdin, line 1, inmodule
TypeError: unsupported operand type(s) for +: 'int' and 'str'




Yes. And you have managed to point out a serious flaw in the overall 
logic and consistency of Python, IMHO.


Strings should auto-type-promote to numbers if appropriate.

This behavior should occur in input() as well. If a 'number' string is 
entered and can be converted to a Python number (whatever I mean by that 
at the moment) then the string should be converted to a number (int or 
float as appropriate) and the input() should return a reference to the 
number type  ( a value );  otherwise, input() should return the string 
entered, or throw a type error.


If an operation like (+) is used to add  1 + '1' then the string should 
be converted to int and the addition should take place, returning a 
reference to object int (2).



My feelings about this are strongly influenced by my experiences with 
the REXX language on IBM's SAA systems--- OS/2 and VM/CMS. In REXX 
everything is a string... everything. If a string just happens to be a 
REXX number, then it can be manipulated as you might expect for a 
number.  Neither here, nor there... just that I believe Python could 
take advantage of the Python Number concept and provide for auto-type 
casting of string to number (int or float) as appropriate if the string 
meets the Python Number requirements.


Just an idea... again, probably got beat up long before my time, I'm 
guessing...



kind regards,
m harris



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


Re: Input() in Python3

2011-04-22 Thread Chris Angelico
On Fri, Apr 22, 2011 at 4:22 PM, harrismh777 harrismh...@charter.net wrote:
 now we get this for input():

   raw_input(prompt) -- string

I would have to say that the 2.x behaviour of input() is a mistake
that's being corrected in 3.x. With a simple name like input(), it
should do something simple and straightforward - not eval() the
expression.

 to:        a = eval(input(enter a number  ))

U NO. NO NO NO. What if someone enters os.exit() as their
number? You shouldn't eval() unchecked user input!

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


Re: Input() in Python3

2011-04-22 Thread Chris Angelico
On Fri, Apr 22, 2011 at 4:49 PM, Chris Angelico ros...@gmail.com wrote:
 U NO. NO NO NO. What if someone enters os.exit() as their
 number? You shouldn't eval() unchecked user input!

Whoops, I meant sys.exit() - but you probably knew that already.

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


Re: Closing generators

2011-04-22 Thread Wolfgang Rohdewald
On Freitag 22 April 2011, Terry Reedy wrote:
  for i in g:
  if i is not None:
  g.close()
  return i
 
 When returning from the function, g, if local, should
 disappear.

yes - it disappears in the sense that it no longer 
accessible, but

AFAIK python makes no guarantees as for when an object
is destroyed - CPython counts references and destroys
when no reference is left, but that is implementation
specific

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Chris Angelico
On Fri, Apr 22, 2011 at 4:38 PM, harrismh777 harrismh...@charter.net wrote:
 My feelings about this are strongly influenced by my experiences with the
 REXX language on IBM's SAA systems--- OS/2 and VM/CMS. In REXX everything is
 a string... everything. If a string just happens to be a REXX number, then
 it can be manipulated as you might expect for a number.

Wow, someone else who knows REXX and OS/2! REXX was the first bignum
language I met, and it was really cool after working in BASIC and
80x86 assembly to suddenly be able to work with arbitrary-precision
numbers!

The everything is a string, but treat it as a number if you like
system is rather handy in a few places. I wanted it for my automated
DNS editor - I wanted to concatenate several numbers (from the date,
and the constant 1), and then, if the resulting number is not
greater than another number (the previous serial), increment. Ahh
well...

I'm not so sure that all strings should autopromote to integer (or
numeric generally). However, adding a string and a number _should_
(IMHO) promote the number to string.

print Hello, +name+, you have +credit+ dollars of credit with us.

Okay, that one is probably better done with the % operator, but it
definitely makes logical sense to concatenate numbers and strings as
strings, not to add them as numbers.

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


Re: shared dictionary of dictionaries with Manager

2011-04-22 Thread Dan Stromberg
2011/4/21 Darío Suárez Gracia dario.sua...@telefonica.net

 Hi all,
 I was trying to share a dictionary of dictionaries of arrays with Manager
 from multiprocessing. Without multiprocessing the code works perfectly, but
 with the current example the last print does not show the correct result.


It appears that if you put a manager.dict A, inside another manager.dict B,
then B gets passed to a subprocess as a manager.dict, but A gets passed
across as a vanilla dict (in 2.7) - so naturally, changes in A go undetected
in other processes.  This might be a bug; the doc says you can nest manager
types.  It's probably getting lost when the manager.dict is pickled and then
unpickled on the other end.  It might be possible to fix this with copy_reg
or __reduce__ or __getstate__, but no guarantees.

You'll probably be better served by rearchitecting a bit anyway - try to use
simpler types in shared memory (these are fast), or pass a little more
complex types via queues (these aren't terribly fast, but at least they're a
cogent abstraction).

Using lots of shared, mutable state is a Bad Thing for concurrency. - it
complicates things fast, and will kill the performance benefits of
concurrency you're trying to get.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Input() in Python3

2011-04-22 Thread Chris Rebert
On Thu, Apr 21, 2011 at 11:22 PM, harrismh777 harrismh...@charter.net wrote:
 My interactive scripts are giving errors on the input(). I discovered
 another fairly significant change in Python3, as discussed in PEP 3111.

 I was a little flabbergasted to discover that input() was proposed to be
 removed 'totally' from 3000. Of course I agree with PEP 3111 and am thankful
 that input() is still a built-in.  doh.

Well, it pretty much *was* totally removed; it was prone to misuse and
had very few legitimate uses. It's just that raw_input() also got
renamed simultaneously.
What were you using it for? There are often much better alternatives.

 The problem is that the behavior was significantly changed, again, causing
 existing code to break un-necessarily.

Python 3 has many unnecessary backwards-incompatible changes; the
Python devs have made this abundantly clear and one should be aware of
this before going into Python 3. And again, I don't think a behavior
change is the best way to conceptualize this, although from a user
perspective, there indeed isn't much difference between a behavior
change and a simultaneous removal and renaming.

 So, input() used to be equivalent to:

   eval(raw_input(prompt)) -- value


 now we get this for input():


   raw_input(prompt) -- string


 I'm not whining or anything, just wondering why? Could someone enlighten me
 please?

 Anyway, it looks like the best fix for 2.x -- 3.x  code changes:

 change:    a = input(enter a number  )

 to:        a = eval(input(enter a number  ))

Did you run your scripts through the 2to3 converter tool? This is one
of the many changes it can apply automatically.

 Again, this is just another example where leaving the advertised interface
 alone would have made more sense... unless of course, I'm missing something
 important here.

input() was rarely used correctly and is quite trivially replaced.
raw_input() was used much more frequently, but was a bit awkwardly
named. Python 3 made use of its backwards-incompatible status to
rectify both of these problems at once. Writing correct code will be
now easier for newbies.

If you're porting stuff to Python 3, using 2to3 and reading the
summary of changes from 2.x are absolute necessities.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Snowball to Python compiler

2011-04-22 Thread Stefan Behnel

Terry Reedy, 22.04.2011 05:48:

On 4/21/2011 8:25 PM, Paul Rubin wrote:

Matt Chaput writes:

I'm looking for some code that will take a Snowball program and
compile it into a Python script. Or, less ideally, a Snowball
interpreter written in Python.

(http://snowball.tartarus.org/)

Anyone heard of such a thing?


I never saw snowball before, it looks kind of interesting, and it
looks like it already has a way to compile to C. If you're using
it for IR on any scale, you're surely much better off using the C
routines with a C API wrapper,


If the C routines are in a shared library, you should be able to write the
interface in Python with ctypes.


Since it appears that the code has to get compiled anyway, Cython is likely 
a better option, as it makes it easier to write a fast and Pythonic wrapper.


From a quick look, Snowball also has a -widechar option that could allow 
interfacing directly with Python's Unicode strings in 16-bit Unicode builds 
(but not 32-bit builds!). That would provide for really fast wrappers that 
do not even need an intermediate encoding step. And PEP 393 would 
eventually allow to include both a UTF-8 and a 16-bit version of the 
(prefixed) Snowball code, and to use them alternatively, depending on the 
internal layout of the processed string, with the obvious fallback to UTF-8 
encoding only for strings that really exceed the lower 16-bit Unicode range.


That sounds like a really nice project.

Stefan

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


Re: Closing generators

2011-04-22 Thread Thomas Rachel

Am 22.04.2011 09:01, schrieb Wolfgang Rohdewald:


On Freitag 22 April 2011, Terry Reedy wrote:



When returning from the function, g, if local, should
disappear.


yes - it disappears in the sense that it no longer
accessible, but

AFAIK python makes no guarantees as for when an object
is destroyed - CPython counts references and destroys
when no reference is left, but that is implementation
specific


Right - that's what I am thought about when writing the OP. But Terry is 
right - often the generator doesn't need to know that is 
closed/terminated, which is anyway possible only since 2.5.


But in these (admittedly rarely) cases, it is better practice to close 
explicitly, isn't it?



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


PyLZMA lastwritetime file to python datetime

2011-04-22 Thread rabusta
How convert lastwritetime file to python datetime?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyLZMA lastwritetime file to python datetime

2011-04-22 Thread Chris Rebert
On Fri, Apr 22, 2011 at 1:49 AM, rabusta rabu...@gmail.com wrote:
 How convert lastwritetime file to python datetime?

[Mildly educated guess after scanning
https://github.com/fancycode/pylzma/blob/master/py7zlib.py ]:

It's likely a Unix timestamp. Perhaps try
datetime.datetime.utcfromtimestamp() or
datetime.datetime.fromtimestamp() ?
http://docs.python.org/library/datetime.html#datetime.datetime.utcfromtimestamp
http://docs.python.org/library/datetime.html#datetime.datetime.fromtimestamp

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-22 Thread Jean-Michel Pichavant

MRAB wrote:

On 21/04/2011 18:12, Pascal J. Bourguignon wrote:

chadcdal...@gmail.com  writes:


Let's say I have the following

class BaseHandler:
 def foo(self):
 print Hello

class HomeHandler(BaseHandler):
 pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


But you created one!


No, he didn't, he created an instance of HomeHandler.
I think this is really wrong within the OP question context. This is a 
key concept about OOP and inheritance, any object of class HomeHandler 
is an object of class BaseHandler and also an object of any other base 
class.


However it is true that for convenience, there are some language abuses 
around this terms that we're all using, for instance:
 - class refers to the lowest class of the object (like the python 
__class__ attribute)
 - instance of means sometimes created using the constructor of 
when stating for example  that you cannot create an instance of a 
virtual class. From a formal OO POV, anyone can create an instance of a 
virtual class, you just need to create an instance of one of its 
subclass. What you cannot, is create a instance of a virtual class using 
the constructor of that virtual class.


Also note that
isinstance(test, BaseHandler)
returns True. And this is no Python trick to trigger some magic, this is 
what OO is about.



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


Re: PyLZMA lastwritetime file to python datetime

2011-04-22 Thread rabusta
On Apr 22, 5:12 pm, Chris Rebert c...@rebertia.com wrote:
 [Mildly educated guess after 
 scanninghttps://github.com/fancycode/pylzma/blob/master/py7zlib.py]:

 It's likely a Unix timestamp. Perhaps try
 datetime.datetime.utcfromtimestamp() or
 datetime.datetime.fromtimestamp() 
 ?http://docs.python.org/library/datetime.html#datetime.datetime.utcfro...http://docs.python.org/library/datetime.html#datetime.datetime.fromti...


Thanks for the reply!
but lastwritetime contains 64bit value and function
datetime.fromtimestamp an error (timestamp out of range for platform
time_t), I tried to take only the upper 32bit, but it does not
correspond to the actual date file...

for example:
 f.header.files.files[0]['lastwritetime']
14620470108690448384L

real date: 2010-04-28 06:22:20
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Argument count mismatch

2011-04-22 Thread Daniel Kluev
On Fri, Apr 22, 2011 at 12:43 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 It looks to me like this function relies on no fewer than three global
 variables, two that you read from and one which you write to:

 c
 Session
 MSPResponse

 This is almost certainly poor design. Using global state is almost always
 harmful and should be avoided.

Looks like its something similar to Pylons web framework. While
generally globals vars are indeed bad, in this case they are
specifically provided by framework to be used this way.
They are 'thread-local' rather than global, and usually cause no harm,
since framework guarantees that these instances are bound to context
of this particular http request.

-- 
With best regards,
Daniel Kluev
-- 
http://mail.python.org/mailman/listinfo/python-list


Pairwise frequency count from an incidence matrix of group membership

2011-04-22 Thread Shafique, M. (UNU-MERIT)
Hi,
I have a number of different groups g1, g2, … g100 in my data. Each group is 
comprised of a known but different set of members (m1, m2, …m1000) from the 
population. The data has been organized in an incidence matrix:
g1g2g3g4g5
m01
m210010
m301100
m411011
m500110

I need to count how many groups each possible pair of members share (i.e., both 
are member of). 
I shall prefer the result in a pairwise edgelist with weight/frequency in a 
format like the following:
m1, m1, 4
m1, m2, 1
m1, m3, 2
m1, m4, 3
m1, m5, 1
m2, m2, 2
... and so  on.

I shall highly appreciate if anybody could suggest/share some code/tool/module 
which could help do this.

Best regards,
Muhammad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pairwise frequency count from an incidence matrix of group membership

2011-04-22 Thread Jean-Michel Pichavant

Shafique, M. (UNU-MERIT) wrote:

Hi,
I have a number of different groups g1, g2, … g100 in my data. Each 
group is comprised of a known but different set of members (m1, m2, 
…m1000) from the population. The data has been organized in an 
incidence matrix:

g1 g2 g3 g4 g5
m1 1 1 1 0 1
m2 1 0 0 1 0
m3 0 1 1 0 0
m4 1 1 0 1 1
m5 0 0 1 1 0

I need to count how many groups each possible pair of members share 
(i.e., both are member of). 
I shall prefer the result in a pairwise edgelist with weight/frequency 
in a format like the following:

m1, m1, 4
m1, m2, 1
m1, m3, 2
m1, m4, 3
m1, m5, 1
m2, m2, 2
... and so on.

I shall highly appreciate if anybody could suggest/share some 
code/tool/module which could help do this.


Best regards,
Muhammad


Here are some clues

m1 = [1,1,1,0,1]
m2 = [1,0,0,1,0]

def foo(list1, list2):
 return len([ index for index, val in enumerate(list1) if val and 
list2[index]])


 foo(m1, m1)
 4

 foo(m1, m2)
 1


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


Re: Vectors

2011-04-22 Thread Algis Kabaila
On Friday 22 April 2011 11:43:26 Gregory Ewing wrote:
 Algis Kabaila wrote:
  the Vector3 class
  is available without any prefix euclid:
  
  import euclid
  v = Vector3(111.., 222.2, 333.3)
 
 Doesn't work that way for me:
 
 Python 2.7 (r27:82500, Oct 15 2010, 21:14:33)
 [GCC 4.2.1 (Apple Inc. build 5664)] on darwin
 Type help, copyright, credits or license for more
 information.
 
   import euclid
   Vector3
 
 Traceback (most recent call last):
File stdin, line 1, in module
 NameError: name 'Vector3' is not defined
 
 Are you sure you hadn't previously done 'from euclid import
 Vector3' or 'from euclid import *' in that session?

I've tested it again and it does behave in a standard manner.  
I must have imported all as you suspected. Makes me much 
happier, though I do feel sheepish.  As they say, sh... happens.

BTW, I did modify the euclid very slightly to work with Python 3 
- just change the syntax of messages with exception in line with 
syntax changes.

Thanks for sharing your experience with that cute package!

OldAl.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary size changed during iteration

2011-04-22 Thread Mark Niemczyk
As of Python 3.x (which I suspect you are running):

The objects returned by dict.keys(), dict.values() and dict.items() are view 
objects. They provide a dynamic view on the dictionary’s entries, which means 
that when the dictionary changes, the view reflects these changes., and 

Iterating views while adding or deleting entries in the dictionary may raise a 
RuntimeError or fail to iterate over all entries.

 see: http://docs.python.org/release/3.1.3/library/stdtypes.html#dict-views

On my system:
ActivePython 3.2.0.0 (ActiveState Software Inc.) based on
Python 3.2 (r32:88445, Feb 21 2011, 11:25:33) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type copyright, credits or license() for more information.
 ukeys = {}
 type(ukeys.keys())
class 'dict_keys'
 

So, to achieve your objective, one solution could be to change the ukeys 
assignment statement to:

 ukeys = list(self.updates.keys())



Hope this helps,

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


Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Mel
harrismh777 wrote:

 Heiko Wundram wrote:
 The difference between strong typing and weak typing is best described
 by:

 Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
 [GCC 4.3.4 20090804 (release) 1] on cygwin
 Type help, copyright, credits or license for more information.
   1+'2'
 Traceback (most recent call last):
File stdin, line 1, inmodule
 TypeError: unsupported operand type(s) for +: 'int' and 'str'
 
 
 Yes. And you have managed to point out a serious flaw in the overall
 logic and consistency of Python, IMHO.
 
 Strings should auto-type-promote to numbers if appropriate.

Appropriate is the problem.  This is why Perl needs two completely 
different kinds of comparison -- one that works as though its operands are 
numbers, and one that works as though they're strings.  Surprises to the 
programmer who picks the wrong one.

Mel.

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


Re: dictionary size changed during iteration

2011-04-22 Thread Roy Smith
In article mailman.644.1303306435.9059.python-l...@python.org,
 Peter Otten __pete...@web.de wrote:

 You now have to create the list explicitly to avoid the error:
 
  d = dict(a=1)
  keys = list(d.keys())
  for k in keys:
 ... d[b] = 42
 ...

That works, but if d is large, it won't be very efficient because it has 
to generate a large list.

If d is large, and the number of keys to be mutated is relatively small, 
a better solution may be to do it in two passes.  The first loop 
traverses the iterator and builds a list of things to be changed.  The 
second loop changes them.

changes = [ ]
for key in d.iterkeys():
  if is_bad(key):
changes.append(key)
for key in changes:
  d[key] = I'm not dead yet

Both solutions are O(n), but the second may run significantly faster and 
use less memory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Roy Smith
In article iorui3$a9g$1...@speranza.aioe.org, Mel mwil...@the-wire.com 
wrote:

  Strings should auto-type-promote to numbers if appropriate.
 
 Appropriate is the problem.  This is why Perl needs two completely 
 different kinds of comparison -- one that works as though its operands are 
 numbers, and one that works as though they're strings.  Surprises to the 
 programmer who picks the wrong one.

Ugh, tell me about it.

The project I'm currently working on used to use PHP (which has the same 
auto-promotion semantics as Perl) as the front end to a SQL database.  
The PHP code gleefully turned strings into numbers and back again all 
over the place, but it all got cleaned up at the database interface 
since SQL has strict typing.

We converted the back end database to MongoDB, which does not have 
strict typing.  We're still cleaning up the mess of inconsistent data 
(i.e. string vs integer) that creeps into the database through various 
paths.  Not to mention 0 vs. '' vs null vs false.

Implicit type conversion can be convenient.  But, then again, so can 
removing the safety guards from a chain saw.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes for AIX

2011-04-22 Thread sjw
I need to!But  ctypes can't work on AIX...
Need help..


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


Re: ctypes for AIX

2011-04-22 Thread Stefan Behnel

sjw, 22.04.2011 15:26:

I need to!But  ctypes can't work on AIX...
Need help..


What are you trying to do, and why do you need ctypes for it?

Stefan

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


Re: Teaching Python

2011-04-22 Thread Westley Martínez
On Fri, Apr 22, 2011 at 01:04:55AM -0500, harrismh777 wrote:
 Westley Martínez wrote:
 But really, hack
  has always been a negative term.  It's original definition is chopping,
  breaking down, kind of like chopping down the security on someone elses
  computer.  Now I don't know where the term originally came from, but the
  definition the media uses is quite a fair use.
 
 
 Not so much...
 
 ... the term hacker was coined at the MIT lab back in the days of
 the PDP-10 /11.   We can thank RMS, and friends.
 
 
 http://stallman.org/cgi-bin/showpage.cgi?path=/articles/on-hacking.htmlterm=hackingtype=normcase=0
 
 
 RMS coined the term Cracker for the pejorative use.
 
 Hackers cause no harm; ever.   Hackers are elegant ethical people
 who love the craft for the sake of the craft and the beauty of their
 art.
 
 Hackers do have a disdain for Herbert, (if you're a Trek-ie you
 know what I mean)...and hackers love to taunt Herbert...
 
 Herbert...!  Herbert...!  Herbert...!
 
  /\
 /  \
 
 
 Hackers are free and insist on freedom. Hackers would rather count
 on their fingers than be forced to use proprietary closed systems
 and software.  Hackers have no use for IBM, nor Microsoft.  (nor
 google)
 
 
 I am and forever will be a joyful hacker   :)
 
 
 
 
 PS   The media is clueless...   (Herbert... Herbert... Herbert...)
 
 
 
 

Well I guess that means I'm no hacker.  I love IBM and Microsoft (and
Google, too ^_^).  So what would you call me?  A developer?  I'm
unemployed.  A cracker?  Well I do like to exploit website's security
and occasionally social engineer my friends' e-mail accounts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-22 Thread Kyle T. Jones

Ethan Furman wrote:

chad wrote:

Let's say I have the following

class BaseHandler:
def foo(self):
print Hello

class HomeHandler(BaseHandler):
pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


You don't need to create an instance of BaseHandler.  You have the
class, Python knows you have the class -- Python will look there if the
subclasses lack an attribute.

~Ethan~



Really?  That's not at all how I thought it worked in Python 
(post-instantiation referencing of class and superclass code...)


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


Re: Input() in Python3

2011-04-22 Thread Westley Martínez
On Fri, Apr 22, 2011 at 04:49:19PM +1000, Chris Angelico wrote:
 On Fri, Apr 22, 2011 at 4:22 PM, harrismh777 harrismh...@charter.net wrote:
  now we get this for input():
 
    raw_input(prompt) -- string
 
 I would have to say that the 2.x behaviour of input() is a mistake
 that's being corrected in 3.x. With a simple name like input(), it
 should do something simple and straightforward - not eval() the
 expression.
 
  to:        a = eval(input(enter a number  ))
 
 U NO. NO NO NO. What if someone enters os.exit() as their
 number? You shouldn't eval() unchecked user input!
 
 Chris Angelico

Right, there's no way to check you're getting a number, however using:

a = int(input('enter a number  ')) # use float() for floats

will raise an exception if it can't convert the string.
-- 
http://mail.python.org/mailman/listinfo/python-list


suggestions, comments on an is_subdict test

2011-04-22 Thread Vlastimil Brom
Hi all,
I'd like to ask for comments or advice on a simple code for testing a
subdict, i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:

def is_subdict(test_dct, base_dct):
Test whether all the items of test_dct are present in base_dct.
unique_obj = object()
for key, value in test_dct.items():
if not base_dct.get(key, unique_obj) == value:
return False
return True

I'd like to ask for possibly more idiomatic solutions, or more obvious
ways to do this. Did I maybe missed some builtin possibility?
I am unsure whether the check  against an unique object() or the
negated comparison are usual.?
(The builtin exceptions are ok, in case anything not dict-like is
passed. A cornercase like  is_subdict({}, 4)
 True
doesen't seem to be worth a special check just now.)

Thanks in advance for the suggestions,
  regards,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Input() in Python3

2011-04-22 Thread Mel
Westley Martínez wrote:
 On Fri, Apr 22, 2011 at 04:49:19PM +1000, Chris Angelico wrote:

 U NO. NO NO NO. What if someone enters os.exit() as their
 number? You shouldn't eval() unchecked user input!
 
 Chris Angelico
 
 Right, there's no way to check you're getting a number, however using:
 
 a = int(input('enter a number  ')) # use float() for floats
 
 will raise an exception if it can't convert the string.

But sys.exit() doesn't return a string.  My fave is

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type help, copyright, credits or license for more information.
 import sys
 a = int (input ('enter a number '))
enter a number sys.setrecursionlimit(1)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a 
Python object' in type 'exceptions.RuntimeError' ignored
Exception RuntimeError: 'maximum recursion depth exceeded while calling a 
Python object' in type 'exceptions.RuntimeError' ignored
Error in sys.excepthook:
RuntimeError: maximum recursion depth exceeded

Original exception was:
Traceback (most recent call last):
  File stdin, line 1, in module
RuntimeError: maximum recursion depth exceeded while calling a Python object
 int (0)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a 
Python object' in type 'exceptions.RuntimeError' ignored
Exception RuntimeError: 'maximum recursion depth exceeded while calling a 
Python object' in type 'exceptions.RuntimeError' ignored
Error in sys.excepthook:
RuntimeError: maximum recursion depth exceeded

Original exception was:
Traceback (most recent call last):
  File stdin, line 1, in module
RuntimeError: maximum recursion depth exceeded while calling a Python object
 


Mel.

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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread MRAB

On 22/04/2011 14:55, Vlastimil Brom wrote:

Hi all,
I'd like to ask for comments or advice on a simple code for testing a
subdict, i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:

def is_subdict(test_dct, base_dct):
 Test whether all the items of test_dct are present in base_dct.
 unique_obj = object()
 for key, value in test_dct.items():
 if not base_dct.get(key, unique_obj) == value:
 return False
 return True

I'd like to ask for possibly more idiomatic solutions, or more obvious
ways to do this. Did I maybe missed some builtin possibility?
I am unsure whether the check  against an unique object() or the
negated comparison are usual.?
(The builtin exceptions are ok, in case anything not dict-like is
passed. A cornercase like  is_subdict({}, 4)

True

doesen't seem to be worth a special check just now.)


You could shorten it slightly to:

def is_subdict(test_dct, base_dct):
Test whether all the items of test_dct are present in base_dct.
unique_obj = object()
return all(base_dct.get(key, unique_obj) == value for key, value in 
test_dct.items())

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


Re: ctypes for AIX

2011-04-22 Thread Anssi Saari
Waddle, Jim jim.wad...@boeing.com writes:

 I do not have sufficient knowledge to know how to fix this. I would think 
 that this error somehow is related to compiling on aix. If you have any 
 suggestions on how to correct this problem , I would appreciate it

I'd have to guess your main problem is not using gcc to compile. From
a quick look, that's what the guys at the pware site did.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Peter Otten
Vlastimil Brom wrote:

 Hi all,
 I'd like to ask for comments or advice on a simple code for testing a
 subdict, i.e. check whether all items of a given dictionary are
 present in a reference dictionary.
 Sofar I have:
 
 def is_subdict(test_dct, base_dct):
 Test whether all the items of test_dct are present in base_dct.
 unique_obj = object()
 for key, value in test_dct.items():
 if not base_dct.get(key, unique_obj) == value:
 return False
 return True
 
 I'd like to ask for possibly more idiomatic solutions, or more obvious
 ways to do this. Did I maybe missed some builtin possibility?
 I am unsure whether the check  against an unique object() or the
 negated comparison are usual.?
 (The builtin exceptions are ok, in case anything not dict-like is
 passed. A cornercase like  is_subdict({}, 4)
 True
 doesen't seem to be worth a special check just now.)

I would avoid the unique object because it's neither hard nor costly:

def is_subdict(test, base):
return all(k in base and base[k] == v for k, v in test.iteritems())


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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Chris Rebert
On Fri, Apr 22, 2011 at 6:55 AM, Vlastimil Brom
vlastimil.b...@gmail.com wrote:
 Hi all,
 I'd like to ask for comments or advice on a simple code for testing a
 subdict, i.e. check whether all items of a given dictionary are
 present in a reference dictionary.
 Sofar I have:

 def is_subdict(test_dct, base_dct):
    Test whether all the items of test_dct are present in base_dct.
    unique_obj = object()
    for key, value in test_dct.items():
        if not base_dct.get(key, unique_obj) == value:
            return False
    return True

 I'd like to ask for possibly more idiomatic solutions, or more obvious
 ways to do this. Did I maybe missed some builtin possibility?
 I am unsure whether the check  against an unique object() or the
 negated comparison are usual.?

I second MRAB's all() suggestion. The use of object() as a higher-rank
None is entirely normal; don't worry about it.

Also, the following occurs to me as another idiomatic, perhaps more
/conceptually/ elegant possibility, but it's /practically/ speaking
quite inefficient (unless perhaps some dict view tricks can be
exploited):

def is_subdict(sub, larger):
return set(sub.items()).issubset(set(larger.items()))

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Zero Piraeus
:

 I'd like to ask for comments or advice on a simple code for testing a
 subdict, i.e. check whether all items of a given dictionary are
 present in a reference dictionary.

Anything wrong with this?

def is_subdict(test_dct, base_dct):
return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
k in test_dct)

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Wolfgang Rohdewald
On Freitag 22 April 2011, Vlastimil Brom wrote:
 check whether all items of a given dictionary are
 present in a reference dictionary

I would not call this is_subdict. That name does not
clearly express that all keys need to have the same
value.

set(subdict.items()) = set(reference.items())

should be equivalent to your code

if you only want to check for presence of all
keys in the reference dict:

set(subdict.keys()) = set(reference.keys())

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


Re: Pairwise frequency count from an incidence matrix of group membership

2011-04-22 Thread scattered
On Apr 22, 6:57 am, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:
 Shafique, M. (UNU-MERIT) wrote:
  Hi,
  I have a number of different groups g1, g2, … g100 in my data. Each
  group is comprised of a known but different set of members (m1, m2,
  …m1000) from the population. The data has been organized in an
  incidence matrix:
  g1 g2 g3 g4 g5
  m1 1 1 1 0 1
  m2 1 0 0 1 0
  m3 0 1 1 0 0
  m4 1 1 0 1 1
  m5 0 0 1 1 0

  I need to count how many groups each possible pair of members share
  (i.e., both are member of).
  I shall prefer the result in a pairwise edgelist with weight/frequency
  in a format like the following:
  m1, m1, 4
  m1, m2, 1
  m1, m3, 2
  m1, m4, 3
  m1, m5, 1
  m2, m2, 2
  ... and so on.

  I shall highly appreciate if anybody could suggest/share some
  code/tool/module which could help do this.

  Best regards,
  Muhammad

 Here are some clues

 m1 = [1,1,1,0,1]
 m2 = [1,0,0,1,0]

 def foo(list1, list2):
       return len([ index for index, val in enumerate(list1) if val and
 list2[index]])

   foo(m1, m1)
  4

   foo(m1, m2)
  1

 JM- Hide quoted text -

 - Show quoted text -

He seems to have variables named m1,m2, etc. Would make more sense to
have an array m, but given the varables:

def count_matches(i,j):
pairs = zip(eval(m+str(i)),eval(m+str(j)))
return sum([x*y for x,y in pairs])

Then:

 m3 = [1,0,1,1]
 m4 = [1,0,0,1]
 count_matches(3,4)
 2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding empty columns. Is there a faster way?

2011-04-22 Thread nn
On Apr 21, 4:32 pm, Jon Clements jon...@googlemail.com wrote:
 On Apr 21, 5:40 pm, nn prueba...@latinmail.com wrote:









  time head -100 myfile  /dev/null

  real    0m4.57s
  user    0m3.81s
  sys     0m0.74s

  time ./repnullsalt.py '|' myfile
  0 1 Null columns:
  11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68

  real    1m28.94s
  user    1m28.11s
  sys     0m0.72s

  import sys
  def main():
      with open(sys.argv[2],'rb') as inf:
          limit = sys.argv[3] if len(sys.argv)3 else 1
          dlm = sys.argv[1].encode('latin1')
          nulls = [x==b'' for x in next(inf)[:-1].split(dlm)]
          enum = enumerate
          split = bytes.split
          out = sys.stdout
          prn = print
          for j, r in enum(inf):
              if j%100==0:
                  prn(j//100,end=' ')
                  out.flush()
                  if j//100=limit:
                      break
              for i, cur in enum(split(r[:-1],dlm)):
                  nulls[i] |= cur==b''
      print('Null columns:')
      print(', '.join(str(i+1) for i,val in enumerate(nulls) if val))

  if not (len(sys.argv)2):
      sys.exit(Usage: +sys.argv[0]+
            delimiter filename limit)

  main()

 What's with the aliasing enumerate and print??? And on heavy disk IO I
 can hardly see that name lookups are going to be any problem at all?
 And why the time stats with /dev/null ???

 I'd probably go for something like:

 import csv

 with open('somefile') as fin:
     nulls = set()
     for row in csv.reader(fin, delimiter='|'):
         nulls.update(idx for idx,val in enumerate(row, start=1) if not
 val)
     print 'nulls =', sorted(nulls)

 hth
 Jon

Thanks, Jon
aliasing is a common method to avoid extra lookups. The time stats for
head is giving the pure I/O time. So of the 88 seconds the python
program takes 5 seconds are due to I/O, so there is quite a bit of
overhead.

I ended up with this, not super fast so I probably won't be running it
against all 350 million rows of my file but faster than before:

time head -100 myfile |./repnulls.py
nulls = [11, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 33, 45, 50, 68]

real0m49.95s
user0m53.13s
sys 0m2.21s


import sys
def main():
fin = sys.stdin.buffer
dlm = sys.argv[1].encode('latin1') if len(sys.argv)1 else b'|'
nulls = set()
nulls.update(i for row in fin for i, val in
enumerate(row[:-1].split(dlm), start=1) if not val)
print('nulls =', sorted(nulls))
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Irmen de Jong
On 22-4-2011 15:55, Vlastimil Brom wrote:
 Hi all,
 I'd like to ask for comments or advice on a simple code for testing a
 subdict, i.e. check whether all items of a given dictionary are
 present in a reference dictionary.
 Sofar I have:
 
 def is_subdict(test_dct, base_dct):
 Test whether all the items of test_dct are present in base_dct.
 unique_obj = object()
 for key, value in test_dct.items():
 if not base_dct.get(key, unique_obj) == value:
 return False
 return True
 
 I'd like to ask for possibly more idiomatic solutions, or more obvious
 ways to do this. Did I maybe missed some builtin possibility?


I would use:

test_dct.items() = base_dct.items()

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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Peter Otten
Zero Piraeus wrote:

 :
 
 I'd like to ask for comments or advice on a simple code for testing a
 subdict, i.e. check whether all items of a given dictionary are
 present in a reference dictionary.
 
 Anything wrong with this?
 
 def is_subdict(test_dct, base_dct):
 return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
 k in test_dct)

It may raise a KeyError.

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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread MRAB

On 22/04/2011 15:57, Irmen de Jong wrote:

On 22-4-2011 15:55, Vlastimil Brom wrote:

Hi all,
I'd like to ask for comments or advice on a simple code for testing a
subdict, i.e. check whether all items of a given dictionary are
present in a reference dictionary.
Sofar I have:

def is_subdict(test_dct, base_dct):
 Test whether all the items of test_dct are present in base_dct.
 unique_obj = object()
 for key, value in test_dct.items():
 if not base_dct.get(key, unique_obj) == value:
 return False
 return True

I'd like to ask for possibly more idiomatic solutions, or more obvious
ways to do this. Did I maybe missed some builtin possibility?



I would use:

test_dct.items()= base_dct.items()


In Python 2:

 test_dct = {foo: 0, bar: 1}
 base_dct = {foo: 0, bar: 1, baz: 2}

 test_dct.items() = base_dct.items()
False

In Python 3:

 test_dct = {foo: 0, bar: 1}
 base_dct = {foo: 0, bar: 1, baz: 2}
 test_dct.items() = base_dct.items()
True

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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Zero Piraeus
:

 Anything wrong with this?

 def is_subdict(test_dct, base_dct):
     return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
 k in test_dct)

 It may raise a KeyError.

Really? That was what ``test_dct = base_dct and`` ... is supposed to
prevent. Have I missed something?

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Input() in Python3

2011-04-22 Thread Benjamin Kaplan
On Apr 22, 2011 10:12 AM, Mel mwil...@the-wire.com wrote:

 Westley Martínez wrote:
  On Fri, Apr 22, 2011 at 04:49:19PM +1000, Chris Angelico wrote:

  U NO. NO NO NO. What if someone enters os.exit() as their
  number? You shouldn't eval() unchecked user input!
 
  Chris Angelico
 
  Right, there's no way to check you're getting a number, however using:
 
  a = int(input('enter a number  ')) # use float() for floats
 
  will raise an exception if it can't convert the string.

 But sys.exit() doesn't return a string.  My fave is

 Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
 [GCC 4.4.3] on linux2
 Type help, copyright, credits or license for more information.
  import sys
  a = int (input ('enter a number '))
 enter a number sys.setrecursionlimit(1)
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in type 'exceptions.RuntimeError' ignored
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in type 'exceptions.RuntimeError' ignored
 Error in sys.excepthook:
 RuntimeError: maximum recursion depth exceeded

 Original exception was:
 Traceback (most recent call last):
  File stdin, line 1, in module
 RuntimeError: maximum recursion depth exceeded while calling a Python
object
  int (0)
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in type 'exceptions.RuntimeError' ignored
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in type 'exceptions.RuntimeError' ignored
 Error in sys.excepthook:
 RuntimeError: maximum recursion depth exceeded

 Original exception was:
 Traceback (most recent call last):
  File stdin, line 1, in module
 RuntimeError: maximum recursion depth exceeded while calling a Python
object
 


Mel.


We're talking about python 3, not python 2. If you're using python 2, the
equivalent code would be int(raw_input()) and that isn't vulnerable to this
sort of thing.
 --
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Peter Otten
Zero Piraeus wrote:

 Anything wrong with this?

 def is_subdict(test_dct, base_dct):
 return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
 k in test_dct)

 It may raise a KeyError.
 
 Really? That was what ``test_dct = base_dct and`` ... is supposed to
 prevent. Have I missed something?

 {1:0} = {2:0}
True
 def is_subdict(test_dct, base_dct):
... return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
... k in test_dct)
...
 is_subdict({1:0}, {2:0})
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 3, in is_subdict
  File stdin, line 3, in genexpr
KeyError: 1

I think you have to convert to sets before performing the = comparison to 
get a proper subset test.

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


dict comparison [was: suggestions, comments on an is_subdict test]

2011-04-22 Thread Zero Piraeus
:

On 22 April 2011 13:30, Peter Otten __pete...@web.de wrote:
 def is_subdict(test_dct, base_dct):
 ...     return test_dct = base_dct and all(test_dct[k] == base_dct[k] for
 ... k in test_dct)
 ...
 is_subdict({1:0}, {2:0})
 Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 3, in is_subdict
  File stdin, line 3, in genexpr
 KeyError: 1

 I think you have to convert to sets before performing the = comparison to
 get a proper subset test.

Huh. I thought I remembered that dict comparison worked like set
comparison (and my admittedly minimal testing seemed to confirm that).
Turns out it's actually consistent, but not otherwise defined beyond
equality.

  http://docs.python.org/reference/expressions.html#id15

I maintain that the behaviour I expected makes more sense ;-) I wonder
whether making it work the way I want it to (dammit) would have been
as prohibitively expensive as the lexicographical comparison mentioned
in the footnote referenced in the above link?

 -[]z.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About threads in python

2011-04-22 Thread sturlamolden
On Apr 21, 3:19 pm, dutche dut...@gmail.com wrote:

 My question is about the efficiency of threads in python, does anybody
 has something to share?

Never mind all the FUD about the GIL. Most of it is ill-informed
and plain wrong.

The GIL prevents you from doing one thing, which is parallel
compute-bound code in plain Python. But that is close to
idiotic use of Python threads anyway. I would seriously
question the competance of anyone attempting this, regardless
of the GIL. It is optimising computational code in the wrong
end.

To optimise computational code, notice that Python itself
gives you a 200x performance penalty. That is much more
important than not using all 4 cores on a quadcore processor.
In this case, start by identifying bottlenecks using the
profiler. Then apply C libraries or these or rewrite to Cython.
If that is not sufficient, you can start to think about using
more hardware (e.g. multithreading in C or Cython). This advice
only applies to computational code though. Most usecases for
Python will be i/o bound (file i/o, GUI, database, webserver,
internet client), for which the GIL is not an issue at all.

Python threads will almost always do what you expect. Try
your code first -- if they don't scale, then ask this question.
Usually the problem will be in your own code, and have nothing
to do with the GIL. This is almost certainly the case if an
i/o bound server do not scale, as i/o bound Python code are
(almost) never affected by the GIL.

In cases where a multi-threaded i/o solution do not scale,
you likely want to use asynchronous design instead, as the problem
can be the use of threads per se. See if Twisted fits your need.
Scalability problems for i/o bound server might also be external to
Python. For example it could be a database server and not the use
of Python threads. For example switching from Sqlite to
Microsoft SQL server will have impact on the way your program
behaves under concurrent load: Sqlite is is faster per query,
but has a global lock. If you want concurrent access to a
database, a global lock in the database is a much more important
issue than a global lock in the Python interpreter. If you want
a fast response, the sluggishness of the database can be more
important than the synchronization of the Python code.

In the rare event that the GIL is an issue, there are still
things you can do:

You can always use processes instead of threads (i.e.
multiprocessing.Process instead of threading.Thread). Since
the API is similar, writing threaded code is never a waste of
effort.

There are also Python implementations that don't have a GIL
(PyPy, Jython, IronPython). You can just swap interpreter
and see if it scales better.

Testing with another interpreter or multiprocessing is a good
litmus test to see if the problem is in your own code.

Cython and Pyrex are compilers for a special CPython extension
module language. They give you full control over the GIL, as well
as the speed of C when you need it. They can make Python threads
perform as good as threads in C for computational code -- I have
e.g. compared with OpenMP to confirm for myself, and there is
really no difference.

You thus have multiple options if the GIL gets in your way,
without major rewrite, including:

- Interpreter without a GIL (PyPy, Jython, IronPython)
- multiprocessing.Process instead of threading.Thread
- Cython or Pyrex

Things that require a little bit more effort include:

- Use a multi-threaded C library for your task.
- ctypes.CDLL
- OpenMP in C/C++, call with ctypes or Cython
- Outproc COM+ server + pywin32
- Fortran + f2py
- rewrite to use os.fork (except Windows)


IMHO:

The biggest problems with the GIL is not the GIL, but
bullshit FUD and C libraries that don't release the GIL
as often as they should. NumPy ans SciPy is notorius cases
of the latter, and there are similar cases in the standard
library as well.

If I should give an advice it would be to just try Python threads
and see for your self. Usually they will do what you expect.
You only have a problem if they do not. In that case there
are plenty of things that can be done, most of them with very
little effort.


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


Re: A question about Python Classes

2011-04-22 Thread Ethan Furman

Kyle T. Jones wrote:

Ethan Furman wrote:

chad wrote:

Let's say I have the following

class BaseHandler:
def foo(self):
print Hello

class HomeHandler(BaseHandler):
pass


Then I do the following...

test = HomeHandler()
test.foo()

How can HomeHandler call foo() when I never created an instance of
BaseHandler?


You don't need to create an instance of BaseHandler.  You have the
class, Python knows you have the class -- Python will look there if the
subclasses lack an attribute.

~Ethan~



Really?  That's not at all how I thought it worked in Python 
(post-instantiation referencing of class and superclass code...)


I'm not sure exactly what you're asking/stating, but does this help?

8---Py 3.2 code--
class BaseClass():
def bFoo(self):
print(Base foo here!)

class NormalClass(BaseClass):
def nFoo(self):
print(Normal foo here.)

class EnhancedClass(NormalClass):
def eFoo(self):
print(Enhanced foo comin' at ya!)

class EnrichedClass(EnhancedClass):
def rFoo(self):
print(Am I glowing yet?)

test = EnrichedClass()
test.bFoo()
test.nFoo()
test.eFoo()
test.rFoo()

def newFoo(self):
print(Ha!  You've been replaced!)

BaseClass.bFoo = newFoo

test.bFoo()
8--
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict comparison [was: suggestions, comments on an is_subdict test]

2011-04-22 Thread Peter Otten
Zero Piraeus wrote:

 :
 
 On 22 April 2011 13:30, Peter Otten __pete...@web.de wrote:
 def is_subdict(test_dct, base_dct):
 ... return test_dct = base_dct and all(test_dct[k] == base_dct[k]
 for ... k in test_dct)
 ...
 is_subdict({1:0}, {2:0})
 Traceback (most recent call last):
 File stdin, line 1, in module
 File stdin, line 3, in is_subdict
 File stdin, line 3, in genexpr
 KeyError: 1

 I think you have to convert to sets before performing the = comparison
 to get a proper subset test.
 
 Huh. I thought I remembered that dict comparison worked like set
 comparison (and my admittedly minimal testing seemed to confirm that).
 Turns out it's actually consistent, but not otherwise defined beyond
 equality.
 
   http://docs.python.org/reference/expressions.html#id15
 
 I maintain that the behaviour I expected makes more sense ;-) 
 I wonder
 whether making it work the way I want it to (dammit) would have been
 as prohibitively expensive as the lexicographical comparison mentioned
 in the footnote referenced in the above link?

The discussion is moot for Python 2, and because of backwards compatibility 
has been for a long time. Python 3 uses a different approach:

 {1:0}  {1:0}
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unorderable types: dict()  dict()

This is the behaviour that makes the most sense to me. I would have 
preferred attempts at set comparison to raise the same error which would 
have prevented surprises like

 a, b = {1}, {2}
 a  b, a  b, a == b
(False, False, False)
 a, b = sorted([{1}, {2}])
 a = b
False


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


Re: A question about Python Classes

2011-04-22 Thread Ian Kelly
On Fri, Apr 22, 2011 at 7:49 AM, Kyle T. Jones
onexpadrem...@evomeryahoodotyouknow.com wrote:
 You don't need to create an instance of BaseHandler.  You have the
 class, Python knows you have the class -- Python will look there if the
 subclasses lack an attribute.

 ~Ethan~


 Really?  That's not at all how I thought it worked in Python
 (post-instantiation referencing of class and superclass code...)

Yes, it looks up the attribute in the superclass tree at the time that
it's referenced, not at the time it's instantiated or at the time the
class is created.  So:

 class Base(object):
... x = 5
...
 class Test(Base):
... pass
...
 t = Test()
 t.x
5
 Test.x = 42
 t.x
42
 Base.x = 7
 del Test.x
 t.x
7

Or were you talking about something else?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A question about Python Classes

2011-04-22 Thread Carl Banks
On Thursday, April 21, 2011 11:00:08 AM UTC-7, MRAB wrote:
 On 21/04/2011 18:12, Pascal J. Bourguignon wrote:
  chadcda...@gmail.com  writes:
 
  Let's say I have the following
 
  class BaseHandler:
   def foo(self):
   print Hello
 
  class HomeHandler(BaseHandler):
   pass
 
 
  Then I do the following...
 
  test = HomeHandler()
  test.foo()
 
  How can HomeHandler call foo() when I never created an instance of
  BaseHandler?
 
  But you created one!
 
 No, he didn't, he created an instance of HomeHandler.
 
  test is an instance of HomeHandler, which is a subclass of BaseHandler,
  so test is also an instance of BaseHandler.
 
 test isn't really an instance of BaseHandler, it's an instance of
 HomeHandler, which is a subclass of BaseHandler.

I'm going to vote that this is incorrect usage.  An instance of HomeHandler is 
also an instance of BaseHandler, and it is incorrect to say it is not.  The 
call to HomeHandler does create an instance of BaseHandler.

The Python language itself validates this usage.  isinstance(test,BaseHandler) 
returns True.


If you are looking for a term to indicate an object for which type(test) == 
BaseHandler, then I would suggest proper instance.  test is an instance of 
BaseHandler, but it is not a proper instance.


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


Re: Input() in Python3

2011-04-22 Thread Chris Angelico
On Sat, Apr 23, 2011 at 12:08 AM, Mel mwil...@the-wire.com wrote:
 But sys.exit() doesn't return a string.  My fave is

It doesn't return _at all_. Boom, process terminated.

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


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Vlastimil Brom
Thanks everyone for your opinions and suggestions!
I especially like the all(...) approaches of MRAB and Peter Otten,
however, the set conversion like
 set(test_dct.items()) = set(base_dct.items())
True
looks elegant too.
In both approaches I can get rid of the negated comparison and the
additional parsing cost (for me reading it) is not that high.

As for the name,  I tried to make explicit (for this post), that both
the keys and their values are important in this test, but it doesn't
matter that much if is_subdict doesn't communicate this well
(probably?), as the audience of this code is not going to be anyone
but me.

Thanks for all the comments!
  regards,
vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread MRAB

On 22/04/2011 21:31, Vlastimil Brom wrote:

Thanks everyone for your opinions and suggestions!
I especially like the all(...) approaches of MRAB and Peter Otten,
however, the set conversion like

set(test_dct.items())= set(base_dct.items())

True
looks elegant too.


That works only if the values in the dicts are hashable.


In both approaches I can get rid of the negated comparison and the
additional parsing cost (for me reading it) is not that high.

As for the name,  I tried to make explicit (for this post), that both
the keys and their values are important in this test, but it doesn't
matter that much if is_subdict doesn't communicate this well
(probably?), as the audience of this code is not going to be anyone
but me.


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


Re: Vectors

2011-04-22 Thread sturlamolden
On Apr 20, 9:47 am, Algis Kabaila akaba...@pcug.org.au wrote:

 Are there any modules for vector algebra (three dimensional
 vectors, vector addition, subtraction, multiplication [scalar
 and vector]. Could you give me a reference to such module?

NumPy

Or one of these libraries (ctypes or Cython):

BLAS (Intel MKL, ACML, ACML-GPU, GotoBLAS2, or ATLAS)
Intel VML
ACML-VM








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


Re: learnpython.org - an online interactive Python tutorial

2011-04-22 Thread Dan Stromberg
On Thu, Apr 21, 2011 at 11:38 PM, harrismh777 harrismh...@charter.netwrote:


 Yes. And you have managed to point out a serious flaw in the overall logic
 and consistency of Python, IMHO.

 Strings should auto-type-promote to numbers if appropriate.


Please no.  It's a little more convenient sometimes when you're coding, but
it adds bugs that aren't worth the small benefit.

Explicit is better than implicit.

http://www.python.org/dev/peps/pep-0020/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestions, comments on an is_subdict test

2011-04-22 Thread Steven D'Aprano
On Fri, 22 Apr 2011 07:38:38 -0700, Chris Rebert wrote:

 Also, the following occurs to me as another idiomatic, perhaps more
 /conceptually/ elegant possibility, but it's /practically/ speaking
 quite inefficient (unless perhaps some dict view tricks can be
 exploited):
 
 def is_subdict(sub, larger):
 return set(sub.items()).issubset(set(larger.items()))

That cannot work if either dict contains an unhashable value:

 d = {2: []}
 set(d.items())
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unhashable type: 'list'


But if you know your dict items are hashable, and your dicts not 
especially large, I don't see why we should fear the inefficiency of 
turning them into sets. Worrying about small efficiencies is usually 
counter-productive, especially in a language like Python that so often 
trades off machine efficiency for developer efficiency.


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


Re: Input() in Python3

2011-04-22 Thread Steven D'Aprano
On Sat, 23 Apr 2011 06:25:51 +1000, Chris Angelico wrote:

 On Sat, Apr 23, 2011 at 12:08 AM, Mel mwil...@the-wire.com wrote:
 But sys.exit() doesn't return a string.  My fave is
 
 It doesn't return _at all_. Boom, process terminated.


Technically it raises an exception, which can then be caught by the usual 
exception-handling mechanism. So it's not quite Boom.

 try:
... sys.exit(42)
... except SystemExit as e:
... print(e.code)
...
42



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


Re: Input() in Python3

2011-04-22 Thread Chris Angelico
On Sat, Apr 23, 2011 at 9:55 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Sat, 23 Apr 2011 06:25:51 +1000, Chris Angelico wrote:

 On Sat, Apr 23, 2011 at 12:08 AM, Mel mwil...@the-wire.com wrote:
 But sys.exit() doesn't return a string.  My fave is

 It doesn't return _at all_. Boom, process terminated.


 Technically it raises an exception, which can then be caught by the usual
 exception-handling mechanism. So it's not quite Boom.

Sure, but it still doesn't return anything. In any case, it's not
something you want to eval casually in the middle of asking the user
for an integer.

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


Re: .Well, ok, I will try some of that. But I am running window 7, not Linux.

2011-04-22 Thread P S
I did a little writeup for setting PyVISA up in Windows. It's not exactly 
polished, but it can get you through the difficult bits. If you need any 
additional help, leave comments/questions on my blog.

http://psonghi.wordpress.com/2011/03/29/pyvisa-setup-in-windows/

 On Friday, April 01, 2011 11:29 AM Manatee wrote:

 I have unpacked the PyVISA files into the Python/lib/site-packages dir
 and from the IDLE GUI I get and error
 
 import visa
 
 Traceback (most recent call last):
 File pyshell#25, line 1, in module
 import visa
 ImportError: No module named visa
 
 
 
 There must be more to just putting the files in the correct directory.
 Need help configuring PyVISA to work.
 My ultimate goal is to control electronic instruments with Python
 through visa.


 On Friday, April 01, 2011 2:05 PM GüntherDietrich wrote:

 Yes, there is more:
 
 - DON'T unpack the files into any site-packages folder. If you already
 have done it, remove them.
 - Unpack the PyVISA archive to any other folder.
 - On the command line, change into the PyVISA folder. There you should
 find - among others - the two files setup.py and setup.cfg (at least
 if you use PyVISA-1.3.tar.gz).
 - Now, it depends on what variant of python you use and want to install
 PyVISA for and on the configuration of your PYTHONPATH rsp. sys.path
 and the folders they point to.
 You can simply try: 'sudo python ./setup install'
 If you are lucky, that is it. If not, you have to decide, where the
 installation script has to put the files to. For example, for my
 python 2.6, I chose
 '/Library/Frameworks/Python.framework/Versions/2.6/'. In this path,
 there is a folder 'lib/site-packages', which is pointed to by
 sys.path, and where .pth files are evaluated.
 - Edit the file setup.cfg. Near the end, in section '[install]', you will
 find the line 'prefix=/usr'. Replace the '/usr' by your chosen path.
 - Save the file and retry the install (see above).
 
 
 
 Best regards,
 
 G??nther


 On Friday, April 01, 2011 3:40 PM Manatee wrote:

 .
 
 Well, ok, I will try some of that. But I am running window 7, not Linux.
 The sudo command sounds like Linux.



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


Re: Vectors

2011-04-22 Thread Algis Kabaila
On Saturday 23 April 2011 06:57:23 sturlamolden wrote:
 On Apr 20, 9:47 am, Algis Kabaila akaba...@pcug.org.au 
wrote:
  Are there any modules for vector algebra (three dimensional
  vectors, vector addition, subtraction, multiplication
  [scalar and vector]. Could you give me a reference to such
  module?
 
 NumPy
 
 Or one of these libraries (ctypes or Cython):
 
 BLAS (Intel MKL, ACML, ACML-GPU, GotoBLAS2, or ATLAS)
 Intel VML
 ACML-VM

Thanks for that.  Last time I looked at numpy (for Python3) it 
was available in source only.  I know, real men do compile, but 
I am an old man...  I will compile if it is unavoidable, but in 
case of numpy it does not seem  a simple matter. Am I badly 
mistaken?

euclid has another attraction - the source is readily available, 
not too burdened by backward compatibility issues and relatively 
easy to follow, though I managed to get lost in it   :)

OldAl.
-- 
Algis
http://akabaila.pcug.org.au/StructuralAnalysis.pdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Run a few Python commands from a temporary filesystem when the rootfs is halted

2011-04-22 Thread Frederick Grose
Forwarded conversation
Subject: Run a few Python commands from a temporary filesystem when the
rootfs is halted


From: *Frederick Grose* fgr...@gmail.com
Date: Fri, Apr 22, 2011 at 7:54 PM
To: tu...@python.org


With Bash, when one needs to halt the current root filesystem, to pivot to a
new filesystem, one can copy some of the command files and their
dependencies to a temporary file system and execute from that code base.

Is there a way to accomplish the same within a Python script?

Or must I chain Python and Bash together for this?

  --Fred

--
From: *Steve Willoughby* st...@alchemy.com
Date: Fri, Apr 22, 2011 at 7:59 PM
To: tu...@python.org


I'm not sure those words mean what you think they mean, or I'm missing what
you're trying to do here.  halting the root filesystem? pivot? code base?

You're not trying to talk about jail/chroot, perhaps?

-- 
Steve Willoughby / st...@alchemy.com
A ship in harbor is safe, but that is not what ships are built for.
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
___
Tutor maillist  -  tu...@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

--
From: *Frederick Grose* fgr...@gmail.com
Date: Fri, Apr 22, 2011 at 8:14 PM
To: tu...@python.org


The particulars are that I've rebuilt a Fedora LiveOS filesystem image from
a currently running instance (incorporating the filesystem changes in the
device-mapper overlay into a new base filesystem image file).

I'd like to halt the active rootfs, switch to its mirror, copy over the
halted filesystem image file with the refreshed version, and then switch
back.

--Fred

--
From: *Steven D'Aprano* st...@pearwood.info
Date: Fri, Apr 22, 2011 at 8:22 PM
To: tu...@python.org


This is way off-topic for a Python tutor list. This is about learning the
Python programming language, not the intricate corners of (I assume) Linux
system administration.

I would imagine that it would be very, very difficult in Python, because you
would need somehow to end the *current* Python process and start up a *new*
Python process running from executables on the new file system, without
manual intervention.

I strongly suggest you take this question to the main Python list,
pyt...@python.org, which is also available as a news group comp.lang.python,
and show the bash code you are trying to duplicate. There's no guarantee
you'll get an answer there either, but it's more likely than here.

Good luck!


-- 
Steven

The Bash code I'm trying to simulate is from Douglas McClendon's
ZyX-LiveInstaller,
http://cloudsession.com/dawg/projects/zyx-liveinstaller/

After copying /sbin/dmsetup and its dependencies to
/dev/shm/zyx-liveinstaller (/dev/shm is mounted on a tmpfs), the following
code is executed:

LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
/dev/shm/zyx-liveinstaller/dmsetup \
--noudevrules --noudevsync \
suspend ${liveos_root_dev}
LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
/dev/shm/zyx-liveinstaller/dmsetup \
--noudevrules --noudevsync \
resume ${liveos_root_dev}-sub
LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
/dev/shm/zyx-liveinstaller/dmsetup \
--noudevrules --noudevsync \
resume ${liveos_root_dev}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Closing generators

2011-04-22 Thread Terry Reedy

On 4/22/2011 4:01 AM, Thomas Rachel wrote:

Am 22.04.2011 09:01, schrieb Wolfgang Rohdewald:


On Freitag 22 April 2011, Terry Reedy wrote:



When returning from the function, g, if local, should
disappear.


yes - it disappears in the sense that it no longer
accessible, but

AFAIK python makes no guarantees as for when an object
is destroyed - CPython counts references and destroys
when no reference is left, but that is implementation
specific


.close() methods that release operating system resources are needed 
*because* there is no guarantee of immediate garbage collection. They 
were not needed when CPython was the only Python. The with statement was 
added partly to make it easier to make sure that .close() was called.



Right - that's what I am thought about when writing the OP. But Terry is
right - often the generator doesn't need to know that is
closed/terminated, which is anyway possible only since 2.5.

But in these (admittedly rarely) cases, it is better practice to close
explicitly, isn't it?


If by 'rare case' you mean a generator that opens a file or socket, or 
something similar, then yes. One can think of a opened file object as an 
iterator (it has __iter__ and __next__) with lots of other methods.
Instead of writing such a generator, though, I might consider an 
iterator class with __enter__ and __exit__ methods so that it was also a 
with-statement context manager, just like file objects and other such 
things, so that closing would be similarly automatic. Or easier:


from contextlib import closing

def generator_that_needs_closing(args): ...

with closing(generator_that_needs_closing(args)) as g:
for item in g:
do stuff

and g.close() will be called on exit from the statement.

The 'closing' example in the doc uses urlopen, which similarly has a 
close() methods


--
Terry Jan Reedy

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


Re: Run a few Python commands from a temporary filesystem when the rootfs is halted

2011-04-22 Thread Dan Stromberg
You could open a pivot_root subprocess using the subprocess module, or
you could run pivot_root() directly using ctypes.  I doubt any
preexisting Python module wraps pivot_root(), but I'd love to be
surprised.  You may find that your Python module path does amusing
things right after the pivot, so don't be taken aback much if import
suddenly doesn't see some module.

On Fri, Apr 22, 2011 at 5:52 PM, Frederick Grose fgr...@gmail.com wrote:
 Forwarded conversation
 Subject: Run a few Python commands from a temporary filesystem when the
 rootfs is halted
 

 From: Frederick Grose fgr...@gmail.com
 Date: Fri, Apr 22, 2011 at 7:54 PM
 To: tu...@python.org


 With Bash, when one needs to halt the current root filesystem, to pivot to a
 new filesystem, one can copy some of the command files and their
 dependencies to a temporary file system and execute from that code base.

 Is there a way to accomplish the same within a Python script?

 Or must I chain Python and Bash together for this?

   --Fred

 --
 From: Steve Willoughby st...@alchemy.com
 Date: Fri, Apr 22, 2011 at 7:59 PM
 To: tu...@python.org


 I'm not sure those words mean what you think they mean, or I'm missing what
 you're trying to do here.  halting the root filesystem? pivot? code base?

 You're not trying to talk about jail/chroot, perhaps?

 --
 Steve Willoughby / st...@alchemy.com
 A ship in harbor is safe, but that is not what ships are built for.
 PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

 --
 From: Frederick Grose fgr...@gmail.com
 Date: Fri, Apr 22, 2011 at 8:14 PM
 To: tu...@python.org


 The particulars are that I've rebuilt a Fedora LiveOS filesystem image from
 a currently running instance (incorporating the filesystem changes in the
 device-mapper overlay into a new base filesystem image file).

 I'd like to halt the active rootfs, switch to its mirror, copy over the
 halted filesystem image file with the refreshed version, and then switch
 back.

     --Fred

 --
 From: Steven D'Aprano st...@pearwood.info
 Date: Fri, Apr 22, 2011 at 8:22 PM
 To: tu...@python.org


 This is way off-topic for a Python tutor list. This is about learning the
 Python programming language, not the intricate corners of (I assume) Linux
 system administration.

 I would imagine that it would be very, very difficult in Python, because you
 would need somehow to end the *current* Python process and start up a *new*
 Python process running from executables on the new file system, without
 manual intervention.

 I strongly suggest you take this question to the main Python list,
 pyt...@python.org, which is also available as a news group comp.lang.python,
 and show the bash code you are trying to duplicate. There's no guarantee
 you'll get an answer there either, but it's more likely than here.

 Good luck!


 --
 Steven

 The Bash code I'm trying to simulate is from Douglas McClendon's
 ZyX-LiveInstaller,
 http://cloudsession.com/dawg/projects/zyx-liveinstaller/

 After copying /sbin/dmsetup and its dependencies to
 /dev/shm/zyx-liveinstaller (/dev/shm is mounted on a tmpfs), the following
 code is executed:

 LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
     /dev/shm/zyx-liveinstaller/dmsetup \
     --noudevrules --noudevsync \
     suspend ${liveos_root_dev}
 LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
     /dev/shm/zyx-liveinstaller/dmsetup \
     --noudevrules --noudevsync \
     resume ${liveos_root_dev}-sub
 LD_LIBRARY_PATH=/dev/shm/zyx-liveinstaller \
     /dev/shm/zyx-liveinstaller/dmsetup \
     --noudevrules --noudevsync \
     resume ${liveos_root_dev}







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


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


Re: Vectors

2011-04-22 Thread sturlamolden
On Apr 23, 2:32 am, Algis Kabaila akaba...@pcug.org.au wrote:

 Thanks for that.  Last time I looked at numpy (for Python3) it
 was available in source only.  I know, real men do compile, but
 I am an old man...  I will compile if it is unavoidable, but in
 case of numpy it does not seem  a simple matter. Am I badly
 mistaken?


There is a Win32 binary for Python 3.1:

http://sourceforge.net/projects/numpy/files/NumPy/1.5.1/

I have not tried to compile NumPy as I use Enthought to
avoid such headaches. I value my own time enough to pay
for a subscription ;-)

http://enthought.com/



Sturla

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


[issue11899] TarFile.gettarinfo modifies self.inodes

2011-04-22 Thread Lars Gustäbel

Lars Gustäbel l...@gustaebel.de added the comment:

Good point. Do you happen to have a working implementation already?

--
assignee:  - lars.gustaebel
priority: normal - low
versions: +Python 3.3 -Python 3.2

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



[issue11879] TarFile.chown: should use TarInfo.uid if user lookup fails

2011-04-22 Thread Lars Gustäbel

Changes by Lars Gustäbel l...@gustaebel.de:


--
assignee:  - lars.gustaebel
priority: normal - low

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



[issue9228] Make changes in the PATH and PATHEXT on installation

2011-04-22 Thread Jonathan Hartley

Changes by Jonathan Hartley tart...@tartley.com:


--
nosy: +jonathan.hartley

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



[issue11907] SysLogHandler can't send long messages

2011-04-22 Thread Lukáš Lalinský

New submission from Lukáš Lalinský lalin...@gmail.com:

It seems that logging.handlers.SysLogHandler can't handle messages that can't 
be passed atomically via the socket. I'm not sure what is the right behavior 
(the syslog() function truncates the message), but I think it shouldn't 
propagate the exception to the application.

Python 2.7.1 (r271:86832, Apr 18 2011, 08:47:29) 
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd8
Type help, copyright, credits or license for more information.
 import logging.handlers
 handler = logging.handlers.SysLogHandler('/dev/log')
 logger = logging.getLogger()
 logger.addHandler(handler)
 logger.warn('x' * 4096)
Traceback (most recent call last):
  File /usr/local/lib/python2.7/logging/handlers.py, line 808, in emit
self.socket.send(msg)
error: [Errno 40] Message too long
Logged from file stdin, line 1

--
messages: 134265
nosy: lukas.lalinsky
priority: normal
severity: normal
status: open
title: SysLogHandler can't send long messages
type: crash
versions: Python 2.7

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



[issue2292] Missing *-unpacking generalizations

2011-04-22 Thread Fred L. Drake, Jr.

Changes by Fred L. Drake, Jr. fdr...@acm.org:


--
nosy: +fdrake

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



[issue9325] Add an option to pdb/trace/profile to run library module as a script

2011-04-22 Thread Greg Słodkowicz

Greg Słodkowicz jerg...@gmail.com added the comment:

Thanks, Nick. Before your last comment, I haven't looked much into Pdb, instead 
focusing on profile.py and trace.py because they looked like simpler cases. I 
think the approach with CodeRunner objects would work just fine for profile and 
trace but Pdb uses run() inherited from Bdb. In order to make it work with a 
CodeRunner object, it seems run() would have to be reimplemented in Pdb 
(effectively becoming a 'runCodeRunner()'), and we could probably do without 
_runscript(). Is that what you had in mind?

--

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



[issue11513] chained exception/incorrect exception from tarfile.open on a non-existent file

2011-04-22 Thread Barry A. Warsaw

Barry A. Warsaw ba...@python.org added the comment:

Commented on the patch.  I'll be happy to land this for Evan.

--
assignee:  - barry
nosy: +barry

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



[issue11885] argparse docs needs fixing

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


Removed file: http://bugs.python.org/file21750/unnamed

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



[issue11885] argparse docs needs fixing

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

No problem, it’s Ezio who did the work.

--
versions:  -Python 3.4

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



[issue1322] platform.dist() has unpredictable result under Linux

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

The hard part was supporting distro-specific release files; I think that now 
most of them provide the lsb_release info.  If it proves more complicated than 
that, then let’s deprecate the function.

--

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



[issue11881] Add list.get

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

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



[issue11862] urlparse.ParseResult to have meaningful __str__

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Why couldn’t ParseResult call urlunparse to implement a useful __str__?

--
components: +Library (Lib) -Extension Modules
nosy: +eric.araujo
versions: +Python 3.3

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



[issue11869] Include information about the bug tracker Rietveld code review tool

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

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



[issue10154] locale.normalize strips - from UTF-8, which fails on Mac

2011-04-22 Thread Piotr Sikora

Piotr Sikora piotr.sik...@frickle.com added the comment:

It's the same on OpenBSD (and I'm pretty sure it's true for other BSDs as well).

 locale.resetlocale()
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python2.6/locale.py, line 523, in resetlocale
_setlocale(category, _build_localename(getdefaultlocale()))
locale.Error: unsupported locale setting
 locale._build_localename(locale.getdefaultlocale())
'en_US.UTF8'

Works fine with Marc-Andre's alias table fix.

Any chances this will be eventually fixed in 2.x?

--
nosy: +PiotrSikora

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



[issue11873] test_regexp() of test_compileall failure on x86 OpenIndiana 3.x

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

How do we debug this?  Does someone have access to a similar box to see whether 
the pyc files do get created and where?

--
nosy: +eric.araujo

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



[issue11874] argparse assertion failure with brackets in metavars

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +bethard, eric.araujo
versions: +Python 3.2, Python 3.3

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



[issue11879] TarFile.chown: should use TarInfo.uid if user lookup fails

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

If you make the suggested change to your Python, do the tests still pass?

--
nosy: +eric.araujo

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



[issue11884] Argparse calls ngettext but doesn't import it

2011-04-22 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I added the import and calls in 1827a8ac9b18, so this report is strange.  What 
is your exact version and where did you get it?

--
assignee:  - eric.araujo
nosy: +eric.araujo

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



[issue11901] Docs for sys.hexversion should give the algorithm

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

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



[issue11906] Test_argparse failure but only in interactive mode

2011-04-22 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

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



[issue11901] Docs for sys.hexversion should give the algorithm

2011-04-22 Thread Raymond Hettinger

Raymond Hettinger raymond.hettin...@gmail.com added the comment:

+1

--
nosy: +rhettinger

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



[issue11908] Weird `slice.stop or sys.maxint`

2011-04-22 Thread Ram Rachum

New submission from Ram Rachum cool...@cool-rr.com:

In the documentation for `itertools.islice` I see this line:

it = iter(xrange(s.start or 0, s.stop or sys.maxint, s.step or 1))

Is it really okay to do `s.stop or sys.maxint`? I'm assuming this was targeting 
`None`, but what if `s.stop == 0`? And `s.step` could (pathologically) be `0` 
too, no?

--
assignee: docs@python
components: Documentation
messages: 134276
nosy: cool-RR, docs@python
priority: normal
severity: normal
status: open
title: Weird `slice.stop or sys.maxint`
type: behavior
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 
3.3, Python 3.4

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



[issue11908] Weird `slice.stop or sys.maxint`

2011-04-22 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee: docs@python - rhettinger
nosy: +rhettinger

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



[issue1322] platform.dist() has unpredictable result under Linux

2011-04-22 Thread Zooko O'Whielacronx

Zooko O'Whielacronx zo...@zooko.com added the comment:

There seems to be some mistake, re #msg134219 and #msg134255. The current 
version of may patch *does* avoid the cost of a subprocess in the common case. 
I described this new strategy in #msg73744 and as far as I know it satisfies 
all of MAL's earlier objection about that.

To recap, this code here: 
http://tahoe-lafs.org/trac/tahoe-lafs/browser/trunk/src/allmydata/__init__.py?annotate=blamerev=5033#L36
 does the following strategy:

1. Parse the /etc/lsb-release file. /etc/lsb-release is not part of the de jure 
standard, but it is a de facto standard that is available on many 
distributions. Parsing it is fast and gives the right answer on many 
distributions.

2. If that didn't work (which can happen on some distributions, including 
common ones when a certain optional lsb base package isn't installed), then 
invoke the current platform.dist() code. This is a lot of code, its code has to 
be changed before it can recognize any new distribution or a change in a 
distribution, and it gives answers on Ubuntu and Arch Linux which users say are 
the wrong answer, but it is fast and it gives the answer users want in most 
cases.

3. If that didn't work (which presumably only happens on distributions that the 
authors of platform.dist() didn't know about or didn't bother to support), then 
invoke the de jure standard executable lsb_release. This works on any 
LSB-compliant system, but it costs a subprocess.

4. If that didn't work, check for /etc/arch-release to signal Arch Linux.

--

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



[issue11909] Doctest sees directives in strings when it should only see them in comments

2011-04-22 Thread Devin Jeanpierre

New submission from Devin Jeanpierre jeanpierr...@gmail.com:

From the doctest source:

'Option directives are comments starting with doctest:.  Warning: this may 
give false  positives for string-literals that contain the string #doctest:.  
Eliminating these false positives would require actually parsing the string; 
but we limit them by ignoring any line containing #doctest: that is 
*followed* by a quote mark.'

This isn't a huge deal, but it's a bit annoying. Above being confusing, this is 
in contradiction with the doctest documentation, which states:

'Doctest directives are expressed as a special Python comment following an 
example’s source code'

No mention is made of this corner case where the regexp breaks.

As per the comment in the source, the patched version parses the source using 
the tokenize module, and runs a modified directive regex on all comment tokens 
to find directives.

--
components: Library (Lib)
files: comments.diff
keywords: patch
messages: 134278
nosy: Devin Jeanpierre
priority: normal
severity: normal
status: open
title: Doctest sees directives in strings when it should only see them in 
comments
Added file: http://bugs.python.org/file21757/comments.diff

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



[issue11909] Doctest sees directives in strings when it should only see them in comments

2011-04-22 Thread R. David Murray

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


--
stage:  - patch review
type:  - feature request
versions: +Python 3.3

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



[issue11873] test_regexp() of test_compileall failure on x86 OpenIndiana 3.x

2011-04-22 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Given that it happens randomly I suspect a timing issue, but without having 
reviewed the code in question.  I'm not sure when I'll have time to look at 
this.

--

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



[issue9319] imp.find_module('test/badsyntax_pep3120') causes segfault

2011-04-22 Thread R. David Murray

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


--
status: closed - open

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



[issue11885] argparse docs needs fixing

2011-04-22 Thread Boštjan Mejak

Boštjan Mejak bostjan.me...@gmail.com added the comment:

I ment to say Ezio. Got confused. Thanks, Ezio!

--
Added file: http://bugs.python.org/file21758/unnamed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11885
___I ment to say Ezio. Got confused. Thanks, Ezio!
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8407] expose signalfd(2) and pthread_sigmask in the signal module

2011-04-22 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
title: expose signalfd(2) and sigprocmask(2) in the signal module - expose 
signalfd(2) and pthread_sigmask in the signal module

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



[issue9319] imp.find_module('test/badsyntax_pep3120') causes segfault

2011-04-22 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset fa5e348889c2 by Victor Stinner in branch '3.2':
Issue #9319: Fix a crash on parsing a Python source code without encoding
http://hg.python.org/cpython/rev/fa5e348889c2

--

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



[issue9319] imp.find_module('test/badsyntax_pep3120') causes segfault

2011-04-22 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Fixed in 3.2 (fa5e348889c2) and 3.3 (7b8d625eb6e4). The bug is a regression 
introduced in Python 3.2, so Python 3.1 doesn't need to be fixed.

--
status: open - closed

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



[issue9319] imp.find_module('test/badsyntax_pep3120') causes segfault

2011-04-22 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset 701069f9888c by Victor Stinner in branch '3.2':
Issue #9319: Fix the unit test
http://hg.python.org/cpython/rev/701069f9888c

--

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



[issue11906] Test_argparse failure but only in interactive mode

2011-04-22 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

If I put the same line I ran interactively in a file and run it

from test import test_argparse as t; t.test_main()

all tests pass. So it is specifically a problem from the interactive prompt.

--
nosy: +michael.foord

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



  1   2   >