PyOhio (July 30-31) Call for Proposals; due June 3

2011-04-28 Thread Catherine Devlin
PyOhio 2011, the fourth annual Python programming conference for Ohio
and the surrounding region, will take place Saturday-Sunday, July
30-31, 2011 at the Ohio State University in Columbus, Ohio. A variety
of activities are planned, including tutorials, scheduled talks,
Lightning Talks, Open Spaces and Sprints.

PyOhio invites all interested people to submit proposals for scheduled
talks, tutorials, and panels. All topics of interest to Python
programmers will be considered. Standard presentation slots will be 40
minutes plus a 10 minute question-and-answer period.

PyOhio is a great venue to get word out about your favorite Python
library and how you use it, talk about how Python is used in your
company, or practice your speaking in front of a welcoming audience.

PyOhio is especially interested in hosting a Beginner’s Track for
those new to Python or new to programming in general. If your proposal
would be suitable for inclusion in a Beginner’s Track, please indicate
so. Organizers will work with speakers and instructors in the
Beginner’s Track to help them coordinate their talks/tutorials into a
smooth, coherent learning curve for new Python users.

To ensure that you provide all necessary information, please use the
submission template provided below. If organizing a panel, please
confirm all panelists’ intention to participate before submitting your
proposal.

PyOhio may record presentations for later release over the web.
Presenters will need to sign a release of recording rights to PyOhio;
see http://wiki.python.org/moin/PyOhio/RecordingRelease

All proposals should be emailed to c...@pyohio.org for review. Please
submit proposals by Friday, June 3, 2011. Accepted speakers will be
notified by June 17.

You can read more about the conference at http://pyohio.org. If you
have questions about proposals, please email c...@pyohio.org. You can
also contact the PyOhio organizers at pyohio-organiz...@python.org.

The template can be downloaded here: http://bit.ly/lJAACo [pyohio.org]

-- 
- Catherine
http://catherinedevlin.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: ElementTree XML parsing problem

2011-04-28 Thread Stefan Behnel

Hegedüs Ervin, 27.04.2011 21:33:

hello,


I'm using ElementTree to parse an XML file, but it stops at the
second record (id = 002), which contains a non-standard ascii
character, ä. Here's the XML:

?xml version=1.0?
snapshot time=Mon Apr 25 08:47:23 PDT 2011
records
record id=001 education=High School employment=7 yrs /
record id=002 education=Universität Bremen employment=3 years /
record id=003 education=River College employment=5 yrs /
/records
/snapshot

The complaint offered up by the parser is


I've checked this xml with your script, I think your locales
settings are not good.

$ ./parse.py

XML file: test.xml
001 High School
002 Universität Bremen
003 River College

(name of xml file is test.xml)

So, I started change the codepage mark of xml:

?xml version=1.0 encoding=UTF-8 ?  - same result
?xml version=1.0 encoding=ISO-8859-2 ?  - same result
?xml version=1.0 encoding=ISO-8859-1 ?  - same result


You probably changed this in an editor that supports XML and thus saves the 
file in the declared encoding. Switching between the three by simply 
changing the first line (the XML declaration) and not adapting the encoding 
of the document itself would otherwise not yield the same result for the 
document given above.


Stefan

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


Re: Access violation reading 0x00000010

2011-04-28 Thread yuan zheng
libcommon = CDLL(c:\libcommon-0.dll, RTLD_GLOBAL)

libcommon.SIM_init() - This is the invoking.




thanks,
yuanzheng.

2011/4/28 Chris Angelico ros...@gmail.com

 On Thu, Apr 28, 2011 at 1:00 PM, yuan zheng tsinghuayua...@gmail.com
 wrote:
  Hi,
  everyone. I have a question when I invoke an api which is included a
  library
  open by CDLL. And then it will prompt the follow error:

 How are you invoking it?

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

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


Re: Access violation reading 0x00000010

2011-04-28 Thread Chris Angelico
On Thu, Apr 28, 2011 at 4:01 PM, yuan zheng tsinghuayua...@gmail.com wrote:

 libcommon = CDLL(c:\libcommon-0.dll, RTLD_GLOBAL)

 libcommon.SIM_init() - This is the invoking.

When you have a backslash in a literal string, you need to double it:
libcommon = CDLL(c:\\libcommon-0.dll, RTLD_GLOBAL)

I don't know if that's your problem, but it could be!

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


Re: ElementTree XML parsing problem

2011-04-28 Thread Ervin Hegedüs
hello,

On Thu, Apr 28, 2011 at 07:57:28AM +0200, Stefan Behnel wrote:
 So, I started change the codepage mark of xml:
 
 ?xml version=1.0 encoding=UTF-8 ?  - same result
 ?xml version=1.0 encoding=ISO-8859-2 ?  - same result
 ?xml version=1.0 encoding=ISO-8859-1 ?  - same result
 
 You probably changed this in an editor that supports XML and thus
 saves the file in the declared encoding.

no. I've saved the XML as UTF8, and didn't change the _file_
encoding - just modified the XML header, nothing else...

(I'm using Geany - it doesn't realize what user wrote in file,
just can save file as another encodign, when user choose one)


 Switching between the three
 by simply changing the first line (the XML declaration) and not
 adapting the encoding of the document itself would otherwise not
 yield the same result for the document given above.

yes, that's what I wrote exactly.


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


Re: Have you read the Python docs lately?

2011-04-28 Thread Paul Rubin
Raymond Hettinger pyt...@rcn.com writes:
 A number of developers have been working on adding examples and useful
 advice to the docs.  To sharpen your skills, here are some pieces of
 recommended reading:

Thanks, those are nice.  The logging one looks especially useful.  The
module always looked very confusing to me (too Java-like), and I've
dreaded the day when I might have to figure out how to use it instead of
my own ad-hoc logging.  I can sleep better now ;-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access violation reading 0x00000010

2011-04-28 Thread yuan zheng
Sorry , the path is just an example.

This is not the question I think. Because there is lots of api
in libcommon-0.dll, and there is no fault when invoking other
api, such as libcommon.SIM_start().. It's just fault when invoking
this api - SIM_init(). So I wanna which situation would lead to this error:
--
WindowsError: exception: access violation reading 0x0010
--



thanks,
yuanzheng.


2011/4/28 Chris Angelico ros...@gmail.com

 On Thu, Apr 28, 2011 at 4:01 PM, yuan zheng tsinghuayua...@gmail.com
 wrote:
 
  libcommon = CDLL(c:\libcommon-0.dll, RTLD_GLOBAL)
 
  libcommon.SIM_init() - This is the invoking.

 When you have a backslash in a literal string, you need to double it:
 libcommon = CDLL(c:\\libcommon-0.dll, RTLD_GLOBAL)

 I don't know if that's your problem, but it could be!

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

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


Re: Have you read the Python docs lately?

2011-04-28 Thread Terry Reedy

On 4/27/2011 7:40 PM, Ben Finney wrote:

http://docs.python.org/dev/howto/logging.html


This one in particular was sorely needed, especially its early if-then
discussion of whether to use ‘logging’ at all. Thanks very much to Vinay
Sajip.


Yes, he has been working pretty steadily for some months to improve the 
tests, code, and docs.


--
Terry Jan Reedy


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


Re: Reliably call code after object no longer exists or is unreachable?

2011-04-28 Thread Gregory Ewing

Jack Bates wrote:


Python's __del__ or destructor method works (above) - but only in the
absence of reference cycles (below). An object, with a __del__ method,
in a reference cycle, causes all objects in the cycle to be
uncollectable.


Store a weak reference to the object somewhere with a
callback. This should work even in the presence of
cycles, as long as the weak reference itself isn't
part of the cycle.

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


argparse parser stores lists instead of strings

2011-04-28 Thread Andrew Berg
I've set up groups of arguments for a script I'm writing, and any time I
give an argument a value, it gets stored as a list instead of a string,
even if I explicitly tell it to store a string. Arguments declared with
other types (e.g. float, int) and default values are stored as expected.
For example:

