Re: Passing FILE * types using ctypes

2010-03-05 Thread Gregory Ewing
Francesco Bochicchio wrote: Python file objects have a method fileno() whic returns the 'C file descriptor', i.e. the number used by low level IO in python as well as in C. I would use this as interface between python and C and then in the C function using fdopen to get a FILE * for an already o

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Paul Rubin
Steve Howell writes: >> Modify the JSON standard so that "JSON 2.0" allows comments. > > If you don't control the JSON standard, providing a compelling > alternative to JSON might be the best way to force JSON to accomodate > a wider audience. Ehh, either the JSON standardizers care about this i

indentation error

2010-03-05 Thread asit
Consider the following code import stat, sys, os, string, commands try: pattern = raw_input("Enter the file pattern to search for :\n") commandString = "find " + pattern commandOutput = commands.getoutput(commandString) findResults = string.split(commandOutput, "\n") print "Fi

Re: Failure in test_hashlib.py and test_hmac.py

2010-03-05 Thread Paul Rubin
Chris Lieb writes: > I am building Python 2.6.4 on a shared server and am encountering test > failures in test_hashlib.py and test_hmac.py, You should certainly file a bug report (bugs.python.org). If you want to debug it yourself and include a patch, that's great. Otherwise, just file the repo

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > Paul Rubin wrote: >> ReST was another solution in search of a problem. > > I think the basic idea behind ReST is quite good, i.e. understanding as > markup various typographical conventions that make sense in plain text, > such as underli

comparing two lists

