Re: UTF-8 in basic CGI mode

2008-01-16 Thread Sion Arrowsmith
coldpizza <[EMAIL PROTECTED]> wrote: >I am using this 'word' variable like this: > >print u'' % (word) > >and apparently this causes exceptions with non-ASCII strings. > >I've also tried this: >print u'' % >(word.encode('utf8')) >but I still get the same UnicodeDecodeError.. Your 'word' i

Re: Interesting Thread Gotcha

2008-01-17 Thread Sion Arrowsmith
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >Of course start_new_thread could throw an error if it got nothing callable >as first argument. No idea why it doesn't. It does: >>> thread.start_new_thread(None, None) Traceback (most recent call last): File "", line 1, in ? TypeError: first arg must

Re: problem with gethostbyaddr with intranet addresses on MAC

2008-01-28 Thread Sion Arrowsmith
shailesh <[EMAIL PROTECTED]> wrote: >Python 2.4.4 (#1, Oct 18 2006, 10:34:39) >[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin >Type "help", "copyright", "credits" or "license" for more information. from socket import * x = gethostbyname('google.com') x >'64.233.167.99'

Re: refcount

2008-01-30 Thread Sion Arrowsmith
Benjamin <[EMAIL PROTECTED]> wrote: >> [ help(sys.getrefcount) says: ] >> [ ... ] The count returned is generally >> one higher than you might expect, because it includes the (temporary) >> reference as an argument to getrefcount(). >Are there any cases when it wouldn't? When the temporary refer

Re: Removing Pubic Hair Methods

2008-01-30 Thread Sion Arrowsmith
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >On Tue, 29 Jan 2008 11:48:38 -0800, Tobiah wrote: >> class genital: >> def pubic_hair(self): >> pass >> def remove(self): >> del(self.pubic_hair) >I think `pubic_hair` is an attribute instead of a method. > >O

Re: issues with searching through dictionaries for certain values

2008-02-01 Thread Sion Arrowsmith
Connolly <[EMAIL PROTECTED]> wrote: >Right basically I've got to the end of my main section of my program an I've >got it comparing the same dictionary to ensure that the values are the same >(sounds stupid I know), yet what my line of code I am using to do this is >failing to do is to check eve

Re: socket script from perl -> python

2008-02-08 Thread Sion Arrowsmith
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >kettle <[EMAIL PROTECTED]> writes: >> # pack $length as a 32-bit network-independent long >> my $len = pack('N', $length); >[...] >> the sticking point seems to be the $len variable. >Use len = struct.pack('!L', length) in Python. See >http://docs.python.

Re: keyword 'in' not returning a bool?

2008-02-08 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, c james <[EMAIL PROTECTED]> wrote: sample = {'t':True, 'f':False} 't' in sample == True >False > >Why is this? http://docs.python.org/lib/comparisons.html "Comparisons can be chained arbitrarily; for example, x < y <= z is equivalent to x < y and y <= z,

Re: How to tell if I'm being run from a shell or a module

2008-02-15 Thread Sion Arrowsmith
Gabriel Genellina <[EMAIL PROTECTED]> wrote: >a) See if the __main__ module has a __file__ attribute. >b) See if sys.stdin is a real tty c) See if sys.argv[0] != '' (Although this works for the command line interactive shell, I've a suspicion it will fail with IDLE. But I don't have IDLE to hand

Re: a question in python curses modules

2008-02-15 Thread Sion Arrowsmith
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >When the interpreter shuts down it has to remove objects. Everything you >need in a `__del__()` method must be referenced by that object to be sure >that it is still there and not already garbage collected. *But* it's not >guaranteed that `__d

Re: Linux/Python Issues

2008-02-19 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >CNR, which is now free, is absolutely marvelous when it's got what you >need. If Python2.5 were in the warehouse, I'd have clicked, gone to >make a cup of coffee and the appropriate icon would be on my desktop >when I came back. If I were Python.org I'd not consider any

Re: float / rounding question

2008-02-25 Thread Sion Arrowsmith
Necmettin Begiter <[EMAIL PROTECTED]> wrote: >25 February 2008 Monday 12:44:46 tarihinde [EMAIL PROTECTED] =C5=9Fun= >lar=C4=B1 yazm=C4=B1=C5=9Ft=C4=B1: >> Of course the function above returns 53.601. >>=20 >> How do I format it correctly? > >Use the round(number,digits) function: > >t

Re: popening a process in a specific working directory

2008-03-05 Thread Sion Arrowsmith
Michael Torrie <[EMAIL PROTECTED]> wrote: >I'm currently using popen2.Popen4. Is there a way to properly specify a >particular working directory when launching a process in python? Switch to using subprocess.Popen and specify the cwd argument. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org

Re: for-else

2008-03-07 Thread Sion Arrowsmith
Jeffrey Barish <[EMAIL PROTECTED]> wrote: >Terry Reedy wrote: >> A for-loop is equivalent to a while loop with the condition 'iterator is >> not exhausted'.  So do_else when that condition is false -- the iterator >> is exhausted. >I think that this is the most important statement in this thread.

Re: Difference between 'function' and 'method'

2008-03-07 Thread Sion Arrowsmith
Gabriel Genellina <[EMAIL PROTECTED]> wrote: >En Thu, 06 Mar 2008 23:46:43 -0200, <[EMAIL PROTECTED]> escribi�: >> [ ... ] >You may look at the SimpleXMLRPCServer class and see how it implements >introspection. It's rather easy (and doesn't require metaclasses nor >decorators nor any other fa

Re: wxPython/wxWidgets ok for production use ?

2008-03-11 Thread Sion Arrowsmith
Stefan Behnel <[EMAIL PROTECTED]> wrote: >Just to make this sound a bit less like FUD: my last experience with wxPython >dates back a couple of years (2004/5?), but back then, we used BoaConstructor >in a project, which crashed a bit too often to do real work with it - and with >crashing I mean cr

Re: How to send a var to stdin of an external software

2008-03-13 Thread Sion Arrowsmith
Benjamin Watine <[EMAIL PROTECTED]> wrote: >How can I do this ? I would like a function like that : > > theFunction ('cat -', stdin=myVar) > >I don't need to get any return value. http://docs.python.org/lib/node534.html says this is spelt myVar = subprocess.Popen(["cat", "-"], stdout=subpr

Re: Get cgi script to begin execution of another script...

2008-03-13 Thread Sion Arrowsmith
sophie_newbie <[EMAIL PROTECTED]> wrote: >Basically I've a CGI script, that when executed by the user, I want to >call another script that does a very long running task (10 hours +) >and print a message on the screen saying that the user will be emailed >on completion of the very long task. The sc

Re: Implementing file reading in C/Python

2009-01-12 Thread Sion Arrowsmith
Grant Edwards wrote: >On 2009-01-09, Sion Arrowsmith wrote: >> Grant Edwards wrote: >>>If I were you, I'd try mmap()ing the file instead of reading it >>>into string objects one chunk at a time. >> You've snipped the bit further on in that sen

Re: Implementing file reading in C/Python

2009-01-12 Thread Sion Arrowsmith
In case the cancel didn't get through: Sion Arrowsmith wrote: >Grant Edwards wrote: >>2GB should easily fit within the process's virtual memory >>space. >Assuming you're in a 64bit world. Me, I've only got 2GB of address >space available to play in

Re: initialising a class by name

2009-01-14 Thread Sion Arrowsmith
Krishnakant wrote: >By the way, is there a kind of global list of modules/classes which are >maintained in a package once the program is loaded into memory? sys.modules is a dict of loaded module objects, keyed by module name. So: >>> getattr(sys.modules["sys"], "version_info") (2, 5, 0, 'final

mimetypes oddity

2009-01-15 Thread Sion Arrowsmith
>>> ge = mimetypes.guess_extension >>> ge('image/jpeg') '.jpe' >>> ge('image/jpeg') '.jpeg' >>> I actually discovered this through explicitly calling mimetypes.init to reload an edited mime.types file between calls to guess_extension, but I think the above scenario makes for more disturbing readi

Re: point class help

2009-01-15 Thread Sion Arrowsmith
r wrote: >here is what i have, it would seem stupid to use a conditional in each >method like this... > >def method(self, other): >if isinstance(other, Point2d): >x, y = origin.x, origin.y >else: >x, y = origin[0], origin[1] >#modify self.x & self.y with x&y Here's an

Re: mimetypes oddity

2009-01-16 Thread Sion Arrowsmith
In article , wrote: >[mimetype weirdness reported] >Sion> Is this a bug? >Might be. Can you file a bug report in the Python issue tracker with a >small script that demonstrates the behavior? http://bugs.python.org/issue4963 (It's tagged as being 2.4 and 2.5 because those are the versio

Re: Newby: how to transform text into lines of text

2009-01-26 Thread Sion Arrowsmith
Diez B. Roggisch wrote: > [ ... ] Your approach of reading the full contents can be >used like this: > >content = a.read() >for line in content.split("\n"): > print line > Or if you want the full content in memory but only ever access it on a line-by-line basis: content = a.readlines() (Ju

Re: Flattening lists

2009-02-05 Thread Sion Arrowsmith
mk wrote: >Brian Allen Vanderburg II wrote: >> I think it may be just a 'little' more efficient to do this: >> >> def flatten(x, res=None): >>if res is None: >> res = [] >>for el in x: >> if isinstance(el, (tuple, list)): >> flatten(el, res) >> else: >>

Re: Very basic question

2008-12-23 Thread Sion Arrowsmith
Sengly wrote: >I would like to calculate a string expression to a float. For example, >I have ('12/5') and I want 2.4 as a result. I tried to use eval but it >only gives me 2 instead of 2.5 py> from __future__ import division py> print eval('12/5') 2.4 py> print eval('12//5') 2 Or switch to 3.0

Re: Implementing file reading in C/Python

2009-01-09 Thread Sion Arrowsmith
Grant Edwards wrote: >On 2009-01-09, Johannes Bauer wrote: >> I've come from C/C++ and am now trying to code some Python because I >> absolutely love the language. However I still have trouble getting >> Python code to run efficiently. Right now I have a easy task: Get a >> file, >If I were you,

Re: xor: how come so slow?

2008-10-17 Thread Sion Arrowsmith
[I think these attributions are right] Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Fri, 17 Oct 2008 22:45:19 +1300, Lawrence D'Oliveiro wrote: >> In message <[EMAIL PROTECTED]>, Steven D'Aprano >> wrote: >>> ... why do you say that xoring random data with other random data >>> produces less ran

Re: question about the textwrap module

2008-10-29 Thread Sion Arrowsmith
Gabriel Genellina <[EMAIL PROTECTED]> wrote: >py> text = 'This is some \t text with multiple\n\n spaces.' >py> import re >py> re.sub(r'\s+', ' ', text) >'This is some text with multiple spaces.' py> ' '.join(text.split()) 'This is some text with multiple spaces.' -- \S -- [EMAIL PRO

Re: [Regex] Search and replace?

2008-11-13 Thread Sion Arrowsmith
Gilles Ganault <[EMAIL PROTECTED]> wrote: >#Extract two bits, and rewrite the HTML >person = re.compile('.+?)>.+?onmouseover="Tip(?P.+?) ') > >output = person.sub('' (note the backslash escaping). Oh, and don't use "input" as a name -- you're shadowing the builtin input function. -- \S -- [EMA

Re: The return code

2008-11-14 Thread Sion Arrowsmith
Jeff McNeil <[EMAIL PROTECTED]> wrote: >> On Nov 13, 6:15 am, "devi thapa" <[EMAIL PROTECTED]> wrote: >> > I am running one service in the python script eg like >> > "service httpd status". >> > If I execute this command in normal shell kernel, the return code is >> > 3. But in the pytho

Re: wildcard match with list.index()

2008-11-19 Thread Sion Arrowsmith
jeff <[EMAIL PROTECTED]> wrote: list >[['a', [], []], ['b', [1, 2], []], ['c', [3, 4], [5, 6]]] list.index(['b',[],[]]) > >ie, would like to match the second element in the list with something >where i just know 'b' is the first element, but have no idea what the >other elements will be:

Re: More elegant way to try running a function X times?

2008-11-19 Thread Sion Arrowsmith
Gilles Ganault <[EMAIL PROTECTED]> wrote: >As a newbie, it's pretty likely that there's a smarter way to do this, >so I'd like to check with the experts: > >I need to try calling a function 5 times. If successful, move on; If >not, print an error message, and exit the program: > >= >success =

Re: Help with dict and iter

2009-04-02 Thread Sion Arrowsmith
mattia wrote: > So, I'm looking for a way to "reset" the next() value every >time i complete the scan of a list. itertools.cycle ? -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: simple iterator question

2009-04-02 Thread Sion Arrowsmith
Neal Becker wrote: >How do I interleave 2 sequences into a single sequence? > >How do I interleave N sequences into a single sequence? itertools.chain(*itertools.izip(*Nsequences)) -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: dict is really slow for big truck

2009-04-29 Thread Sion Arrowsmith
wrote: >On Apr 28, 2:54 pm, forrest yang wrote: >> for line in open(file) >>    arr=line.strip().split('\t') >>    dict[line.split(None, 1)[0]]=arr > >Keys are integers, so they are very efficiently managed by the dict. The keys aren't integers, though, they're strings. Though I don't think tha

Re: string processing question

2009-05-01 Thread Sion Arrowsmith
Kurt Mueller wrote: >:> python -c 'print unicode("ä", "utf8")' >ä > >:> python -c 'print unicode("ä", "utf8")' | cat >Traceback (most recent call last): > File "", line 1, in >UnicodeEncodeError: 'ascii' codec can't encode characters in position >0-1: ordinal not in range(128) $ python -c 'imp

Re: object query assigned variable name?

2009-05-05 Thread Sion Arrowsmith
John O'Hagan wrote: >I can see that it's tantalizing, though, because _somebody_ must know about >the assignment; after all, we just executed it! Except we haven't, if we're talking about reporting from the object's __init__: >>> class Brian: ... def __init__(self): ... print "I'm

Re: for with decimal values?

2009-05-05 Thread Sion Arrowsmith
Gabriel Genellina wrote: >En Sun, 03 May 2009 17:41:49 -0300, Zentrader >escribió: >> There is no need for a function or a generator. A for() loop is a >> unique case of a while loop >> ## for i in range(-10.5, 10.5, 0.1): >> ctr = -10.5 >> while ctr < 10.5: >>print ctr >>ctr += 0.1 >

Re: object query assigned variable name?

2009-05-06 Thread Sion Arrowsmith
John O'Hagan wrote: >I guess what I meant was that if I type: > >brian = Brian() > >in the python shell and then hit return, it seems to me that _somewhere_ (in >the interpreter? I have no idea how it's done) it must be written that the >new Brian object will later be assigned the name "brian",

Re: Performance java vs. python

2009-05-21 Thread Sion Arrowsmith
Duncan Booth wrote: >namekuseijin wrote: >> I find it completely unimaginable that people would even think >> suggesting the idea that Java is simpler. It's one of the most stupidly >> verbose and cranky languages out there, to the point you can't really do >> anything of relevance without a

Re: Performance java vs. python

2009-05-21 Thread Sion Arrowsmith
Lie Ryan wrote: >Sion Arrowsmith wrote: >> Once, when faced with a rather hairy problem that client requirements >> dictated a pure Java solution for, I coded up a fully functional >> prototype in Python to get the logic sorted out, and then translated >> it. [And it

Re: python's setuptools (eggs) vs ruby's gems survey/discussion

2008-06-03 Thread Sion Arrowsmith
Carl Banks <[EMAIL PROTECTED]> wrote: >1. setuptools will download and install dependencies on the user's >behalf, without asking, by default. It will *attempt* to download etc. etc. on the assumption that you have convenient, fast network connection. If you don't My experience is getting on

Re: 'string'.strip(chars)-like function that removes from the middle?

2008-06-17 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Terry Reedy wrote: >> >>> 'abcde'.translate(str.maketrans('','','bcd')) >> 'ae' >You should mention that you are using Python 3.0 ;) >The 2.5 equivalent would be > u"abcde".translate(dict.fromkeys(map(ord, u"bcd"))) >u'

Re: numeric emulation and __pos__

2008-07-09 Thread Sion Arrowsmith
Ethan Furman <[EMAIL PROTECTED]> wrote: >Anybody have an example of when the unary + actually does something? I've seen it (jokingly) used to implement a prefix increment operator. I'm not going to repeat the details in case somebody decides it's serious code. -- \S -- [EMAIL PROTECTED] -- http

Re: Allow tab completion when inputing filepath?

2008-07-10 Thread Sion Arrowsmith
Keith Hughitt <[EMAIL PROTECTED]> wrote: >> Keith Hughitt wrote: >> > [ ... ] I have >> > found some ways to enable tab completion for program-related commands, >> > but not for system filepaths. >Currently Unix/Console. What's wrong with the readline module? http://docs.python.org/lib/module-re

Re: User-defined exception: "global name 'TestRunError' is not defined"

2008-07-10 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: >I'm using some legacy code that has a user-defined exception in it. > >The top level program includes this line > >from TestRunError import * > >It also imports several other modules. These other modules do not >explicitly import TestRun

Re: One step up from str.split()

2008-07-15 Thread Sion Arrowsmith
Joel Koltner <[EMAIL PROTECTED]> wrote: >I normally use str.split() for simple splitting of command line arguments, but >I would like to support, e.g., long file names which-- under windows -- are >typically provided as simple quoted string. E.g., > >myapp --dosomething --loadthis "my file name.

Re: Execution speed question

2008-07-28 Thread Sion Arrowsmith
Suresh Pillai <[EMAIL PROTECTED]> wrote: > [ ... ] is >there any way to iterate over the items in a set other than converting to >a list or using the pop() method. Er, how about directly iterating over the set? -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ "Frankly I have no

Re: xml.dom's weirdness?

2008-07-28 Thread Sion Arrowsmith
Stefan Behnel <[EMAIL PROTECTED]> wrote: >Using my system Python (2.5.1 on Ubunutu Gutsy): > > $ strace -e open python -c '' 2>&1 | wc -l > 551 > $ strace -e open python -c '<><<' 2>&1 | wc -l > 4631 > >Using a self-built Python I have lying around: > > $ strace -e open python2.3 -c '' 2>&1 |

Re: Continuous integration for Python projects

2008-07-29 Thread Sion Arrowsmith
Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >Hussein B wrote: >> Please correct my if I'm wrong but it seems to me that the major >> continuous integration servers (Hudson, CruiseControl, TeamCity ..) >> don't support Python based application. >> It seems they mainly support Java, .NET and Ruby. >>

Re: Build tool for Python

2008-07-30 Thread Sion Arrowsmith
Hussein B <[EMAIL PROTECTED]> wrote: >Apache Ant is the de facto building tool for Java (whether JSE, JEE >and JME) application. >With Ant you can do what ever you want: [ ... ] ... bash your head against your desk for hours trying to make sense of its classloader system, struggle for days on end

Re: Native Code vs. Python code for modules

2008-07-30 Thread Sion Arrowsmith
alex23 <[EMAIL PROTECTED]> wrote: >On Jul 30, 1:56=A0pm, koblas <[EMAIL PROTECTED]> wrote: >> Ruby has been getting pummeled for the last year or more on the >> performance subject. =A0They've been working hard at improving it. =A0Fro= >m >> my arm chair perspective Python is sitting on it's laure

Re: very large dictionary

2008-08-01 Thread Sion Arrowsmith
Simon Strobl <[EMAIL PROTECTED]> wrote: >I tried to load a 6.8G large dictionary on a server that has 128G of >memory. I got a memory error. I used Python 2.5.2. How can I load my >data? Let's just eliminate one thing here: this server is running a 64-bit OS, isn't it? Because if it's a 32-bit OS

Re: module import search path strangeness

2008-08-12 Thread Sion Arrowsmith
Peter Otten <[EMAIL PROTECTED]> wrote: >tow wrote: >> sys.path.append(os.path.join(project_directory, os.pardir)) >> project_module = __import__(project_name, {}, {}, ['']) >> sys.path.pop() >Ouch. I presume that "Ouch" is in consideration of what might happen if the subject of the __

Re: newb loop problem

2008-08-13 Thread Sion Arrowsmith
Dave <[EMAIL PROTECTED]> wrote: >hitNum = 0 >stopCnt = 6 + hitNum >offSet = 5 > >for i in range(0,10,1): The step argument to range defaults to 1: it's tidier to omit it. Similarly, the start argument defaults to 0, so you can drop that too. for i in range(10): > for x in range(hitNum,len

Re: Can't do a multiline assignment!

2008-04-17 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >In Python, you usually can use parentheses to split something over >several lines. But you can't use parentheses for an assignment of >several lines. Yes you can, you just need an iterable of the right length on the other side for the tuple unpacking to work: >>> (CON

Re: Simple unicode-safe version of str(exception)?

2008-04-29 Thread Sion Arrowsmith
Russell E. Owen <[EMAIL PROTECTED]> wrote: >No. e.message is only set if the exeption object receives exactly one >argument. And not always then: >>> e1 = Exception(u"\u00fe") >>> e1.message Traceback (most recent call last): File "", line 1, in ? AttributeError: Exception instance has no attr

Re: file data to list

2008-08-29 Thread Sion Arrowsmith
Emile van Sebille <[EMAIL PROTECTED]> wrote: >data = zip(*[xx.split() for xx in open('data.txt').read().split("\n")]) Files are iterable: data = zip(*[xx.rstrip().split() for xx in open('data.txt')]) saves you creating the extra intermediate list resulting from split("\n"). -- \S -- [EMAIL PR

Re: max(), sum(), next()

2008-09-03 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Empty Python lists [] don't know the type of the items it will >contain, so this sounds strange: > sum([]) >0 >>> help(sum) sum(...) sum(sequence, start=0) -> value >>> sum(range(x) for x in range(5)) Traceback (most recent call last): File "", line 1, in

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Sion Arrowsmith
josh logan <[EMAIL PROTECTED]> wrote: >sorted(P) # throws TypeError: unorderable types Player() < Player() > >The sorted function works when I define __lt__. >I must be misreading the documentation, because I read for the >documentation __cmp__ that it is called if none of the other rich >comparis

Re: Can I use a conditional in a variable declaration?

2006-03-21 Thread Sion Arrowsmith
Ron Adam <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> I want the equivalent of this: >> >> if a == "yes": >>answer = "go ahead" >> else: >>answer = "stop" >> >> in [a] more compact form: >I sometimes find it useful to do: > > answers = {True: "go ahead", False: "stop"} >

Can XML-RPC performance be improved?

2006-03-21 Thread Sion Arrowsmith
I've got an established client-server application here where there is now a need to shovel huge amounts of data (structured as lists of lists) between the two, and the performance bottleneck has become the amount of time spent parsing XML (it's taking 100% CPU on one or other end of the connection

Re: don't understand popen2

2006-03-23 Thread Sion Arrowsmith
Martin P. Hellwig <[EMAIL PROTECTED]> wrote: >std_out, std_in = popen2.popen2("F:\coding\pwSync\popen_test\testia.py") ^^ Your problem is, I suspect, nothing to do with popen2(), which is supported by the fact that the only thing other th

Re: Can XML-RPC performance be improved?

2006-03-23 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: > Diez> Sion Arrowsmith wrote: >>> I've got an established client-server application here where there >>> is now a need to shovel huge amounts of data (structured as lists of >>> lists) between the tw

Re: Default/editable string to raw_input

2006-03-23 Thread Sion Arrowsmith
Sybren Stuvel <[EMAIL PROTECTED]> wrote: >Paraic Gallagher enlightened us with: >> While I agree in principal to your opinion, the idea is that an >> absolute moron would be able to configure a testcell with smallest >> amount of effort possible. >Then explain to me why learning how to use your pr

Re: Can XML-RPC performance be improved?

2006-03-23 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Steve> I suppose there *was* a good reason for using XML-RPC in the >Steve> first place? >I don't know about the OP, but in my case it was a drop-dead simple >cross-language RPC protocol. I am the OP and *I* don't know if there was a good reason for using XML-R

Re: don't understand popen2

2006-03-24 Thread Sion Arrowsmith
Kent Johnson <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> (and please avoid the abuse of raw strings for Windows paths). >Why do you consider that abuse of raw strings? I consider it abuse because it's not what they were invented for. I consider discouraging i

Re: problems with looping, i suppose

2006-03-28 Thread Sion Arrowsmith
John Salerno <[EMAIL PROTECTED]> wrote: >Does what I originally pasted in my message look incorrect? To me, it >all seems indented properly. Yes. Somewhere or other you've got your tabstop set to 4, and python treats literal tabs as being of equivalent indent to 8 spaces. As does my newsreader,

Re: in-place string reversal

2006-03-28 Thread Sion Arrowsmith
Sathyaish <[EMAIL PROTECTED]> wrote: >How would you reverse a string "in place" in python? > [ ... ] >Forget it! I got the answer to my own question. Strings are immutable, >*even* in python. I'm not sure what that "*even*" is about, but glad that "You can't, strings are immutable" is a satisfacto

Re: What's the best way to learn perl for a python programmer?

2006-03-28 Thread Sion Arrowsmith
Magnus Lycka <[EMAIL PROTECTED]> wrote: >The thing that really bit me when I tried to go back to Perl after >years with Python was dereferencing. Completely obvious things in >Python, such as extracting an element from a list inside a dict in >another list felt like black magic. Not that long ago

Re: in-place string reversal

2006-03-28 Thread Sion Arrowsmith
Felipe Almeida Lessa <[EMAIL PROTECTED]> wrote: >Em Ter, 2006-03-28 às 16:03 +0100, Sion Arrowsmith escreveu: >> >>> "".join(reversed("foo")) >$ python2.4 -mtimeit '"".join(reversed("foo"))' >10 loo

Re: how to comment lot of lines in python

2006-04-03 Thread Sion Arrowsmith
Eric Deveaud <[EMAIL PROTECTED]> wrote: >some moderns editors allow you to comment/uncomment a selected Bunch >of lines of code Out of curiousity, is there a modern editor which *doesn't* allow you to comment/uncomment a selected bunch of lines of code? -- \S -- [EMAIL PROTECTED] -- http://ww

Re: string building

2006-04-03 Thread Sion Arrowsmith
John Salerno <[EMAIL PROTECTED]> wrote: >Out of curiosity, is there any kind of equivalent in Python to the >StringBuilder class in C#? Here's a quick description from the .NET >documentation: > >"This class represents a string-like object whose value is a mutable >sequence of characters. The v

Re: using range() in for loops

2006-04-05 Thread Sion Arrowsmith
AndyL <[EMAIL PROTECTED]> wrote: >Paul Rubin wrote: >> Normally you'd use range or xrange. range builds a complete list in >> memory so can be expensive if the number is large. xrange just counts >> up to that number. >so when range would be used instead of xrange. if xrange is more >efficient,

Re: shelve and ".bak .dat .dir" files

2006-04-06 Thread Sion Arrowsmith
Michele Petrazzo <[EMAIL PROTECTED]> wrote: >I'm trying a script on a debian 3.1 that has problems on shelve library. >The same script work well on a fedora 2 and I don't know why it create >this problem on debian: > [ ... ] >Now I see that shelve create not my file, but three files that has the

Re: pre-PEP: The create statement

2006-04-06 Thread Sion Arrowsmith
Kay Schluehr <[EMAIL PROTECTED]> wrote: >Steven Bethard wrote: >> Python-Version: 2.6 >Have you a rough estimation how many modules will be broken when >"create" is introduced as a keyword? A quick scan of the standard library suggests that it will have a grand total of 3 modules requiring a fix (

Re: pre-PEP: The create statement

2006-04-06 Thread Sion Arrowsmith
Michele Simionato <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> A quick scan of the standard library suggests that it will have >> a grand total of 3 modules requiring a fix (it's a method name >> in imaplib and a named argument in a couple of places in b

Re: shelve and ".bak .dat .dir" files

2006-04-07 Thread Sion Arrowsmith
Michele Petrazzo <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> This is a documented behaviour of shelve: > [ open(filename) may create files with names based on filename + ext ] >(and I fail to understand why >> it is a problem). >Because: >1) I pass

Re: passing argument to script

2006-04-07 Thread Sion Arrowsmith
Daniel Nogradi <[EMAIL PROTECTED]> wrote: >If you execute your script from the command line on Linux you need to >enclose it in quotation marks otherwise your shell will interfere. So >you need to invoke your program as > >python yourscript.py "ABCE-123456 ABC_DEF_Suggest(abc def ghi).txt" Same i

Re: About classes and OOP in Python

2006-04-10 Thread Sion Arrowsmith
fyhuang <[EMAIL PROTECTED]> wrote: > [ ... ] no such thing as a private variable. Any >part of the code is allowed access to any variable in any class, and >even non-existant variables can be accessed: they are simply created. You're confusing two issues: encapsulation and dynamic name binding. Yo

Re: Characters contain themselves?

2006-04-11 Thread Sion Arrowsmith
Graham Fawcett <[EMAIL PROTECTED]> wrote: >You could always use an "is-proper-subset-of" function, which is closer >to the intent of your algorithm. Using Jamitzky's very clever infix >recipe [1], you can even write it as an infix operator: > >#Jamitzky's infix-operator class, abbreviated >class I

Re: quiet conversion functions

2006-04-13 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >def CFloat(value): > try: > value = float(value) > except (ValueError, TypeError): > value = 0 > return value >>> type(CFloat(None)) I think you want value = 0.0 . And you might also want to consider what errors

Re: list.clear() missing?!?

2006-04-13 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >except that arguments along the line of "if the syntax is not obj.method(), >it's not OO enough" are likely to be mostly ignored. > >(nobody's going to be impressed by yet another "len(obj) isn't OO" variant) Does that suggest that what's needed is clear(o

Re: Variable class instantiation

2009-12-11 Thread Sion Arrowsmith
Steven D'Aprano wrote: >thisModule = __import__(__name__) >classToUse = thisModule.__dict__['C1'] Any reason to prefer this over: classToUse = getattr(thisModule, 'C1') ? (I think, for a module, they should do exactly the same thing. Personally, I prefer keeping explicit references to __specia

Re: Raw string substitution problem

2009-12-18 Thread Sion Arrowsmith
Gregory Ewing wrote: >MRAB wrote: >> Regular expressions and replacement strings have their own escaping >> mechanism, which also uses backslashes. >This seems like a misfeature to me. It makes sense for >a regular expression to give special meanings to backslash >sequences, because it's a sublan

Re: Simple if-else question

2009-10-01 Thread Sion Arrowsmith
MRAB wrote: >> [ for ... else ] >The example that makes it clearest for me is searching through a list >for a certain item and breaking out of the 'for' loop if I find it. If I >get to the end of the list and still haven't broken out then I haven't >found the item, and that's when the else statem

Re: Help with code = Extract numerical value to variable

2009-10-23 Thread Sion Arrowsmith
Steve wrote: >If there is a number in the line I want the number otherwise I want a >0 >I don't think I can use strip because the lines have no standards What do you think strip() does? Read http://docs.python.org/library/stdtypes.html#str.lstrip *carefully* (help(''.lstrip) is slightly ambiguou

Re: Simple list problem that's defeating me!

2010-06-24 Thread Sion Arrowsmith
Mark Lawrence wrote: >On 22/06/2010 15:06, Neil Webster wrote: >> I have a list of lists such as [[a,2,3,4],[b,10,11,12], [a,2,3,4]]. I >> need to combine the two lists that have the same first character in >> this example 'a'. In reality there are 656 lists within the list. >> [ ... ] >My simp

Re: N00b question: matching stuff with variables.

2010-06-29 Thread Sion Arrowsmith
Stephen Hansen wrote: >On 6/28/10 10:29 AM, Ken D'Ambrosio wrote: >> for line in file: >> match = re.search((seek)",(.*),(.*)", line) # Stuck here > [ ... ] > name, foo, bar = line.split(",") > if seek in name: > # do something with foo and bar > >That'll return True if the wo

Re: Why aren't OrderedDicts comparable with < etc?

2009-07-17 Thread Sion Arrowsmith
Jack Diederich wrote: >It isn't an OrderedDict thing, it is a comparison thing. Two regular >dicts also raise an error if you try to LT them. Since when? Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information

Re: Why aren't OrderedDicts comparable with < etc?

2009-07-20 Thread Sion Arrowsmith
Terry Reedy wrote: >Sion Arrowsmith wrote: >> Jack Diederich wrote: >>> It isn't an OrderedDict thing, it is a comparison thing. Two regular >>> dicts also raise an error if you try to LT them. >> Python 2.5.2 >>>>> d1 = dict((str(i), i) f

Re: Python docs disappointing - group effort to hire writers?

2009-08-08 Thread Sion Arrowsmith
Terry Reedy wrote: >RayS wrote: >> http://www.php.net/manual/en/language.types.array.php is a prime example >> [ ... ] >I consider consider this to an unreadable mishmash. [compared to] > something compact and readable. Are you talking about the language or the documentation? 9-) (Actually, th

Re: Remove empty strings from list

2009-09-15 Thread Sion Arrowsmith
Bruno Desthuilliers wrote: > >> mylist = line.strip().split() > >will already do the RightThing(tm). So will mylist = line.split() -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: Why use "locals()"

2009-09-15 Thread Sion Arrowsmith
Sean DiZazzo wrote: >> def print_item(item): >>      description = textwrap.fill(item.description, 40) >>      short = item.description.split('\n', 1)[0] >>      code = str(item.id).zfill(6) >>      print "%(code)s %(short)s\n%(description)s\n" % locals() > >I see the use of that, but according t

Re: Why use "locals()"

2009-09-16 Thread Sion Arrowsmith
Gabriel Genellina wrote: > escribió: >> What I'm not clear about is under what circumstances locals() does >> not produce the same result as vars() . > >py> help(vars) >Help on built-in function vars in module __builtin__: > >vars(...) > vars([object]) -> dictionary > > Without arguments,

Re: Not this one the other one, from a dictionary

2009-09-22 Thread Sion Arrowsmith
Vlastimil Brom wrote: other_key = (set(data_dict.iterkeys()) - set([not_wanted_key,])).pop() other_key = set(data_dict.iterkeys()).difference([not_wanted]).pop() saves you the construction of an unnecessary set instance. At the cost of a bit more verbosity, you can get rid of a second set:

Re: if the else short form

2010-09-30 Thread Sion Arrowsmith
Andreas Waldenburger wrote: > >[ ... ] >Boolean values behave like the values 0 and 1, respectively, in >almost all contexts, the exception being that when converted to a >string, the strings

Re: direct print to log file

2010-10-06 Thread Sion Arrowsmith
Dave Angel wrote: >If you want to be able to go back to the original, then first bind >another symbol to it. Or restore from sys.__stdout__, as long as you're sure that nothing else has rebound sys.stdout first (or don't mind clobbering it). -- \S under construction -- http://mail.pytho

<    1   2   3   4   >