vidin_args=parser.add_argument_group('Video Input Options', 'Various
options that control how the video file is demuxed/decoded.')
vidin_args.add_argument('-m', dest='vmode', nargs=1, type=str,
metavar='video_mode', choices=['ntsc', 'pal', 'film', 'ivtc'],
default='ntsc', help='Valid values are ntsc, pal, film and ivtc.')
...more arguments...
opts=parser.parse_args()

If I assign a value on the command line (e.g. -m pal), opts.vmode is a
list, otherwise it's a string. This is pretty bad since I can't know
whether to get opts.vmode or opts.vmode[0] later in the script. I could
loop through all the options and convert each option to a string, but
that's not really something I want to do, especially if I start adding
more options.

I'm pretty new to Python, and I might have missed something, but I have
been looking!
In case it matters, I'm learning Python 3.2 and have no intention of
using older code (once I have one version of Python covered, then I'll
look into making code that's compatible with 2.x if I have to).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unpickling derived LogRecord in python 2.7 from python2.6

2011-04-28 Thread Peter Otten
Vinay Sajip wrote:

 On Apr 27, 5:41 pm, Peter Otten __pete...@web.de wrote:
 
 The Problem is that as of Python 2.7logging.LogRecord has become a
 newstyle class which is pickled/unpickled differently. I don't know if
 there is an official way to do the conversion, but here's what I've
 hacked up. The script can read pickles written with 2.6 in 2.7, but not
 the other way round.
 [code snipped]
 
 I don't know about official, but another way of doing this is to
 pickle just the LogRecord's __dict__ and send that over the wire. The
 logging package contains a function makeLogRecord(d) where d is a
 dict.

You are right, my approach is too complicated and only needed when the OP 
cannot modify the sending script -- which is unlikely.

 This is the approach used by the examples in the library documentation
 which pickle events for sending across a network:
 
 http://docs.python.org/howto/logging-cookbook.html#sending-and-receiving-
logging-events-across-a-network
 
 The built-in SocketHandler pickles the LogRecord's __dict__ rather
 than the LogRecord itself, precisely because of the improved
 interoperability over pickling the instance directly.

As a minimal change ensuring that the logging.LogRecord subclass used by the 
OP is a newstyle class in 2.6 with

class LogRecord(logging.LogRecord, object):
#...

should work, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Access violation reading 0x00000010

2011-04-28 Thread yuan zheng
I have found my question's answer. The fault is sourced
from the implement of SIM_init().


Thanks a lot.



thanks,
yuanzheng.

2011/4/28 yuan zheng tsinghuayua...@gmail.com

 Sorry , the path is just an example.

 This is not the question I think. Because there is lots of api
 in libcommon-0.dll, and there is no fault when invoking other
 api, such as libcommon.SIM_start().. It's just fault when invoking
 this api - SIM_init(). So I wanna which situation would lead to this
 error:

 --

 WindowsError: exception: access violation reading 0x0010

 --



 thanks,
 yuanzheng.


 2011/4/28 Chris Angelico ros...@gmail.com

 On Thu, Apr 28, 2011 at 4:01 PM, yuan zheng tsinghuayua...@gmail.com
 wrote:
 
  libcommon = CDLL(c:\libcommon-0.dll, RTLD_GLOBAL)
 
  libcommon.SIM_init() - This is the invoking.

 When you have a backslash in a literal string, you need to double it:
 libcommon = CDLL(c:\\libcommon-0.dll, RTLD_GLOBAL)

 I don't know if that's your problem, but it could be!

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



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


Re: argparse parser stores lists instead of strings

2011-04-28 Thread Peter Otten
Andrew Berg wrote:

 I've set up groups of arguments for a script I'm writing, and any time I
 give an argument a value, it gets stored as a list instead of a string,
 even if I explicitly tell it to store a string. Arguments declared with
 other types (e.g. float, int) and default values are stored as expected.
 For example:
 
 vidin_args=parser.add_argument_group('Video Input Options', 'Various
 options that control how the video file is demuxed/decoded.')
 vidin_args.add_argument('-m', dest='vmode', nargs=1, type=str,
 metavar='video_mode', choices=['ntsc', 'pal', 'film', 'ivtc'],
 default='ntsc', help='Valid values are ntsc, pal, film and ivtc.')
 ...more arguments...
 opts=parser.parse_args()
 
 If I assign a value on the command line (e.g. -m pal), opts.vmode is a
 list, otherwise it's a string. This is pretty bad since I can't know
 whether to get opts.vmode or opts.vmode[0] later in the script. I could
 loop through all the options and convert each option to a string, but
 that's not really something I want to do, especially if I start adding
 more options.
 
 I'm pretty new to Python, and I might have missed something, but I have
 been looking!

http://docs.python.org/py3k/library/argparse.html#nargs


Note that nargs=1 produces a list of one item. This is different from the 
default, in which the item is produced by itself.


So just omit 'nargs=1' from the add_argument() call.

 In case it matters, I'm learning Python 3.2 and have no intention of
 using older code (once I have one version of Python covered, then I'll
 look into making code that's compatible with 2.x if I have to).

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


Re: use of index (beginner's question)

2011-04-28 Thread Iain King
On Apr 28, 2:45 am, Chris Angelico ros...@gmail.com wrote:
 Incidentally, you're allowed to put the comma on the last item too:

  lists = [
   ['pig', 'horse', 'moose'],
   ['62327', '49123', '79115'],
 ]

 Often makes for easier maintenance, especially when you append
 array/list elements.

 Chris Angelico

I did not know this.  Very useful!

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


Re: argparse parser stores lists instead of strings

2011-04-28 Thread Gabriel Genellina
En Thu, 28 Apr 2011 04:24:46 -0300, Andrew Berg  
bahamutzero8...@gmail.com escribió:



I've set up groups of arguments for a script I'm writing, and any time I
give an argument a value, it gets stored as a list instead of a string,
even if I explicitly tell it to store a string. Arguments declared with
other types (e.g. float, int) and default values are stored as expected.
For example:

vidin_args=parser.add_argument_group('Video Input Options', 'Various
options that control how the video file is demuxed/decoded.')
vidin_args.add_argument('-m', dest='vmode', nargs=1, type=str,
metavar='video_mode', choices=['ntsc', 'pal', 'film', 'ivtc'],
default='ntsc', help='Valid values are ntsc, pal, film and  
ivtc.')

...more arguments...
opts=parser.parse_args()

If I assign a value on the command line (e.g. -m pal), opts.vmode is a
list, otherwise it's a string. This is pretty bad since I can't know
whether to get opts.vmode or opts.vmode[0] later in the script. I could
loop through all the options and convert each option to a string, but
that's not really something I want to do, especially if I start adding
more options.


That's because of nargs=1. From the argparse documentation: [1]

	Note that nargs=1 produces a list of one item. This is different from the  
default, in which the item is produced by itself.


So, just remove nargs=1 from add_argument()

[1] http://docs.python.org/py3k/library/argparse.html#nargs

--
Gabriel Genellina

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


Re: Access violation reading 0x00000010

2011-04-28 Thread Gabriel Genellina
En Thu, 28 Apr 2011 03:35:48 -0300, yuan zheng tsinghuayua...@gmail.com  
escribió:



Sorry , the path is just an example.

This is not the question I think. Because there is lots of api
in libcommon-0.dll, and there is no fault when invoking other
api, such as libcommon.SIM_start().. It's just fault when invoking
this api - SIM_init(). So I wanna which situation would lead to this  
error:

--
WindowsError: exception: access violation reading 0x0010
--


On Thu, Apr 28, 2011 at 4:01 PM, yuan zheng tsinghuayua...@gmail.com
wrote:

 libcommon = CDLL(c:\libcommon-0.dll, RTLD_GLOBAL)

 libcommon.SIM_init() - This is the invoking.


It's hard to guess, but if you get an access violation just from those two  
lines of code, I'd say the problem is inside SIM_init() itself.


It may be attempting to dereference a NULL pointer: accessing a field  
inside a struct, or calling a virtual function from a NULL object...


Also, make sure CDLL is the right choice; it implies a prototype like this:

int cdecl SIM_INIT(void);

--
Gabriel Genellina

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


Spurious character in IOError exception

2011-04-28 Thread loial
When I correctly trap an IOError a spurious u' appears in the file
path in the exception message :

The path used in the code is correct i.e. /home/myfile

But the error message says :

[Errno 2] No such file or directory: u'/home/myfile'


I am simply doing

 except IOError, e:
print str(e)


Any ideas where the 'u  is coming from?

This is python 2.4.1



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


Re: How to upload a file

2011-04-28 Thread Gabriel Genellina
En Wed, 27 Apr 2011 11:14:54 -0300, Torsten Bronger  
bron...@physik.rwth-aachen.de escribió:



Hallöchen!

I'm skimming through the various recipies for uploading a file via
HTTP.  Unfortunately, all of them are awkward but also rather old.
(See for example
http://stackoverflow.com/questions/68477/send-file-using-post-from-a-python-script)

In my module, I do my HTTP request like this:

opener =  
urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))

opener.open(url, urllib.urlencode(data, doseq=True))

Well, and now I'd also like to include a file upload to the POST
data.  The solution should use urllib2, otherwise I'd have to change
most of my existing code.

If you now say Torsten, unfortunately it *is* so complicated I'll
jump through the hoops, but I'd love to hear that with Python 2.6.5
there's an easier way.  ;-)


This particular battery isn't included (yet - see  
http://bugs.python.org/issue3244)

but this little library may help:
https://bitbucket.org/chrisatlee/poster

--
Gabriel Genellina

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


Re: Spurious character in IOError exception

2011-04-28 Thread Peter Otten
loial wrote:

 When I correctly trap an IOError a spurious u' appears in the file
 path in the exception message :
 
 The path used in the code is correct i.e. /home/myfile
 
 But the error message says :
 
 [Errno 2] No such file or directory: u'/home/myfile'
 
 
 I am simply doing
 
  except IOError, e:
 print str(e)
 
 
 Any ideas where the 'u  is coming from?
 
 This is python 2.4.1

The filename does not appear directly in the error message, it is first 
converted by repr(). This ensures that

(1) the error message will consist only of ascii characters
(2) the filename can reliably reconstructed from the message

 try: open(äöü)
... except IOError, e: print e
...
[Errno 2] No such file or directory: '\xc3\xa4\xc3\xb6\xc3\xbc'

but the output may puzzle end users. The u'...' in your case means that you 
passed a unicode string to the open(...) function.

 try: open(uäöü)
... except IOError, e: print e
...
[Errno 2] No such file or directory: u'\xe4\xf6\xfc'

If you are sure that the output device supports unicode output (i. e. has a 
known encoding and can display the characters in your filename) you can 
build a friendlier message

 try: open(uäöü)
... except IOError, e: print u[Errno %d] %s: %s % (e.errno, e.strerror, 
e.filename)
...
[Errno 2] No such file or directory: äöü

Be aware though that some problems become near-impossible to detect that 
way:

 try: open(uäöü\n) # note the trailing newline
... except IOError, e: print u[Errno %d] %s: %s % (e.errno, e.strerror, 
e.filename)
...
[Errno 2] No such file or directory: äöü




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


Re: use of index (beginner's question)

2011-04-28 Thread Graeme Glass
On Apr 28, 5:32 am, Algis Kabaila akaba...@pcug.org.au wrote:
 On Thursday 28 April 2011 11:23:51 Thomas 'PointedEars' Lahn
 wrote: Chris Angelico wrote:
   Rusty Scalf wrote:
   list1 = ['pig', 'horse', 'moose']
   list2 =  ['62327', '49123', '79115']
   n = 2
   s2 = list + `n`
  list + 'n'
 'listn'

 And IMHO you did not want that, did you?

 OldAl.
 --
 Algishttp://akabaila.pcug.org.au/StructuralAnalysis.pdf

It will not be 'listn' it will be 'list2'. He is using back ticks `
which translates the n into its value 2.
Granted it is not very readable (as it can easily be mistaken for a
single quote depending on the font your using). It would be better
written as 'list%s' %n
-- 
http://mail.python.org/mailman/listinfo/python-list


Need your help

2011-04-28 Thread 1011_wxy
Hi friends:

Here I need some help.

#encoding=utf-8
#moudle a.py
def a():
print  function a!

#encoding=utf-8
#moudle b.py
def b():
print  function b!


#encoding=utf-8
#moudle c.py
import a
import b
def c():
a.a()
b.b()


Here in function c,How can i record all the information printed by a and b with 
out modifying moudle a and b?
I want to output all the printed information into a text file.

Need your help, thanks a lot!

Best Regards

2011-04-28



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


Re: Need your help

2011-04-28 Thread Chris Rebert
On Wed, Apr 27, 2011 at 10:38 PM, 1011_wxy 1011_...@163.com wrote:
 Hi friends:

 Here I need some help.

 #encoding=utf-8
 #moudle a.py
 def a():
     print  function a!

 #encoding=utf-8
 #moudle b.py
 def b():
     print  function b!


 #encoding=utf-8
 #moudle c.py
 import a
 import b
 def c():
 a.a()
 b.b()


 Here in function c,How can i record all the information printed by a and b
 with out modifying moudle a and b?
 I want to output all the printed information into a text file.

 Need your help, thanks a lot!

import a, b, sys
def c():
orig_stdout = sys.stdout
sys.stdout = open('my_log_file.log', 'w')
a.a()
b.b()
sys.stdout.close()
sys.stdout = orig_stdout


Someone may have written a with-statement context manager that
abstracts away the swapping.

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


Re: Need your help

2011-04-28 Thread Ervin Hegedüs
hello,

 Here I need some help.
 
 #encoding=utf-8
 #moudle a.py
 def a():
 print  function a!
 
 #encoding=utf-8
 #moudle b.py
 def b():
 print  function b!
 
 
 #encoding=utf-8
 #moudle c.py
 import a
 import b
 def c():
 a.a()
 b.b()
 
 
 Here in function c,How can i record all the information printed by a and b 
 with out modifying moudle a and b?
 I want to output all the printed information into a text file.
 
 Need your help, thanks a lot!

sounds you want something like this:

#!/usr/bin/python

import a
import b

import sys
import StringIO

output = StringIO.StringIO()

def c():
# save default stdout
tout = sys.stdout
# redirect stdout to StringIO object
sys.stdout = output
# a.a() prints their output to StringIO object
a.a()
# back up default stdout
sys.stdout = tout
# print StringIO object value
print retval:, output.getvalue()

c()



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


Re: Need your help

2011-04-28 Thread Ervin Hegedüs
hello,

On Thu, Apr 28, 2011 at 01:20:16PM +0200, Ervin Hegedüs wrote:
 #!/usr/bin/python
 
 import a
 import b
 
 import sys
 import StringIO
 
 output = StringIO.StringIO()
 
 def c():
 # save default stdout
 tout = sys.stdout
 # redirect stdout to StringIO object
 sys.stdout = output
 # a.a() prints their output to StringIO object
 a.a()
 # back up default stdout
 sys.stdout = tout
 # print StringIO object value
 print retval:, output.getvalue()
 
 c()

sorry,

this is a littlebit more abstact example, it gives a StringIO
object, instead of write to a file - of course, you can do what
you want with that string...


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


Re: Need your help

2011-04-28 Thread Jean-Michel Pichavant

1011_wxy wrote:

Hi friends:
 
Here I need some help.
 
#encoding=utf-8

#moudle a.py
def a():
print  function a!
 
#encoding=utf-8

#moudle b.py
def b():
print  function b!
 
 
#encoding=utf-8

#moudle c.py
import a
import b
def c():
a.a()
b.b()
 
 
Here in function c,How can i record all the information printed by a 
and b with out modifying moudle a and b?

I want to output all the printed information into a text file.
 
Need your help, thanks a lot!
 
Best Regards
 
2011-04-28


Kerry Wang

Hi,

python c.py  afile.log


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


High respected career - Careers in next month

2011-04-28 Thread gaurav
Potential income in Management careers.
Work in Management careers.
Visit: http://managementjobs.webs.com/index.htm 
http://jobscore.webs.com/executivemanager.htm

Careers for Management - Careers in next month
http://employmentsmanagement.blogspot.com/ http://rojgars1.webs.com/gov.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


回复: Re: Need your help

2011-04-28 Thread 1011_wxy
Hi JM:

python c.py  afile.log 


could you pls give me the whole example?
I am so sorry that I am a beginner in Python.


2011-04-28



1011_wxy



发件人: Jean-Michel Pichavant jeanmic...@sequans.com
发送时间: 2011-04-28 20:42
主 题: Re: Need your help
收件人: 1011_wxy 1011_...@163.com
抄 送: python-list@python.org python-list@python.org





1011_wxy wrote: 
 Hi friends: 
   
 Here I need some help. 
   
 #encoding=utf-8 
 #moudle a.py 
 def a(): 
 print  function a! 
   
 #encoding=utf-8 
 #moudle b.py 
 def b(): 
 print  function b! 
   
   
 #encoding=utf-8 
 #moudle c.py 
 import a 
 import b 
 def c(): 
 a.a() 
 b.b() 
   
   
 Here in function c,How can i record all the information printed by a  
 and b with out modifying moudle a and b? 
 I want to output all the printed information into a text file. 
   
 Need your help, thanks a lot! 
   
 Best Regards 
   
 2011-04-28 
  
 Kerry Wang 
Hi, 

python c.py  afile.log 


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


Re: 回复: Re: Need your help

2011-04-28 Thread Jean-Michel Pichavant

1011_wxy wrote:

Hi JM:
 
*python c.py  afile.log* 
 
 
could you pls give me the whole example?

I am so sorry that I am a beginner in Python.


Your module a and  b that you cannot modify given your original 
description, are printing data using the print statement.
That means these module only intend to print the data on the standard 
output (aka stdout, your screen by default).


If you want to print the data in a file, then you have to make stdout 
that file. 2 possible way have been provided:


1/ within the c.py file, redirect sys.stdout to a file (see Chris 
Rebert's answer)
2/ use the system command line to redirect stdout to a file. In any unix 
system, you can redirect stdout to a file( instead of the screen) that way:


   echo Hello world  afile.txt

It works for any command, including

   python c.py  afile.txt


That will execute you c.py file writing everything into afile.txt 
instead of your display.


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


Re: Need your help

2011-04-28 Thread Thomas Rachel

Am 28.04.2011 13:14, schrieb Chris Rebert:


import a, b, sys
def c():
 orig_stdout = sys.stdout
 sys.stdout = open('my_log_file.log', 'w')
 a.a()
 b.b()
 sys.stdout.close()
 sys.stdout = orig_stdout


Someone may have written a with-statement context manager that
abstracts away the swapping.


@contextlib.contextmanager
def swap_stdout(target):
orig_stdout = sys.stdout
sys.stdout = target
try:
yield target
finally:
sys.stdout = orig_stdout

In this case, I can use all kinds of files (open() files, StringIO 
objects etc.), and can re-use them if necessary, in order to 
prepend/append data.


Closing can happen additionally, if the user wants.


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


Read-write lock for Python

2011-04-28 Thread Geoff Bache
Hi all,

I currently find myself needing a Python read-write lock. I note that
there is none in the standard library, but googling python read-write
lock quickly produced 6 different competing examples, including two
languishing patch proposals for the standard library.

I can always pick a random one and hope for the best, but I was hoping
someone here might have a tip for one that has been used and debugged
and is likely to work.

Regards,
Geoff Bache
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Jean-Michel Pichavant

Geoff Bache wrote:

Hi all,

I currently find myself needing a Python read-write lock. I note that
there is none in the standard library, but googling python read-write
lock quickly produced 6 different competing examples, including two
languishing patch proposals for the standard library.

I can always pick a random one and hope for the best, but I was hoping
someone here might have a tip for one that has been used and debugged
and is likely to work.

Regards,
Geoff Bache
  

What about

http://docs.python.org/library/threading.html#lock-objects

?

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


Re: Python IDE/text-editor

2011-04-28 Thread Albert van der Horst
In article mailman.511.1303137613.9059.python-l...@python.org,
Alec Taylor  alec.tayl...@gmail.com wrote:
Geany I've tried in the past, it's really buggy on my home computer
and at Uni... however from my phone it works wonderfully! (Use it for
C++ projects on Rhobuntu)

Eric 4 was suggested to me on the #python channel on Freenode...
however I've never been able to get it compiled/working. Too many
dependencies I'm guessing...

PTK looks great, and does everything I want (from screenshots).
Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1
x64, WxPython 2.8 x64. Install ran as admin.

Emacs and vim still seem like good alternatives, when I get the time.
However, currently have 3 assignments to start and finish so would
like a simple Notepad2 with python interpreter attached (and keyboard
shortcut to run script) type program.

Please continue recommending

Thanks,

Alec Taylor

You will never be satisfied, until you've written something yourself.
Start writing now. A friend of mine started writing in 1983,
and since 1985 I'm a happy user. The only language that is a candidate
to write in is C, however.

Groetjes Albert

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

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


Re: Equivalent code to the bool() built-in function

2011-04-28 Thread Albert van der Horst
In article iok5tg$svv$1...@reader1.panix.com,
Grant Edwards  invalid@invalid.invalid wrote:

On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes li...@cheimes.de wrote:
 Am 18.04.2011 21:58, schrieb John Nagle:
 ?? ?? This is typical for languages which backed into a bool type,
 rather than having one designed in. ??The usual result is a boolean
 type with numerical semantics, like

 ?? True + True
 2

 I find the behavior rather useful. It allows multi-xor tests like:

 if a + b + c + d != 1:
 ?? ??raise ValueError(Exactly one of a, b, c or d must be true.)

I guess I never thought about it, but there isn't an 'xor' operator to
go along with 'or' and 'and'.  Must not be something I need very often.

There is.  applied to booleans is xor.


--
Grant Edwards   grant.b.edwardsYow! I am having FUN...
  at   I wonder if it's NET FUN or
  gmail.comGROSS FUN?


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

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


Re: Equivalent code to the bool() built-in function

2011-04-28 Thread Albert van der Horst
In article 9142usf51...@mid.individual.net,
Gregory Ewing  greg.ew...@canterbury.ac.nz wrote:
Chris Angelico wrote:

 Remind me some day to finish work on my ultimate programming
 language, which starts out with a clean slate and lets the programmer
 define his own operators and everything.

Didn't someone already do that and call it lisp? :-)

Lisp is betrayed by its brackets. He wants Forth.


--
Greg

Groetjes Albert

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

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


socket.gethostbyaddr() wrongly returning a DNS CNAME as the 'primary' hostname

2011-04-28 Thread cjblaine
Python 2.7.1 (perhaps others)

I believe this is a bug.  Comments?

Docs state: Return a triple (hostname, aliaslist, ipaddrlist)
where hostname is the primary host name responding to the
given ip_address, aliaslist is a (possibly empty) list of
alternative host names  for the same address, and ipaddrlist
is a list of IPv4/v6 addresses for the same interface on the
same host (most likely containing only a single address).

my-dns-cname.our.org is a CNAME record for primary.our.org
primary.our.org has IP address xx.xx.xx.xx

import socket
socket.gethostbyaddr('xx.xx.xx.xx')

returns:

('my-dns-cname.our.org', ['primary.our.org'], ['xx.xx.xx.xx'])
-- 
http://mail.python.org/mailman/listinfo/python-list


NaN

2011-04-28 Thread Eric Snow
There's a big discussion going on at python-dev and python-ideas about NaN
(not-a-number, from IEEE 754).  I haven't really gotten into any scientific
computing or numeric programming so I have never knowingly dealt with NaN.
 However, I have read the discussions and several things are not clear:

1. Why is NaN not an exception?  (not why not change it to one?  Changing
it now would probably break stuff.)
2. What are the use cases for NaN?  Looks like it gets used a lot as a
numeric (float?) object with non-value.

Any clarification would be really helpful.  Thanks!

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


IDLE lost from Windows menu !

2011-04-28 Thread Uncle Ben
I have lost the convenient feature that to edit a .py file I could
right-click on the file name and reach the menu item Edit with IDLE.

The workaround is not hard, but it wouild be nice to get this feature
back.

It happened when I was mungeing around and downloaded Python 2.3.3 in
addition to Python 2.71, and got into trojuble uintil I discovered
that I was involuntarily RUNNING the older version.  So I cleaned it
out, but still I have this aftermath.

Is there a Windows guru out there who can tell be how to add to the
right-click menu clicking on myfile.py?

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


multiprocessing: file-like object

2011-04-28 Thread buck
I've been having issues with getting a file-like object to work with 
multiprocessing. Since the details are quite lengthy, I've posted them on 
stackoverflow here: 
http://stackoverflow.com/questions/5821880/python-multiprocessing-synchronizing-file-like-object

I hope I'm not being super rude by cross-posting, but I thought some of you 
would be interested in the question, and I'd be delighted to get some ideas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Have you read the Python docs lately?

2011-04-28 Thread Raymond Hettinger
On Apr 27, 11:28 pm, Paul Rubin no.em...@nospam.invalid wrote:
 Raymond Hettinger pyt...@rcn.com writes:
  A number of developers have been working on adding examples and useful
  advice to the docs.  To sharpen your skills, here are some pieces of
  recommended reading:

 Thanks, those are nice.  The logging one looks especially useful.  The
 module always looked very confusing to me (too Java-like), and I've
 dreaded the day when I might have to figure out how to use it instead of
 my own ad-hoc logging.  I can sleep better now ;-).

Vinay put also put together a logging cookbook:

   http://docs.python.org/howto/logging-cookbook.html


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


Re: Equivalent code to the bool() built-in function

2011-04-28 Thread buck
I'm not not touching you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NaN

2011-04-28 Thread Chris Rebert
On Thu, Apr 28, 2011 at 9:21 AM, Eric Snow ericsnowcurren...@gmail.com wrote:
 There's a big discussion going on at python-dev and python-ideas about NaN
 (not-a-number, from IEEE 754).  I haven't really gotten into any scientific
 computing or numeric programming so I have never knowingly dealt with NaN.
  However, I have read the discussions and several things are not clear:
 1. Why is NaN not an exception?  (not why not change it to one?  Changing
 it now would probably break stuff.)

Most things that would produce NaN [e.g. x/0, sqrt(-abs(x))] in
lower-level languages do produce exceptions in Python. If you
encounter a NaN in Python, it was probably either explicitly created
or came from a C extension library. It's basically an abstraction
leaked through from C/hardware for compatibility.

 2. What are the use cases for NaN?  Looks like it gets used a lot as a
 numeric (float?) object with non-value.

FWICT, it's useful in lower-level languages (which typically lack
exceptions and often lack nice ways of returning multiple values from
a function) as a convenient way of signaling a mathematical error. It
also lets some calculations continue to limp along (albeit with a NaN
result) after an error rather than forcing the probably slower
explicit handling of the error at the time of its occurrence. And it's
used to represent missing numeric data values, sort of like a
numerical None/Null: How much does the truck weigh? NaN (i.e. No
idea; we haven't put it on the scale yet).

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


Composition instead of inheritance

2011-04-28 Thread Ethan Furman
For anybody interested in composition instead of multiple inheritance, I 
have posted this recipe on ActiveState (for python 2.6/7, not 3.x):


http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

Comments welcome!

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


Re: Python IDE/text-editor

2011-04-28 Thread Alec Taylor
Your probably right.

I suppose I'll just wait till I finish my fooIDE project

 On Fri, Apr 29, 2011 at 2:21 AM, Albert van der Horst
 alb...@spenarnc.xs4all.nl wrote:
 In article mailman.511.1303137613.9059.python-l...@python.org,
 Alec Taylor  alec.tayl...@gmail.com wrote:
Geany I've tried in the past, it's really buggy on my home computer
and at Uni... however from my phone it works wonderfully! (Use it for
C++ projects on Rhobuntu)

Eric 4 was suggested to me on the #python channel on Freenode...
however I've never been able to get it compiled/working. Too many
dependencies I'm guessing...

PTK looks great, and does everything I want (from screenshots).
Unfortunately, it doesn't run on my system; Win7 x64, Python 2.7.1
x64, WxPython 2.8 x64. Install ran as admin.

Emacs and vim still seem like good alternatives, when I get the time.
However, currently have 3 assignments to start and finish so would
like a simple Notepad2 with python interpreter attached (and keyboard
shortcut to run script) type program.

Please continue recommending

Thanks,

Alec Taylor

 You will never be satisfied, until you've written something yourself.
 Start writing now. A friend of mine started writing in 1983,
 and since 1985 I'm a happy user. The only language that is a candidate
 to write in is C, however.

 Groetjes Albert

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

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


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


Re: use of index (beginner's question) (Iain King)

2011-04-28 Thread Apprentice3D


Envoyé de mon iPad

Le 2011-04-28 à 4:55, python-list-requ...@python.org a écrit :

 Send Python-list mailing list submissions to
python-list@python.org
 
 To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
 or, via email, send a message with subject or body 'help' to
python-list-requ...@python.org
 
 You can reach the person managing the list at
python-list-ow...@python.org
 
 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Python-list digest...
 Today's Topics:
 
   1. Re: Have you read the Python docs lately? (Terry Reedy)
   2. Re: Reliably call code after object no longer exists or is
  unreachable? (Gregory Ewing)
   3. argparse parser stores lists instead of strings (Andrew Berg)
   4. Re: unpickling derived LogRecord in python 2.7 from python2.6
  (Peter Otten)
   5. Re: Access violation reading 0x0010 (yuan zheng)
   6. Re: argparse parser stores lists instead of strings (Peter Otten)
   7. Re: use of index (beginner's question) (Iain King)
   8. Re: argparse parser stores lists instead of strings
  (Gabriel Genellina)
   9. Re: Access violation reading 0x0010 (Gabriel Genellina)
  10. Spurious character in IOError exception (loial)
 
 
 
 
 Ce message ne peut être affiché à cause de son format. Veuillez demander à 
 l’expéditeur de le renvoyer en utilisant un autre format ou un autre logiciel 
 de courrier. multipart/alternative
 
 
 
 
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Geoff Bache
On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:
 Geoff Bache wrote:

 Hi all,

 I currently find myself needing a Python read-write lock. I note that
 there is none in the standard library, but googling python read-write
 lock quickly produced 6 different competing examples, including two
 languishing patch proposals for the standard library.

 I can always pick a random one and hope for the best, but I was hoping
 someone here might have a tip for one that has been used and debugged
 and is likely to work.

 Regards,
 Geoff Bache


 What about

 http://docs.python.org/library/threading.html#lock-objects

Those aren't read-write locks. They are basic locks, which don't
distinguish between readers and writers. I need to be able to lock
between reader and writer operations, without readers locking each
other out.

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


Re: Equivalent code to the bool() built-in function

2011-04-28 Thread Duncan Booth
Albert van der Horst alb...@spenarnc.xs4all.nl wrote:

I guess I never thought about it, but there isn't an 'xor' operator to
go along with 'or' and 'and'.  Must not be something I need very often.
 
 There is.  applied to booleans is xor.
 
Best to get into the habit of using '!=' otherwise you'll find Python 3.x a 
bit frustrating.

However, that only works if you have exactly two values: both 'and' and 
'or' will extend easily to any number of values:

  True and False and True
 False
  False or False or True or False
 True

but using != for 'xor' doesn't extend the same way:

  False != False != True
 False

You can use 'sum(...)==1' for a larger number of values but do have to be 
careful that all of them are bools (or 0|1).

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NaN

2011-04-28 Thread Eric Snow
On Thu, Apr 28, 2011 at 11:01 AM, Chris Rebert c...@rebertia.com wrote:

 On Thu, Apr 28, 2011 at 9:21 AM, Eric Snow ericsnowcurren...@gmail.com
 wrote:
  There's a big discussion going on at python-dev and python-ideas about
 NaN
  (not-a-number, from IEEE 754).  I haven't really gotten into any
 scientific
  computing or numeric programming so I have never knowingly dealt with
 NaN.
   However, I have read the discussions and several things are not clear:
  1. Why is NaN not an exception?  (not why not change it to one?
  Changing
  it now would probably break stuff.)

 Most things that would produce NaN [e.g. x/0, sqrt(-abs(x))] in
 lower-level languages do produce exceptions in Python. If you
 encounter a NaN in Python, it was probably either explicitly created
 or came from a C extension library. It's basically an abstraction
 leaked through from C/hardware for compatibility.

  2. What are the use cases for NaN?  Looks like it gets used a lot as a
  numeric (float?) object with non-value.

 FWICT, it's useful in lower-level languages (which typically lack
 exceptions and often lack nice ways of returning multiple values from
 a function) as a convenient way of signaling a mathematical error. It
 also lets some calculations continue to limp along (albeit with a NaN
 result) after an error rather than forcing the probably slower
 explicit handling of the error at the time of its occurrence. And it's
 used to represent missing numeric data values, sort of like a
 numerical None/Null: How much does the truck weigh? NaN (i.e. No
 idea; we haven't put it on the scale yet).


Thanks Chris.  That's really helpful.  Sounds like NaN is a pretty
overloaded object.  Nick Coghlan brought up in the issue tracker that it is
useful for prototyping algorithms that will be converted to C.  Other than
that, why should Python care?  We have None.  Is it for performance (since
None acts like a number in some ways, but NaN acts like it better)?

Is the problem less with NaN (number object with an undefined value) and
more with the broken reflexivity with regards to equality in general (x is
x doesn't imply that x == x)?  Looks like that situation breaks a number
of different operations in Python, whether or not NaN is involved.

This stuff is way outside my realm of experience so I don't want to wade
into the core lists with these questions, but I want to understand the
issues too...

-eric


 Cheers,
 Chris
 --
 http://rebertia.com

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


Python 3.2 Tkinter and TTK

2011-04-28 Thread steven.oldner
Just downloaded Python3.2 from python's site and attempted to run some
of the examples in the 24.2.10Tk Styling.  The button worked, but the
menu didn't.  I also tried a couple from the TKDocs web site.  Only
errors from there.

So, what do I need to do to get it to run?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Eric Snow
On Thu, Apr 28, 2011 at 11:15 AM, Ethan Furman et...@stoneleaf.us wrote:

 For anybody interested in composition instead of multiple inheritance, I
 have posted this recipe on ActiveState (for python 2.6/7, not 3.x):


 http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

 Comments welcome!

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


That's cool.  And if Spam and Eggs were abstract base classes you could
register TestAll to them.  Granted, that is not so applicable in your
example.   But generally that would help bridge the inheritance gap for
isinstance cases.

-eric

p.s. I would have commented on the recipe but could not log in...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread D'Arcy J.M. Cain
On Thu, 28 Apr 2011 19:14:45 +0200
Geoff Bache geoff.ba...@gmail.com wrote:
 On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
 jeanmic...@sequans.com wrote:
  What about
 
  http://docs.python.org/library/threading.html#lock-objects
 
 Those aren't read-write locks. They are basic locks, which don't
 distinguish between readers and writers. I need to be able to lock
 between reader and writer operations, without readers locking each
 other out.

There really isn't any such thing as read-write locks.  In fact, the
term locks without any further explanation is pretty loose in any
case.  You can use the above method to implement your own locking
scheme.  However, that only works if your application is a single,
multi-threaded app.  Is that the case?  When I saw your original
question I thought that you needed something inter-process.  If so then
you need another scheme.

I think you have to first clarify your requirements and ask again.  I
have gleaned a little more information from your above response, you
don't require readers to be locked out during an update if I understand
the requirement.  There is still a lot of information missing.  For
example:

 - What is being read and written?  Files?
 - Is this a single multi-threaded app or multiple processes?
 - if multiple processes, can they be counted on to cooperate?
 - Do update requests need to be queued or is random availability OK?

Now, don't just answer the above questions. Try to start with that and
think about what other requirements you have.  The more information you
give us, the better the answer will be.  You may even find that locking
is not the actual answer you need.  People do have a tendency to offer
solutions when they think they are asking questions.  Don't pre-suppose
the answer.

http://www.catb.org/~esr/faqs/smart-questions.html is always a good
read in these situations.

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I think I found a mistake in the official language reference documentation -- or I am missing somethig???

2011-04-28 Thread Igor Soares
On 27 abr, 21:29, MRAB pyt...@mrabarnett.plus.com wrote:
 On 27/04/2011 21:02, Igor Soares wrote:









  Reading the section 6.11. The import statement
 http://docs.python.org/py3k/reference/simple_stmts.html#the-import-st...

  I found:
  
  Import statements are executed in two steps: (1) find a module, and
  initialize it if necessary; (2) define a name or names in the local
  namespace (of the scope where the import statement occurs).
  (...)
  The first form (without from) repeats these steps for each identifier
  in the list. The form with from performs step (1) once, and then
  performs step (2) repeatedly.
  
  In the last sentence, isn't it the opposite?
  With the from form it would find/initialize all the modules and
  define just the name after from.
  Or am I missing something?

 The from form is like:

      from monty import spam, eggs

 The steps are:

 1. find module monty, and initialize it if necessary

 2. define name spam in the local namespace

 3. define name eggs in the local namespace

 Also note that the name monty itself never enters the local namespace.

My mistake...
I got confused with wrong code in IDLE...
I also didn't understand that section ( 6.11 ) at first

Thank you guys for the help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Jean-Michel Pichavant

Ethan Furman wrote:
For anybody interested in composition instead of multiple inheritance, 
I have posted this recipe on ActiveState (for python 2.6/7, not 3.x):


http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/ 



Comments welcome!

~Ethan~

Sounds great. But I fear that would completely fool any linter.

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


Re: NaN

2011-04-28 Thread Steven D'Aprano
On Thu, 28 Apr 2011 10:01:49 -0700, Chris Rebert wrote:

  2. What are the use cases for NaN?  Looks like it gets used a lot as a
  numeric (float?) object with non-value.
 
[...]
 And it's
 used to represent missing numeric data values, sort of like a
 numerical None/Null: How much does the truck weigh? NaN (i.e. No
 idea; we haven't put it on the scale yet).

While it is common, it is also an abuse of NANs to use it to represent 
missing values. In Python, that's (probably) best done with None. The 
statistics language R has a specific value NA to use for missing, 
distinct from NANs.

Still, it could be worse... I've seen a programs use  to represent 
missing values, on the basis that nobody could ever have more than (say) 
5000 invoices in the database... 

(I wish I was exaggerating.)


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


Re: IDLE lost from Windows menu !

2011-04-28 Thread Uncle Ben
On Apr 28, 12:28 pm, Uncle Ben b...@greenba.com wrote:
 I have lost the convenient feature that to edit a .py file I could
 right-click on the file name and reach the menu item Edit with IDLE.

 The workaround is not hard, but it wouild be nice to get this feature
 back.

 It happened when I was mungeing around and downloaded Python 2.3.3 in
 addition to Python 2.7.1, and got into trouble until I discovered
 that I was involuntarily RUNNING the older version.  So I cleaned it
 out, but still I have this aftermath.

 Is there a Windows guru out there who can tell be how to add to the
 right-click menu clicking on myfile.py?

 Uncle Ben

It was suggested to me privately that I search for
HKEY_CLASSES_ROOT\*\shell,
right_click on shell,
create a new key called EDIT with IDLE
and another called command python.exe %1

Problem:
  Searching on the HKEY group as above yields no shell.

Did I not do it right, or is there another way?

(I would think that that command would execute my file, not edit it.
But maybe I will be surprised.)

(I am running Windows 7, 64-bit.)

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


Re: IDLE lost from Windows menu !

2011-04-28 Thread MRAB

On 28/04/2011 20:11, Uncle Ben wrote:

On Apr 28, 12:28 pm, Uncle Benb...@greenba.com  wrote:

I have lost the convenient feature that to edit a .py file I could
right-click on the file name and reach the menu item Edit with IDLE.

The workaround is not hard, but it wouild be nice to get this feature
back.

It happened when I was mungeing around and downloaded Python 2.3.3 in
addition to Python 2.7.1, and got into trouble until I discovered
that I was involuntarily RUNNING the older version.  So I cleaned it
out, but still I have this aftermath.

Is there a Windows guru out there who can tell be how to add to the
right-click menu clicking on myfile.py?

Uncle Ben


It was suggested to me privately that I search for
HKEY_CLASSES_ROOT\*\shell,
right_click on shell,
create a new key called EDIT with IDLE
and another called command python.exe %1

Problem:
   Searching on the HKEY group as above yields no shell.

Did I not do it right, or is there another way?

(I would think that that command would execute my file, not edit it.
But maybe I will be surprised.)

(I am running Windows 7, 64-bit.)


Probably the simplest solution would be to install the appropriate
version of Python again.
--
http://mail.python.org/mailman/listinfo/python-list


Re: socket.gethostbyaddr() wrongly returning a DNS CNAME as the 'primary' hostname

2011-04-28 Thread Ned Deily
In article 
850c85c0-be6e-4eec-b6b1-5c79e1716...@glegroupsg2000goo.googlegroups.com
, cjblaine cjbla...@gmail.com wrote:
 Python 2.7.1 (perhaps others)
 
 I believe this is a bug.  Comments?
 
 Docs state: Return a triple (hostname, aliaslist, ipaddrlist)
 where hostname is the primary host name responding to the
 given ip_address, aliaslist is a (possibly empty) list of
 alternative host names  for the same address, and ipaddrlist
 is a list of IPv4/v6 addresses for the same interface on the
 same host (most likely containing only a single address).
 
 my-dns-cname.our.org is a CNAME record for primary.our.org
 primary.our.org has IP address xx.xx.xx.xx
 
 import socket
 socket.gethostbyaddr('xx.xx.xx.xx')
 
 returns:
 
 ('my-dns-cname.our.org', ['primary.our.org'], ['xx.xx.xx.xx'])

socket.gethostbyaddr() is pretty much just a transparent wrapper around 
the platform's C library function of the same name.  See if a simple C 
program with a similar call to gethostbyaddr produces the same results.  
The code in question for Python 2.7 is here:

http://hg.python.org/cpython/file/a6b772599594/Modules/socketmodule.c

-- 
 Ned Deily,
 n...@acm.org

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


Zope with mySQL

2011-04-28 Thread harryjatt

Hi, i am doing web development with Zope. My connected database is mySQL. I
am new to this combination.I have to upload the files to mySQL with
programming in zope and then downloading them via zope.Can you help me in
this regard? I will be very thankfull to you.
Regards, Harry
-- 
View this message in context: 
http://old.nabble.com/Zope-with-mySQL-tp31499628p31499628.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Where to start in writing test programs for electronics

2011-04-28 Thread Manatee
I would like to write test programs that will collect data over the
serial port, control instruments, plot data as its collected, and save
that data to a file. I have partially figured out instrument control
and have downloaded numpy and matplot. I am having trouble pulling it
together as regards feeding realtime data into matplot. I am reading
as much as I can in all areas and I'm hoping someone can give me some
guidance or tips as to how best to proceed with this. Thanks in
advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Have you read the Python docs lately?

2011-04-28 Thread Vinay Sajip
On Apr 28, 12:40 am, Ben Finney ben+pyt...@benfinney.id.au wrote:

 This one in particular was sorely needed, especially its early if-then
 discussion of whether to use ‘logging’ at all.

For that when to use logging part, you can thank Nick Coghlan :-)

Thanks are also due to all those who commented on early drafts, which
were put together initially for the 3.2 release. If anyone has any
other improvements to suggest, keep 'em coming!

Regards,

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


Re: socket.gethostbyaddr() wrongly returning a DNS CNAME as the 'primary' hostname

2011-04-28 Thread cjblaine
Thanks for the reply, Ned.

Bummer for me.  Check this out:

C code on Solaris 10 SPARC returns the following with nscd
running (the Solaris Naming Services Caching Daemon, on by
default):

  PRIMARY according to gethostbyaddr(): my-dns-cname.our.org
  ALIAS according to gethostbyaddr(): primary.our.org

  However, I can stop/start nscd and get the complete opposite
  (correct) result.

C code on Solaris 10 SPARC returns the following with nscd
OFF:

  PRIMARY according to gethostbyaddr(): my-dns-cname.our.org
  ALIAS according to gethostbyaddr(): primary.our.org

  These then ALTERNATE consistently with every successive
  invocation of my code.

C code on Linux 2.6 with glibc 2.5 returns:

  PRIMARY according to gethostbyaddr(): primary.our.org
  [ no aliases get listed ]

Time to query the corporate DNS folks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 Tkinter and TTK

2011-04-28 Thread Jayme Proni Filho
Man,

If you want to programm GUI's it is better for you learn Qt or GTK. They are
so much better than tkinter.
I told this with sadness because I like free things, but the reality is not
like this. This libs are in all places.

---
Jayme Proni Filho
Skype: jaymeproni
Twitter: @jaymeproni
Phone: +55 - 17 - 3631 - 6576
Mobile: +55 - 17 - 9605 - 3560
e-Mail: jaymeproni at yahoo dot com dot br
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deditor

2011-04-28 Thread Kruptein
On 28 apr, 07:46, jmfauth wxjmfa...@gmail.com wrote:
 On 27 avr, 19:22, Alec Taylor alec.tayl...@gmail.com wrote:

  Thanks, any plans for a Windows version?

 - Download the deb
 - Unpack it with a utility like 7zip
 - Throw away the unnecessary stuff, (keep the deditor part)
 - Depending on your libs, adatpt the import
 - Launch deditor.py
 - Then ...

 [5 minutes]

 In fact, this kind of app can be simply packed in a zip file.

 jmf

It isn't that easy as you might have hoped ;)  I'm using wxpython for
rendering the GUI  somehow some things that work in the linux version
break in the windows version  so I need to do some small
modifications  and as I'm a hardcore linux fan I ony use windows for
gaming it usually takes a little longer for a windows release,  I'm
releasing a tarball now btw :D
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE lost from Windows menu !

2011-04-28 Thread Uncle Ben
On Apr 28, 3:29 pm, MRAB pyt...@mrabarnett.plus.com wrote:
 On 28/04/2011 20:11, Uncle Ben wrote:



  On Apr 28, 12:28 pm, Uncle Benb...@greenba.com  wrote:
  I have lost the convenient feature that to edit a .py file I could
  right-click on the file name and reach the menu item Edit with IDLE.

  The workaround is not hard, but it wouild be nice to get this feature
  back.

  It happened when I was mungeing around and downloaded Python 2.3.3 in
  addition to Python 2.7.1, and got into trouble until I discovered
  that I was involuntarily RUNNING the older version.  So I cleaned it
  out, but still I have this aftermath.

  Is there a Windows guru out there who can tell be how to add to the
  right-click menu clicking on myfile.py?

  Uncle Ben

  It was suggested to me privately that I search for
  HKEY_CLASSES_ROOT\*\shell,
  right_click on shell,
  create a new key called EDIT with IDLE
  and another called command python.exe %1

  Problem:
     Searching on the HKEY group as above yields no shell.

  Did I not do it right, or is there another way?

  (I would think that that command would execute my file, not edit it.
  But maybe I will be surprised.)

  (I am running Windows 7, 64-bit.)

 Probably the simplest solution would be to install the appropriate
 version of Python again.- Hide quoted text -

 - Show quoted text -

Tried that.  No change.  Strange things are happening!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-write lock for Python

2011-04-28 Thread Geoff Bache
On Thu, Apr 28, 2011 at 7:53 PM, D'Arcy J.M. Cain da...@druid.net wrote:
 On Thu, 28 Apr 2011 19:14:45 +0200
 Geoff Bache geoff.ba...@gmail.com wrote:
 On Thu, Apr 28, 2011 at 4:28 PM, Jean-Michel Pichavant
 jeanmic...@sequans.com wrote:
  What about
 
  http://docs.python.org/library/threading.html#lock-objects

 Those aren't read-write locks. They are basic locks, which don't
 distinguish between readers and writers. I need to be able to lock
 between reader and writer operations, without readers locking each
 other out.

 There really isn't any such thing as read-write locks.

Did you google it? I even provided the exact search terms to use in my
initial posting. It takes you straight to two standard library patch
proposals and four other solutions, all labelled this way (sometimes
reader-writer locks admittedly). That doesn't happen if it isn't a
standard problem.

I'm not looking for general advice on how to solve some specific
problem. I'm asking if anyone knows anything about the relative merits
of the above 6 solutions.

Regards,
Geoff Bache
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NaN

2011-04-28 Thread Grant Edwards
On 2011-04-28, Chris Rebert c...@rebertia.com wrote:

 2. What are the use cases for NaN?  Looks like it gets used a lot as a
 numeric (float?) object with non-value.

 FWICT, it's useful in lower-level languages (which typically lack
 exceptions and often lack nice ways of returning multiple values from
 a function) as a convenient way of signaling a mathematical error.

When doing stuff involving process control systems, I found it very
useful to use NaN to indicate unknown/invalid.  It propogates
properly through calculations so that when you have an invalid input,
all of the outputs that depend on it also go invalid.

The other option is to use a value/status tuple everywhere you would
normally use a float.  But that falls over every time you need to use
a library function that expects a float as an input and returns a
float as an output.

Since the sensors return a NaN when the value is unkown/invalid it
seemed logical to continue with that paradigm in my Python code -- and
it pretty much just works.

-- 
Grant Edwards   grant.b.edwardsYow! If elected, Zippy
  at   pledges to each and every
  gmail.comAmerican a 55-year-old
   houseboy ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] VCS tools (was Development tools and practices for Pythonistas)

2011-04-28 Thread Martin Schöön
This has been a pretty informative thread so far. Please keep it coming.
I am a hardware development guy and do very little software development.
I have been vaguely aware of tools for version control but inspired by
this thread I have started looking at Mercurial.

My humble contribution (from my boss really) since I have not seen it
mentioned here:
http://code.google.com/p/gource/ (I have zero experience of gource so
there is no point in asking me questions)

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


Re: use of index (beginner's question)

2011-04-28 Thread Rhodri James

On Thu, 28 Apr 2011 01:49:33 +0100, Chris Angelico ros...@gmail.com
wrote:


On Thu, Apr 28, 2011 at 10:42 AM, Rusty Scalf iai-...@sonic.net wrote:

list1 = ['pig', 'horse', 'moose']
list2 =  ['62327', '49123', '79115']
n = 2
s2 = list + `n`
a = s2[list1.index('horse')]
print a


s2 is a string with the value list2; this is not the same as the
variable list2. You could use eval to convert it, but you'd do better
to have a list of lists:

lists = [
 ['pig', 'horse', 'moose']
 ['62327', '49123', '79115']
]

Then you could use:
n = 2
a = lists[n][list1.index('horse')]


*cough* I think you mean

n = 1
a = lists[n][list[0].index('horse')]

The alternative would be to have a dictionary of lists:

lists = {
list1: ['pig', 'horse', 'moose'],
list2: ['62327', '49123', '79115']
}

n = 2
s2 = list + str(n)
a = lists[s2][lists[list1].index('horse')]

Both of these can be made less ugly if the list you want to index into
isn't one of the lists you might want to look up, but that's just a detail.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


subclassing an extension (non built-in) class / type in python 3.2

2011-04-28 Thread Marc Gronle
Hello everybody,

I read in the extending and embedding documentation of python 3, that it is 
easily possible to subclass or subtype a built-in type. However, in my case, I 
would like to subclass a class, defined in a external python-file (py), which I 
can import in my C++-application and access the class by the module's 
dictionary.

Does anybody have an example or just a hint, how to successfully realize this 
type of inheritance?

I will be grateful for every response.

Cheers

Marc
-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: subclassing an extension (non built-in) class / type in python 3.2

2011-04-28 Thread Marc Gronle
Hello everybody,

I read in the extending and embedding documentation of python 3, that it is 
easily possible to subclass or subtype a built-in type. However, in my case, I 
would like to subclass a class, defined in a external python-file (py), which I 
can import in my C++-application and access the class by the module's 
dictionary.

Does anybody have an example or just a hint, how to successfully realize this 
type of inheritance?

I will be grateful for every response.

Cheers

Marc



-- 
NEU: FreePhone - kostenlos mobil telefonieren und surfen!   
Jetzt informieren: http://www.gmx.net/de/go/freephone
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE lost from Windows menu !

2011-04-28 Thread Andrew Berg
On 2011.04.28 02:11 PM, Uncle Ben wrote:
 It was suggested to me privately that I search for
 HKEY_CLASSES_ROOT\*\shell,
 right_click on shell,
 create a new key called EDIT with IDLE
 and another called command python.exe %1
The key you're looking for is HKCR\Python.File\shell. Add a subkey
called Edit with IDLE. Create a subkey in there called command. Inside
HKCR\Python.File\shell\Edit with IDLE\command, modify the default value
to C:\Python32\pythonw.exe C:\Python32\Lib\idlelib\idle.pyw -e %1
(changing the paths if necessary). Do the same with
HKCR\Python.NoConFile\shell to get the command for .pyw files.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 Tkinter and TTK

2011-04-28 Thread David Phillips

 If you want to programm GUI's it is better for you learn Qt or GTK. They are 
 so much better than tkinter.
 I told this with sadness because I like free things, but the reality is not 
 like this. This libs are in all places.
 
 ---
 Jayme Proni Filho
 

My experience with tkinter and Python 3.2 is more positive. I wrote a GUI for 
an editing program (editing like publishers think of it, not programmers) that 
was fairly complex with three different list boxes, an information pane, a 
toolbar, and a pane for the text being edited (implemented with a Text widget). 
 Admittedly it took a little trial and error to perfect the layout of the 
various frames, but when it was done, I was pleased with the appearance, 
functionality, and performance.

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


Re: IDLE lost from Windows menu !

2011-04-28 Thread Terry Reedy

On 4/28/2011 12:28 PM, Uncle Ben wrote:

I have lost the convenient feature that to edit a .py file I could
right-click on the file name and reach the menu item Edit with IDLE.

The workaround is not hard, but it wouild be nice to get this feature
back.

It happened when I was mungeing around and downloaded Python 2.3.3 in
addition to Python 2.71, and got into trojuble uintil I discovered
that I was involuntarily RUNNING the older version.  So I cleaned it
out, but still I have this aftermath.

Is there a Windows guru out there who can tell be how to add to the
right-click menu clicking on myfile.py?


In Window98, one could get from Explorer Window to a file-associations 
dialog/window/tool that would let you change/add 'open', 'open with x', 
'run', for a particular file type without using the registry editor, 
which is slightly dangerous. I have forgotten how to find it in xp, and 
no idea in w7. I would look in windows help and or control panel.


--
Terry Jan Reedy

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


Re: NaN

2011-04-28 Thread Terry Reedy

On 4/28/2011 2:59 PM, Steven D'Aprano wrote:


Still, it could be worse... I've seen a programs use  to represent
missing values, on the basis that nobody could ever have more than (say)
5000 invoices in the database...

(I wish I was exaggerating.)


All 9s in a field for missing was once standard for Fortran programs.

--
Terry Jan Reedy

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


Re: Read-write lock for Python

2011-04-28 Thread Ben Finney
Geoff Bache geoff.ba...@gmail.com writes:

 I currently find myself needing a Python read-write lock.

Please tell us what you mean by “read-write lock”.

 I note that there is none in the standard library, but googling
 python read-write lock quickly produced 6 different competing
 examples, including two languishing patch proposals for the standard
 library.

That's probably because the term isn't well defined. What is your
definition?

-- 
 \  “If you can't beat them, arrange to have them beaten.” —George |
  `\Carlin |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Ben Finney
Ethan Furman et...@stoneleaf.us writes:

 For anybody interested in composition instead of multiple inheritance,
 I have posted this recipe on ActiveState (for python 2.6/7, not 3.x):

 http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

 Comments welcome!

It doesn't look like composition at all, though. I understand
composition to be the setting of attributes on a class or instance; that
recipe doesn't show it very well IMO.

-- 
 \ “[The RIAA] have the patience to keep stomping. They're playing |
  `\ whack-a-mole with an infinite supply of tokens.” —kennon, |
_o__) http://kuro5hin.org/ |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.2 Tkinter and TTK

2011-04-28 Thread Terry Reedy

On 4/28/2011 1:33 PM, steven.oldner wrote:

Just downloaded Python3.2 from python's site and attempted to run some
of the examples in the 24.2.10 Tk Styling.  The button worked,


I found 4 examples, none of which *do* anything. Perhaps they are only 
meant to show syntax. I am running WinXP. You?


.Style:
.configure OK
.map OK
.layout OK? Text says it is not intended to do anything useful
and indeed the displayed button does nothing when pressed.
.theme_settings OK? I do not see any green or olive


but the menu didn't.


What do *you* mean by 'did not work'?

They all compile and display something, but I would have to study more 
before I would know what to expect. It is possible that the examples 
have bugs, or that the ttk module does. Either should be reported on the 
tracker. Others have used it though.


 I also tried a couple from the TKDocs web site.  Only

errors from there.


Syntax error? Runtime exception? or just not look/act as you expect?

--
Terry Jan Reedy

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


Re: [OT] VCS tools

2011-04-28 Thread Ben Finney
Martin Schöön martin.sch...@gmail.com writes:

 This has been a pretty informative thread so far. Please keep it coming.
 I am a hardware development guy and do very little software development.
 I have been vaguely aware of tools for version control but inspired by
 this thread I have started looking at Mercurial.

After my passionate Bazaar evangelism? :-)

I seriously recommend anyone looking for a modern VCS to give Bazaar a
decent trial. It's the one I've found newcomers learn most easily, and
it's astoundingly flexible as one's needs with it grow.

-- 
 \ “I'm a born-again atheist.” —Gore Vidal |
  `\   |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NaN

2011-04-28 Thread Grant Edwards
On 2011-04-28, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 While it is common, it is also an abuse of NANs to use it to
 represent missing values. In Python, that's (probably) best done with
 None.

None won't propogate through calculations to produce None's on outputs.

 The statistics language R has a specific value NA to use for missing,
 distinct from NANs.

 Still, it could be worse... I've seen a programs use  to
 represent missing values, on the basis that nobody could ever have
 more than (say) 5000 invoices in the database... 

All 1's in a float is a NaN, so all 9's in a BCD value is a NaN.  Sort
of makes sense if the BCD operations propogate all-nine values or
raise exceptions when they are encountered (that's a big if).

-- 
Grant Edwards   grant.b.edwardsYow! If elected, Zippy
  at   pledges to each and every
  gmail.comAmerican a 55-year-old
   houseboy ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Carl Banks
On Thursday, April 28, 2011 10:15:02 AM UTC-7, Ethan Furman wrote:
 For anybody interested in composition instead of multiple inheritance, I 
 have posted this recipe on ActiveState (for python 2.6/7, not 3.x):
 
 http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/
 
 Comments welcome!

That's not what we mean by composition.  Composition is when one object calls 
upon another object that it owns to implement some of its behavior.  Often used 
to model a part/whole relationship, hence the name.

The sorts of class that this decorator will work for are probably not the ones 
that are going to have problems cooperating in the first place.  So you might 
as well just use inheritance; that way people trying to read the code will have 
a common, well-known Python construct rather than a custom decorator to 
understand.

If you want to enforce no duplication of attributes you can do that, such as 
with this untested metaclass:

class MakeSureNoBasesHaveTheSameClassAttributesMetaclass(type):
def __new__(metatype,name,bases,dct):
u = collections.Counter()
for base in bases:
for key in base.__dict__.keys():
u[key] += 1
for key in dct.keys():
u[key] += 1
if any(u[key]  1 for key in u.keys()):
raise TypeError(base classes and this class share some class 
attributes)
return type.__new__(metatype,name,bases,dct)
 

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


Re: Read-write lock for Python

2011-04-28 Thread Ryan Kelly
On Thu, 2011-04-28 at 07:02 -0700, Geoff Bache wrote:
 Hi all,
 
 I currently find myself needing a Python read-write lock. I note that
 there is none in the standard library, but googling python read-write
 lock quickly produced 6 different competing examples, including two
 languishing patch proposals for the standard library.
 
 I can always pick a random one and hope for the best, but I was hoping
 someone here might have a tip for one that has been used and debugged
 and is likely to work.

I wrote and have used the SHLock class in threading2 which should do
what you need.  Don't know about likely to work but if it doesn't, I'd
like to hear about it so I can fix it :-)

  `pip install threading2`


  Cheers,

Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au|  http://www.rfk.id.au/ramblings/gpg/ for details



signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] VCS tools

2011-04-28 Thread Tim Chase

On 04/28/2011 04:50 PM, Ben Finney wrote:

This has been a pretty informative thread so far. Please keep it coming.
I am a hardware development guy and do very little software development.
I have been vaguely aware of tools for version control but inspired by
this thread I have started looking at Mercurial.


After my passionate Bazaar evangelism? :-)


I must say my takeaway from the thread was (1) check back in on 
Bazaar to see if the speed is better than I remember and (2) 
Fossil, wha? wow!


-tkc


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


Re: [OT] VCS tools

2011-04-28 Thread Daniel Kluev
On Fri, Apr 29, 2011 at 8:50 AM, Ben Finney ben+pyt...@benfinney.id.au wrote:
 Martin Schöön martin.sch...@gmail.com writes:

 I seriously recommend anyone looking for a modern VCS to give Bazaar a
 decent trial. It's the one I've found newcomers learn most easily, and
 it's astoundingly flexible as one's needs with it grow.


When I was deciding what DVCS I should use for personal projects, Bzr
was first thing I tried. It was quite uncomfortable experience after
svn, esp. with branches and merges, working not the way I was
expecting it to.
Mercurial, on the contrary, did exactly what I was expecting it to,
and was overall very easy to learn.

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


Re: IDLE lost from Windows menu !

2011-04-28 Thread Uncle Ben
On Apr 28, 3:11 pm, Uncle Ben b...@greenba.com wrote:
 On Apr 28, 12:28 pm, Uncle Ben b...@greenba.com wrote:

  I have lost the convenient feature that to edit a .py file I could
  right-click on the file name and reach the menu item Edit with IDLE.

  The workaround is not hard, but it wouild be nice to get this feature
  back.

  It happened when I was mungeing around and downloaded Python 2.3.3 in
  addition to Python 2.7.1, and got into trouble until I discovered
  that I was involuntarily RUNNING the older version.  So I cleaned it
  out, but still I have this aftermath.

  Is there a Windows guru out there who can tell be how to add to the
  right-click menu clicking on myfile.py?

  Uncle Ben

 It was suggested to me privately that I search for
 HKEY_CLASSES_ROOT\*\shell,
 right_click on shell,
 create a new key called EDIT with IDLE
 and another called command python.exe %1

 Problem:
   Searching on the HKEY group as above yields no shell.

 Did I not do it right, or is there another way?

 (I would think that that command would execute my file, not edit it.
 But maybe I will be surprised.)

 (I am running Windows 7, 64-bit.)

 Uncle Ben

Thanks to all for good help.  I finally got what I need by altering
the original advice (A.W.) slightly.

The key to edit was HKCR/Applications/python.exe/shell,
the item is put into the menu in a sub-key labelled Edit with IDLE,
and the command sub-sub-key that works for me is idle.bat %1

I will keep Andrew Berg's note and use it when I encounter .pyw files.

Python's the ninth language I've had to learn. And I love it.

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


Re: IDLE lost from Windows menu !

2011-04-28 Thread Uncle Ben
On Apr 28, 5:17 pm, Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2011.04.28 02:11 PM, Uncle Ben wrote: It was suggested to me privately 
 that I search for
  HKEY_CLASSES_ROOT\*\shell,
  right_click on shell,
  create a new key called EDIT with IDLE
  and another called command python.exe %1

 The key you're looking for is HKCR\Python.File\shell. Add a subkey
 called Edit with IDLE. Create a subkey in there called command. Inside
 HKCR\Python.File\shell\Edit with IDLE\command, modify the default value
 to C:\Python32\pythonw.exe C:\Python32\Lib\idlelib\idle.pyw -e %1
 (changing the paths if necessary). Do the same with
 HKCR\Python.NoConFile\shell to get the command for .pyw files.

Thanks to all for good help.  I finally got what I need by altering
the original advice (A.T.) slightly.

The key to edit was HKCR/Applications/python.exe/shell,
the item is put into the menu in a sub-key labelled Edit with IDLE,
and the command sub-sub-key that works for me is idle.bat %1

I will keep Andrew Berg's note and use it when I encounter .pyw
files.

Python's the ninth language I've had to learn. And I love it.

Uncle Ben

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


Re: Composition instead of inheritance

2011-04-28 Thread Ethan Furman

Carl Banks wrote:

That's not what we mean by composition.  Composition is when one object

 calls upon another object that it owns to implement some of its behavior.
 Often used to model a part/whole relationship, hence the name.

Hmmm. Okay -- any ideas for a better term?  Something that describes 
taking different source classes and fusing them into a new whole, 
possibly using single-inheritance... Frankenstein, maybe?  ;)




The sorts of class that this decorator will work for are probably not

 the ones that are going to have problems cooperating in the first place.
 So you might as well just use inheritance; that way people trying to read
 the code will have a common, well-known Python construct rather than a
 custom decorator to understand.

From thread 'python and super' on Python-Dev:
Ricardo Kirkner wrote:
 I'll give you the example I came upon:

 I have a TestCase class, which inherits from both Django's TestCase
 and from some custom TestCases that act as mixin classes. So I have
 something like

 class MyTestCase(TestCase, Mixin1, Mixin2):
...

 now django's TestCase class inherits from unittest2.TestCase, which we
 found was not calling super.

This is the type of situation the decorator was written for (although 
it's too simplistic to handle that exact case, as Ricardo goes on to say 
he has a setUp in each mixin that needs to be called -- it works fine 
though if you are not adding duplicate names).


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


Re: socket.gethostbyaddr() wrongly returning a DNS CNAME as the 'primary' hostname

2011-04-28 Thread Dan Stromberg
On Thu, Apr 28, 2011 at 1:18 PM, cjblaine cjbla...@gmail.com wrote:

 Thanks for the reply, Ned.

 Bummer for me.  Check this out:

 C code on Solaris 10 SPARC returns the following with nscd
 running (the Solaris Naming Services Caching Daemon, on by
 default):


I'm guessing the IP's PTR record is pointing to a CNAME rather than (one of)
the A record(s).
-- 
http://mail.python.org/mailman/listinfo/python-list


回复: Re: Need your help

2011-04-28 Thread 1011_wxy
Dear Thomas,JM,Chris Rebert:

I got it. Thank you very very very much.


Best Regards

2011-04-29



1011_wxy



发件人: Thomas Rachel 
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de
发送时间: 2011-04-28 21:26
主 题: Re: Need your help
收件人: python-list@python.org



Am 28.04.2011 13:14, schrieb Chris Rebert: 

 import a, b, sys 
 def c(): 
  orig_stdout = sys.stdout 
  sys.stdout = open('my_log_file.log', 'w') 
  a.a() 
  b.b() 
  sys.stdout.close() 
  sys.stdout = orig_stdout 
 
 
 Someone may have written a with-statement context manager that 
 abstracts away the swapping. 

@contextlib.contextmanager 
def swap_stdout(target): 
 orig_stdout = sys.stdout 
 sys.stdout = target 
 try: 
 yield target 
 finally: 
 sys.stdout = orig_stdout 

In this case, I can use all kinds of files (open() files, StringIO  
objects etc.), and can re-use them if necessary, in order to  
prepend/append data. 

Closing can happen additionally, if the user wants. 


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


Aborting Python from C code

2011-04-28 Thread Chris Angelico
In our sandboxed Python environment, I would like to be able to
trigger an abort of the currently-running Python script (from a signal
handler or another thread). Currently, I use PyErr_SetInterrupt()
which raises KeyboardInterrupt in the script; this works for the most
part, but can be bypassed with a script like:

while True:
try:
while True:
pass
except:
pass

I want to be able to administratively order Python to stop executing.
Is it possible to make KeyboardInterrupt non-catchable from Python?
Alternatively, can I use Py_AddPendingCall to do this? I'd rather not
use setjmp/longjmp if I can help it, as they seem a tad brutal, but
I'm thinking in terms of a call that, in effect, doesn't return.

Any ideas would be appreciated!

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


Re: Composition instead of inheritance

2011-04-28 Thread MRAB

On 29/04/2011 02:43, Ethan Furman wrote:

Carl Banks wrote:

That's not what we mean by composition. Composition is when one object

  calls upon another object that it owns to implement some of its
behavior.
  Often used to model a part/whole relationship, hence the name.

Hmmm. Okay -- any ideas for a better term? Something that describes
taking different source classes and fusing them into a new whole,
possibly using single-inheritance... Frankenstein, maybe? ;)


[snip]
Fusing/fusion? Compounding?
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE lost from Windows menu !

2011-04-28 Thread Alec Taylor
Search for the following key in regedit: HKEY_CLASSES_ROOT\*\shell

Right click on “shell”, choose create new key.

Name it “Edit with IDLE

Create a new key below that one and call it “command.”

Now double click on the (Default) value that you will find in the
right hand pane, and type in the following: python.exe %1

(or if you don't have it in your PATH, then put in the absolute python
directory, ie: C:\Python27\bin\python.exe)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE lost from Windows menu !

2011-04-28 Thread Jayme Proni Filho
I agree with MRAB because it is easy and fast solution.

---
Jayme Proni Filho
Skype: jaymeproni
Twitter: @jaymeproni
Phone: +55 - 17 - 3631 - 6576
Mobile: +55 - 17 - 9605 - 3560
e-Mail: jaymeproni at yahoo dot com dot br
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Steven D'Aprano
On Thu, 28 Apr 2011 15:35:47 -0700, Carl Banks wrote:

 On Thursday, April 28, 2011 10:15:02 AM UTC-7, Ethan Furman wrote:
 For anybody interested in composition instead of multiple inheritance,
 I have posted this recipe on ActiveState (for python 2.6/7, not 3.x):
 
 http://code.activestate.com/recipes/577658-composition-of-classes-
instead-of-multiple-inherit/
 
 Comments welcome!
 
 That's not what we mean by composition.  Composition is when one object
 calls upon another object that it owns to implement some of its
 behavior.

I thought that was delegation. As in, when one object delegates some or 
all of it's behaviour to another object:

http://code.activestate.com/recipes/52295


 Often used to model a part/whole relationship, hence the name.

In mathematics, composition means to make a function by applying a 
function to the output of another. E.g.:

f o g(x) is equivalent to f(g(x))

(Strictly speaking, the o in the f o g should be a little circle rather 
than lowercase O.)



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


Re: Composition instead of inheritance

2011-04-28 Thread James Mills
On Fri, Apr 29, 2011 at 11:43 AM, Ethan Furman et...@stoneleaf.us wrote:
 Hmmm. Okay -- any ideas for a better term?  Something that describes taking
 different source classes and fusing them into a new whole, possibly using
 single-inheritance... Frankenstein, maybe?  ;)

I'd have to say that this is typical of MixIns

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Ben Finney
Ethan Furman et...@stoneleaf.us writes:

 Carl Banks wrote:
  That's not what we mean by composition. Composition is when one
  object calls upon another object that it owns to implement some of
  its behavior. Often used to model a part/whole relationship, hence
  the name.

 Hmmm. Okay -- any ideas for a better term? Something that describes
 taking different source classes and fusing them into a new whole,
 possibly using single-inheritance... Frankenstein, maybe? ;)

(Remember that Frankenstein was not the monster, but the scientist.)

“Hybrid”?

-- 
 \  “If sharing a thing in no way diminishes it, it is not rightly |
  `\  owned if it is not shared.” —Augustine of Hippo (354–430 CE) |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Ben Finney
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 On Thu, 28 Apr 2011 15:35:47 -0700, Carl Banks wrote:

  That's not what we mean by composition. Composition is when one
  object calls upon another object that it owns to implement some of
  its behavior.

 I thought that was delegation. As in, when one object delegates some or 
 all of it's behaviour to another object:

 http://code.activestate.com/recipes/52295

The difference being that, with delegation, the object being called is
unrelated to this one. With composition, the object being called is not
wholly separate, but is instead an attribute on the current object.

The “another object that it owns” was, I presume, meant to communicate
this “an object which is an attribute of the current one” relationship.

 In mathematics, composition means to make a function by applying a 
 function to the output of another.

The term “composition” in the programming sense comes from OO design,
not functional nor mathematical terminology.

-- 
 \  “I don't like country music, but I don't mean to denigrate |
  `\  those who do. And for the people who like country music, |
_o__)denigrate means ‘put down’.” —Bob Newhart |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Dan Stromberg
On Thu, Apr 28, 2011 at 3:35 PM, Carl Banks pavlovevide...@gmail.com wrote:
 On Thursday, April 28, 2011 10:15:02 AM UTC-7, Ethan Furman wrote:
 For anybody interested in composition instead of multiple inheritance, I
 have posted this recipe on ActiveState (for python 2.6/7, not 3.x):

 http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

 Comments welcome!

 That's not what we mean by composition.  Composition is when one object calls 
 upon another object that it owns to implement some of its behavior.  Often 
 used to model a part/whole relationship, hence the name.