2010-03-05 Thread jimgardener
hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst=['jon','arya','ned','bran'] newlst=['jaim

Re: Docstrings considered too complicated

2010-03-05 Thread Gregory Ewing
Steven D'Aprano wrote: (a) Can we objectively judge the goodness of code, or is it subjective? (b) Is goodness of code quantitative, or is it qualitative? Yes, I'm not really talking about numeric vs. non-numeric, but objective vs. subjective. The measurement doesn't have to yield a numeric r

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 16:27 , Alf P. Steinbach wrote: * Mike Kent: However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wanted the chdir to

ImportError: No module named glib

2010-03-05 Thread Michael Joachimiak
I am too new to python. If anybody has an idea what to do please help. when I use import glib in my code I get this: >>> import glib Traceback (most recent call last): File "", line 1, in ImportError: No module named glib :~$ python -V Python 2.6.4 /usr/lib/libpyglib-2.0-python2.6.so.0.0.0

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 15:12 , Mike Kent wrote: On Mar 4, 12:30 pm, Robert Kern wrote: He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. No, I was referring to Jean-Michel, who was not familiar wi

Re: indentation error

2010-03-05 Thread Ulrich Eckhardt
asit wrote: > pattern = raw_input("Enter the file pattern to search for :\n") > commandString = "find " + pattern > commandOutput = commands.getoutput(commandString) > findResults = string.split(commandOutput, "\n") > print "Files : " > print commandOutput > print "=

10th Python Game Programming Challenge in three weeks

2010-03-05 Thread Richard Jones
The 10th Python Game Programming Challenge (http://pyweek.org/) will run from the 28th of March to the 4th of April. The PyWeek challenge: - Invites entrants to write a game in one week from scratch either as an individual or in a team, - Is intended to be challenging and fun, - Will hopefully in

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-04 17:52 , Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly failing operation

[ANN] pysqlite 2.6.0 released

2010-03-05 Thread Gerhard Häring
pysqlite 2.6.0 released === Release focus: Synchronize with sqlite3 module in Python trunk. pysqlite is a DB-API 2.0-compliant database interface for SQLite. SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL dat

Re: Partly erratic wrong behaviour, Python 3, lxml

2010-03-05 Thread Stefan Behnel
Jussi Piitulainen, 04.03.2010 22:40: Stefan Behnel writes: Jussi Piitulainen, 04.03.2010 11:46: I am observing weird semi-erratic behaviour that involves Python 3 and lxml, is extremely sensitive to changes in the input data, and only occurs when I name a partial result. I would like some help

Re: comparing two lists

2010-03-05 Thread Vlastimil Brom
2010/3/5 jimgardener : > hi > I have two lists of names.I need to find the difference between these > two lists.I tried to do it using sets.But I am wondering if there is a > better way to do it.Please tell me if there is a more elegant way. > thanks, > jim > > my code snippet follows.. > > oldlst=

Re: NoSQL Movement?

2010-03-05 Thread Duncan Booth
Gregory Ewing wrote: > Duncan Booth wrote: >> Did I mention that bigtable doesn't require you to have the same >> columns in every record? The main use of bigtable (outside of Google's >> internal use) is Google App Engine and that apparently uses one table. >> >> Not one table per applicati

Re: Evaluate my first python script, please

2010-03-05 Thread Tim Wintle
On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > I am looking for advice along the lines of "an easier way to do this" > or "a more python way" (I'm sure that's asking for trouble!) or > "people commonly do this instead" or "here's a slick trick" or "oh, > interesting, here's my version to

Re: NoSQL Movement?

2010-03-05 Thread Juan Pedro Bolivar Puente
On 04/03/10 19:52, ccc31807 wrote: > On Mar 4, 11:51 am, Juan Pedro Bolivar Puente > wrote: >> No, relations are data. > > This depends on your definition of 'data.' I would say that > relationships is information gleaned from the data. > >> "Data is data" says nothing. Data is >> information. >

Re: _winreg and accessing registry settings of another user

2010-03-05 Thread Tim Golden
On 05/03/2010 07:21, News123 wrote: My script shall be part of installing and configuring a PC with some default settings with the minimal amount of human administrator interactions. The steps: - install windows - install python - setup one admin account and one or more user accounts (without ad

Re: loop over list and process into groups

2010-03-05 Thread Paul Rubin
lbolla writes: > for k, g in groupby(clean_up(data) , key=lambda s: s.startswith('VLAN')): > if k: > key = list(g)[0].replace('VLAN','') This is the nicest solution, I think. Mine was more cumbersome. -- http://mail.python.org/mailman/listinfo/python-list

Re: SOAP 1.2 Python client ?

2010-03-05 Thread BlueBird
On 3 mar, 20:35, Stefan Behnel wrote: > BlueBird, 03.03.2010 17:32: > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > that this does not exist. Does anybody know about this ? > > SOAP may be an overly bloated protocol, but it's certainly not black magic. > It's not hard

Proper way to return an instance of a class from a class method ?

2010-03-05 Thread Auré Gourrier
Dear all, I have what will probably sound as stupid questions for experienced Python users... which I am not, hence my seeking for some help. QUESTION 1: I've implemeted a class which defines a container with 2 lists of data (with some specific format). Some of the methods simply t

Re: Evaluate my first python script, please

2010-03-05 Thread Jean-Michel Pichavant
Pete Emerson wrote: I've written my first python program, and would love suggestions for improvement. I'm a perl programmer and used a perl version of this program to guide me. So in that sense, the python is "perlesque" This script parses /etc/hosts for hostnames, and based on terms given on t

Re: NoSQL Movement?

2010-03-05 Thread Bruno Desthuilliers
Philip Semanchuk a écrit : On Mar 3, 2010, at 5:41 PM, Avid Fan wrote: Jonathan Gardner wrote: I see it as a sign of maturity with sufficiently scaled software that they no longer use an SQL database to manage their data. At some point in the project's lifetime, the data is understood well e

Re: ImportError: No module named glib

2010-03-05 Thread mblume
Am Fri, 05 Mar 2010 10:30:49 +0200 schrieb Michael Joachimiak: > I am too new to python. > If anybody has an idea what to do please help. when I use > > import glib > > in my code I get this: > import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No modu

Selecting MAX from a list

2010-03-05 Thread Ines T
I need to select a maximum number from a list and then call the variable that identifies that number, for example: x1,x2=1, y1,y2=4, z1,z2=3 So I need first to find 4 and then to take y to do additional operations as y-z. I will appreciate your SOON help! -- http://mail.python.org/mailman/listinf

Re: ImportError: No module named glib

2010-03-05 Thread Peter Otten
Michael Joachimiak wrote: > I am too new to python. > If anybody has an idea what to do please help. > when I use > > import glib > > in my code I get this: > import glib > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named glib > > :~$ python -V >

Re: indentation error

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 00:04:13 -0800, asit wrote: > Consider the following code [snip] > According to me, indentation is ok. but the python interpreter gives an > indentation error You can trust the interpreter. There *is* an indentation error. Most likely you have mixed spaces and tabs. Try: pyt

Re: Selecting MAX from a list

2010-03-05 Thread Shashwat Anand
On Fri, Mar 5, 2010 at 5:09 PM, Ines T wrote: > I need to select a maximum number from a list use max() > and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > you mean x1 = y1 = 1 or x1, y1 = 1, 1 right ? > So I need first to find 4 and then

Re: NoSQL Movement?

2010-03-05 Thread mk
Bruno Desthuilliers wrote: Well, Zope is backed by an object database rather than a relational one. And it ended up being a *major* PITA on all Zope projects I've worked on... Care to write a few sentences on nature of problems with zodb? I was flirting with the thought of using it on some p

Re: Proper way to return an instance of a class from a class method ?

2010-03-05 Thread Chris Rebert
On Fri, Mar 5, 2010 at 2:35 AM, Auré Gourrier wrote: > QUESTION 2: > If I go this way, I have a second problem: if I create a new class which > inherits from the previous, I would expect/like the methods from the initial > class to return instances from the new class: > > class MyClass2(MyClass):

Re: Method / Functions - What are the differences?

2010-03-05 Thread Bruno Desthuilliers
John Posner a écrit : On 3/3/2010 6:56 PM, John Posner wrote: ... I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll try to produce something over the next couple of days. Starting t

Re: SOAP 1.2 Python client ?

2010-03-05 Thread lbolla
On Mar 5, 10:01 am, BlueBird wrote: > On 3 mar, 20:35, Stefan Behnel wrote: > > > BlueBird, 03.03.2010 17:32: > > > > I am looking for a SOAP 1.2 python client. To my surprise, it seems > > > that this does not exist. Does anybody know about this ? > > > SOAP may be an overly bloated protocol, bu

Re: A "scopeguard" for Python

2010-03-05 Thread Jean-Michel Pichavant
Robert Kern wrote: On 2010-03-04 15:12 , Mike Kent wrote: On Mar 4, 12:30 pm, Robert Kern wrote: He's ignorant of the use cases of the with: statement, true. Ouch! Ignorant of the use cases of the with statement, am I? Odd, I use it all the time. No, I was referring to Jean-Michel, who

Re: Selecting MAX from a list

2010-03-05 Thread lbolla
On Mar 5, 11:39 am, Ines T wrote: > I need to select a maximum number from a list and then call the variable that > identifies that number, for example: > x1,x2=1, y1,y2=4, z1,z2=3 > So I need first to find 4 and then to take y to do additional operations as > y-z. It's not clear what you are su

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 17:52 , Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 12:37 PM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-04 10:56 AM, Alf P. Steinbach wrote: * Robert Kern: On 2010-03-03 18:49 PM, Alf P. Steinbach wrote: [snippety] If you call the possibly fa

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-04 16:27 , Alf P. Steinbach wrote: * Mike Kent: However, I fail to understand his response that I must have meant try/ else instead, as this, as Mr. Kern pointed out, is invalid syntax. Perhaps Mr. Steinbach would like to give an example? OK. Assuming that you wan

Re: loop over list and process into groups

2010-03-05 Thread mk
Sneaky Wombat wrote: [ 'VLAN4065', 'Interface', 'Gi9/6', 'Po2', 'Po3', 'Po306', 'VLAN4068', 'Interface', 'Gi9/6', 'VLAN4069', 'Interface', 'Gi9/6',] Hey, I just invented a cute ;-) two-liner using list comprehensions: # alist = list above tmp, dk = [], {} [(x.startswith('VLAN') and

Re: process mp3 file

2010-03-05 Thread vanam
On Mar 3, 3:43 pm, asit wrote: > > Define "processing". > > getting the title, song name, etc of the file and updating in a > database Other possibility can be passing out the extension of the file and directory where the files are present, using os.walk we can extract the file name by filtering

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant wrote: > You've already been given good advices. > Unlike some of those, I don't think using regexp an issue in any way. > Yes they are not readable, for sure, I 100% agree to that statement, but > you can make them readable very easily. > > # not readable > match = re.se

python on a thumb drive?

2010-03-05 Thread Alex Hall
Hello all, My name is Alex. I am pretty new to Python, but I really like it. I am trying to put my python and pythonw executables on my thumb drive, along with packages, using Moveable Python, but I cannot figure out how to run scripts using it. I would rather use a shell than the script runner gu

Speech to Text

2010-03-05 Thread Santhosh Kumar
Hi All, I am trying to find is there is any way to covert "speech to Text" with Python in UBUNTU. I googled whr I found Many Text to speech. Some one please assist me. -- With Regards, Never Say No, Santhosh V.Kumar +919840411410 -- http://mail.python.org/mailman/listinfo/python-list

Re: Evaluate my first python script, please

2010-03-05 Thread Jean-Michel Pichavant
Duncan Booth wrote: Jean-Michel Pichavant wrote: You've already been given good advices. Unlike some of those, I don't think using regexp an issue in any way. Yes they are not readable, for sure, I 100% agree to that statement, but you can make them readable very easily. # not readable

Re: Partly erratic wrong behaviour, Python 3, lxml

2010-03-05 Thread Jussi Piitulainen
Stefan Behnel writes: > Jussi Piitulainen, 04.03.2010 22:40: > > Stefan Behnel writes: > >> Jussi Piitulainen, 04.03.2010 11:46: > >>> I am observing weird semi-erratic behaviour that involves Python 3 > >>> and lxml, is extremely sensitive to changes in the input data, and > >>> only occurs when I

Re: Evaluate my first python script, please

2010-03-05 Thread Duncan Booth
Jean-Michel Pichavant wrote: > And tell me how not using regexp will ensure the /etc/hosts processing > is correct ? The non regexp solutions provided in this thread did not > handled what you rightfully pointed out about host list and commented > lines. It won't make is automatically correct,

Re: Method / Functions - What are the differences?

2010-03-05 Thread John Posner
On 3/5/2010 7:15 AM, Bruno Desthuilliers wrote: John Posner a écrit : On 3/3/2010 6:56 PM, John Posner wrote: ... I was thinking today about "doing a Bruno", and producing similar pieces on: * properties created with the @property decorator * the descriptor protocol I'll try to produce some

Re: WANTED: A good name for the pair (args, kwargs)

2010-03-05 Thread Jonathan Fine
Jonathan Fine wrote: Hi We can call a function fn using val = fn(*args, **kwargs) I'm looking for a good name for the pair (args, kwargs). Any suggestions? Here's my use case: def doit(fn , wibble, expect): args, kwargs = wibble actual = fn(*args, **kwargs) if

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
Thanks for your response, further questions inline. On Mar 4, 11:07 am, Tim Wintle wrote: > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > I am looking for advice along the lines of "an easier way to do this" > > or "a more python way" (I'm sure that's asking for trouble!) or > > "peo

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 7:00 am, Duncan Booth wrote: > Jean-Michel Pichavant wrote: > > And tell me how not using regexp will ensure the /etc/hosts processing > > is correct ? The non regexp solutions provided in this thread did not > > handled what you rightfully pointed out about host list and commented > >

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread John Bokma
Steven D'Aprano writes: > On Fri, 05 Mar 2010 18:36:06 +1300, Gregory Ewing wrote: > >> Paul Rubin wrote: >>> ReST was another solution in search of a problem. >> >> I think the basic idea behind ReST is quite good, i.e. understanding as >> markup various typographical conventions that make sens

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Steve Howell
On Mar 4, 11:46 pm, Paul Rubin wrote: > > Ehh, either the JSON standardizers care about this issue or else they > don't.  JSON (as currently defined) is a machine-to-machine > serialization format and just isn't that good a choice for handwritten > files.  Adding a comment specification is a small

Re: Evaluate my first python script, please

2010-03-05 Thread Tim Wintle
On Fri, 2010-03-05 at 07:53 -0800, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle wrote: > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a

Re: Failure in test_hashlib.py and test_hmac.py

2010-03-05 Thread Chris Lieb
On Mar 5, 2:50 am, Paul Rubin wrote: > Chris Lieb writes: > > I am building Python 2.6.4 on a shared server and am encountering test > > failures in test_hashlib.py and test_hmac.py, > > You should certainly file a bug report (bugs.python.org).  If you want > to debug it yourself and include a pa

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Tim Chase
Steve Howell wrote: On Mar 4, 11:46 pm, Paul Rubin wrote: We already have to deal with XML. So using XML for config files doesn't require anyone to deal with any lousy formats that they didn't have to deal with before. So the basic answer to your question about well-established standards is y

Re: A "scopeguard" for Python

2010-03-05 Thread Mike Kent
On Mar 4, 8:04 pm, Robert Kern wrote: > No, the try: finally: is not implicit. See the source for > contextlib.GeneratorContextManager. When __exit__() gets an exception from the > with: block, it will push it into the generator using its .throw() method. > This > raises the exception inside the

Re: A "scopeguard" for Python

2010-03-05 Thread Steve Howell
On Mar 5, 8:29 am, Mike Kent wrote: > On Mar 4, 8:04 pm, Robert Kern wrote: > > > No, the try: finally: is not implicit. See the source for > > contextlib.GeneratorContextManager. When __exit__() gets an exception from > > the > > with: block, it will push it into the generator using its .throw(

Re: loop over list and process into groups

2010-03-05 Thread nn
mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > > 'Interface', > > 'Gi9/6', > > 'Po2', > > 'Po3', > > 'Po306', > > 'VLAN4068', > > 'Interface', > > 'Gi9/6', > > 'VLAN4069', > > 'Interface', > > 'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list comprehensions: > >

Re: A "scopeguard" for Python

2010-03-05 Thread Steve Howell
On Mar 4, 5:04 pm, Robert Kern wrote: > On 2010-03-04 15:19 PM, Mike Kent wrote: > > > > > On Mar 3, 12:00 pm, Robert Kern  wrote: > >> On 2010-03-03 09:39 AM, Mike Kent wrote: > > >>> What's the compelling use case for this vs. a simple try/finally? > > >>>      original_dir = os.getcwd() > >>>  

Re: Generic singleton

2010-03-05 Thread Terry Reedy
On 3/4/2010 10:32 PM, Steven D'Aprano wrote: Python does have it's own singletons, like None, True and False. True and False are not singletons. > For some reason, they behave quite differently: Because they are quite different. > NoneType fails if you try to instantiate it again, Because

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-05 10:29 AM, Mike Kent wrote: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. Thi

Re: loop over list and process into groups

2010-03-05 Thread lbolla
On Mar 5, 1:26 pm, mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > >  'Interface', > >  'Gi9/6', > >  'Po2', > >  'Po3', > >  'Po306', > >  'VLAN4068', > >  'Interface', > >  'Gi9/6', > >  'VLAN4069', > >  'Interface', > >  'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list co

Re: loop over list and process into groups

2010-03-05 Thread mk
nn wrote: Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

isinstance(False, int)

2010-03-05 Thread mk
>>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: comparing two lists

2010-03-05 Thread Terry Reedy
On 3/5/2010 3:05 AM, jimgardener wrote: hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst

Re: loop over list and process into groups

2010-03-05 Thread mk
lbolla wrote: It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk -- http://mail.p

Re: ImportError: No module named glib

2010-03-05 Thread Terry Reedy
On 3/5/2010 3:30 AM, Michael Joachimiak wrote: I am too new to python. If anybody has an idea what to do please help. when I use import glib in my code I get this: import glib Traceback (most recent call last): File "", line 1, in ImportError: No module named glib glib is not in Python'

Escaping variable names

2010-03-05 Thread Kamil Wasilewski
Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl"; server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } s

Re: isinstance(False, int)

2010-03-05 Thread Steve Holden
mk wrote: isinstance(False, int) > True isinstance(True, int) > True > > Huh? > issubclass(bool, int) > True > > Huh?! > >>> 3+True 4 >>> 3+False 3 >>> Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it would be a good ideal for Booleans to be a s

Re: Generic singleton

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > >> Python does have it's own singletons, like None, True and False. > > True and False are not singletons. Duotons? Doubletons? >>> t1 = bool(1) >>> t2 = bool(1) >>> t1 is t2 True >>> t1 is

Slicing [N::-1]

2010-03-05 Thread Joan Miller
What does a slice as [N::-1] ? It looks that in the first it reverses the slice and then it shows only N items, right? Could you add an example to get the same result without use `::` to see it more clear? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread Arnaud Delobelle
mk writes: isinstance(False, int) > True isinstance(True, int) > True > > Huh? > issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + False 1 In fact: >>> 1 == True True >>> 0 == False True So what's your question? -- Arnaud -- http://mail

Re: isinstance(False, int)

2010-03-05 Thread Stephen Hansen
On Fri, Mar 5, 2010 at 9:14 AM, mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Huh, what? http://www.python.org/dev/peps/pep-0285/ --S -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? Yes. Do you have an actual question? > >>> issubclass(bool, int) > True > > Huh?! Exactly. Bools are a late-comer to Python. For historical and implementatio

Re: Escaping variable names

2010-03-05 Thread Jean-Michel Pichavant
Kamil Wasilewski wrote: Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl"; server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country

Re: Slicing [N::-1]

2010-03-05 Thread Arnaud Delobelle
Joan Miller writes: > What does a slice as [N::-1] ? > > It looks that in the first it reverses the slice and then it shows > only N items, right? > > Could you add an example to get the same result without use `::` to > see it more clear? > > Thanks in advance >>> l = range(10) >>> l [0, 1, 2,

Re: Evaluate my first python script, please

2010-03-05 Thread sjdevn...@yahoo.com
On Mar 5, 10:53 am, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python

Re: Slicing [N::-1]

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 10:01:40 -0800, Joan Miller wrote: > What does a slice as [N::-1] ? Why don't you try it? >>> s = "abcdefgh" >>> s[4::-1] 'edcba' The rules for extended slicing are not explained very well in the docs, and can be confusing. In my experience, apart from [::-1] it is best to

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
On Fri, Mar 5, 2010 at 2:00 PM, Steve Holden wrote: [...] > > Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it > would be a good ideal for Booleans to be a subclass of integers. > I would never figured out >>> bool.__bases__ (,) Doesn't have side effects not knowing tha

Re: Slicing [N::-1]

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices are supposed to have default

Re: isinstance(False, int)

2010-03-05 Thread MRAB
mk wrote: >>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Python didn't have Booleans originally, 0 and 1 were used instead. When bool was introduced it was made a subclass of int so that existing code wouldn't break. -- h

Re: isinstance(False, int)

2010-03-05 Thread mk
Arnaud Delobelle wrote: 1 == True True 0 == False True So what's your question? Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, but not in Python.. Although I can understand the rationale after skimming PEP 285, I still don't like it very much. Regards, mk

Re: Slicing [N::-1]

2010-03-05 Thread Shashwat Anand
On Fri, Mar 5, 2010 at 11:42 PM, Arnaud Delobelle wrote: > Joan Miller writes: > > > What does a slice as [N::-1] ? > > > > It looks that in the first it reverses the slice and then it shows > > only N items, right? > > > > Could you add an example to get the same result without use `::` to > > s

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 12:01 pm, Joan Miller wrote: > What does a slice as [N::-1] ? Starts at position N and returns all items to the start of the list in reverse order. > > It looks that in the first it reverses the slice and then it shows > only N items, right? Wrong. It shows N+1 items. Remember, counti

Re: isinstance(False, int)

2010-03-05 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? Yes. Do you have an actual question? >>> issubclass(bool, int) True Huh?! Exactly. Bools are a late-comer to Python.

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 10:19 am, "sjdevn...@yahoo.com" wrote: > On Mar 5, 10:53 am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > > I am looking for advice

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: > Arnaud Delobelle wrote: > > 1 == True >> >> True > > 0 == False >> >> True >> >> So what's your question? > > Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, > but not in Python.. Although I can understand the rat

Re: Slicing [N::-1]

2010-03-05 Thread Robert Kern
On 2010-03-05 12:28 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)] [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Mike Kent: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. This raises the exception insid

start function in new process

2010-03-05 Thread wongjoek...@yahoo.com
Hello all, I would like to run a python function completely in a new process. For example I have a parent process. That parent process needs to start a child process in which the function is called. After the child process is finished however I want that the child process should stop and then only

Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ### foo.py def foo: return 'foo' ### foobar.py def foobar: if foo.

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 12:28 pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: > l = range(10) > l > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > l[7::-1] > > [7, 6, 5, 4, 3, 2, 1, 0] > [l[i] for i in range(7, -1, -1)] > > [7, 6, 5, 4, 3, 2, 1, 0] > > Where does

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Steve Howell: On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even wh

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 11:24 am, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo:

Re: start function in new process

2010-03-05 Thread Martin P. Hellwig
On 03/05/10 19:21, wongjoek...@yahoo.com wrote: Any specific reason why threading.Thread or multiprocessing is not suitable to solve your problem? -- mph -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread mk
Rolando Espinoza La Fuente wrote: Doesn't have side effects not knowing that False/True are ints? It does, in fact I was wondering why my iterator didn't work until I figured issubclass(bool, int) is true. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: start function in new process

2010-03-05 Thread wongjoek...@yahoo.com
On 5 mrt, 20:40, "Martin P. Hellwig" wrote: > On 03/05/10 19:21, wongjoek...@yahoo.com wrote: > > Any specific reason why threading.Thread or multiprocessing is not > suitable to solve your problem? > > -- > mph Because I got a memory leak in my function f(). It uses scipy, numpy, pylab, and I a

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Steve Holden
Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo: > return 'foo

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 11:24:44 -0800, Pete Emerson wrote: > In a module, how do I create a conditional that will do something based > on whether or not another module has been loaded? try: import foo except ImportError: foo = None def function(): if foo: return foo.func() e

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >> 1 == True >>> >>> True >> >> 0 == False >>> >>> True >>> >>> So what's your question? >> >> Well nothing I'm just kind of bewildered: I'd

  1   2   >