It's a pretty old idea, that seems to be getting revived in a big way
all of a sudden.  Perhaps the Java people just rediscovered it?

In a Software Engineering class using Ada, the teacher called it
Structural Inclusion, and of course it was an important concept in
Ada, because Ada had no inheritance.  This was in 1989-1990.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Composition instead of inheritance

2011-04-28 Thread Ben Finney
Dan Stromberg drsali...@gmail.com writes:

 On Thu, Apr 28, 2011 at 3:35 PM, Carl Banks pavlovevide...@gmail.com wrote:
  That's not what we mean by composition.  Composition is when one
  object calls upon another object that it owns to implement some of
  its behavior.  Often used to model a part/whole relationship, hence
  the name.

 It's a pretty old idea, that seems to be getting revived in a big way
 all of a sudden. Perhaps the Java people just rediscovered it?

I think it's more that people keep re-discovering how irredeemably messy
multiple inheritance is, and finding that object composition is better
in most cases :-)

-- 
 \  “There's a fine line between fishing and standing on the shore |
  `\looking like an idiot.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use of index (beginner's question)

2011-04-28 Thread Daniel Kluev
On Thu, Apr 28, 2011 at 11:42 AM, Rusty Scalf iai-...@sonic.net wrote:
 list1 = ['pig', 'horse', 'moose']
 list2 =  ['62327', '49123', '79115']
 n = 2
 s2 = list + `n`
 a = s2[list1.index('horse')]
 print a

  -does not work

While advices above are indeed right way to go in your case, there is
a way to get variable by its name.

 list2 = ['62327', '49123', '79115']
 n = 2
 s2 = list{0}.format(n)
 print s2
list2
 print locals()[s2]
['62327', '49123', '79115']
 print locals()[s2][0]
62327

But generally if you need to do that, you would be better with
re-design of your data/architecture.

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


Re: Composition instead of inheritance

2011-04-28 Thread Ian Kelly
On Thu, Apr 28, 2011 at 11:15 AM, Ethan Furman et...@stoneleaf.us wrote:
 For anybody interested in composition instead of multiple inheritance, I
 have posted this recipe on ActiveState (for python 2.6/7, not 3.x):

 http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/

 Comments welcome!

On line 14, is it intentional that attributes whose values happen to
be false are not considered as conflicts?

On line 31, this code:

thing = getattr(thing, '__func__', None) or thing

could be simplified to this:

thing = getattr(thing, '__func__', thing)

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


Python RPM Package build error

2011-04-28 Thread Wells, David J
Hello List,

 

I am attempting to build an rpm from Python-3.1.3.tar.bz2 with the
included spec file from /Python-3.1.3/Misc/RPM/ and it fails with the
following error:

Does anyone have any ideas?

 

# rpmbuild -ba python-3.1.spec

 

mv: cannot stat `idle': No such file or directory

+ echo '#!/usr/bin/env python2.6'

+ echo 'import os, sys'

+ echo 'os.execvp(/usr/bin/python2.6, [/usr/bin/python2.6,
/usr/lib/python3.1/idlelib/idle.py] + sys.argv[1:])'

+ echo 'print Failed to exec Idle'

+ echo 'sys.exit(1)'

+ chmod 755 /var/tmp/python2.6-3.1.3-root/usr/bin/idle2.6

+ cp -a Tools /var/tmp/python2.6-3.1.3-root/usr/lib64/python3.1

+ rm -f mainpkg.files

+ find /var/tmp/python2.6-3.1.3-root/usr/lib64/python3.1/lib-dynload -type
f

+ sed 's|^/var/tmp/python2.6-3.1.3-root|/|'

+ grep -v -e '_tkinter.so$'

error: Bad exit status from /var/tmp/rpm-tmp.7647 (%install)

 

/var/tmp/rpm-tmp.7647 include the following:

 

#  check to see if there are any straggling #! lines

find $RPM_BUILD_ROOT -type f | xargs egrep -n '^#!
*/usr/local/bin/python' \

  | grep ':1:#!' /tmp/python-rpm-files.$$ || true

if [ -s /tmp/python-rpm-files.$$ ]

then

   echo '*'

   cat /tmp/python-rpm-files.$$

   cat @EOF

   *

 There are still files referencing /usr/local/bin/python in the

 install directory.  They are listed above.  Please fix the .spec

 file and try again.  If you are an end-user, you probably want

 to report this to jafo-r...@tummy.com as well.

   *

@EOF

   rm -f /tmp/python-rpm-files.$$

   exit 1

fi

rm -f /tmp/python-rpm-files.$$

 



#  CLEAN



 







/usr/lib/rpm/brp-compress 

/usr/lib/rpm/brp-strip 

/usr/lib/rpm/brp-strip-static-archive 

/usr/lib/rpm/brp-strip-comment-note

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


  1   2   3   >