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

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: 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: 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: 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: 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: 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 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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

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: 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

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: 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-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: 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: 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: 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: 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: [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: 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: 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 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: '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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: How to get memory size/usage of python object

2008-01-09 Thread Sion Arrowsmith
Santiago Romero <[EMAIL PROTECTED]> wrote: > Is there a way to check the REAL size in memory of a python object? > > Something like > >> print sizeof(mylist) > [ ... ] Would you care to precisely define "REAL size" first? Consider: >>> atuple = (1, 2) >>> mylist = [(0, 0), atuple] Should sizeo

Re: "Canonical" way of deleting elements from lists

2008-01-09 Thread Sion Arrowsmith
Robert Latest <[EMAIL PROTECTED]> wrote: > BTW, where can I find all methods of the built-in types? >Section 3.6 only talks about strings and mentions the list append() method >only in an example. Am I too stupid to read the manual, or is this an >omission? 3.6 talks about features common to a

Re: dictionary/hash and '1' versus 1

2008-01-07 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >In Java you can add the number 1 to a string, and have it >automatically converted to string before the string join... What do >you think of that feature? "-%s" % 1 -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards pe

Re: python interfaces

2008-01-07 Thread Sion Arrowsmith
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith a écrit : >(snip rant about Java's "interfaces") > >Hem... Zope3's "interface" system is not exactly the same thing as >Java's one. Yeah, I was in need of letting off some st

Re: Details about pythons set implementation

2008-01-04 Thread Sion Arrowsmith
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: >BTW if you're using C++, why not simply use std::set? Because ... how to be polite about this? No, I can't. std::set is crap. The implementation is a sorted sequence -- if you're lucky, this is a heap or a C array, and you've got O(log n) performance. But

Re: python interfaces

2008-01-04 Thread Sion Arrowsmith
hyperboreean <[EMAIL PROTECTED]> wrote: >Why doesn't python provide interfaces trough its standard library? Because they're pointless. Java interfaces are a hack around the complexities of multiple inheritence. Python does multiple inheritence Just Fine (give or take the subtleties of super()) so

Re: Extract a number from a complicated string

2007-12-21 Thread Sion Arrowsmith
Gerardo Herzig <[EMAIL PROTECTED]> wrote: >>My problem is that I need to extract from this string the number. For >>instance in xyz.vs.1-81_1 I have to extract the number 81, and in >>xyz.vs.1-1234_1 I need to get the number 1234. >> >>What is the easiest way of doing this ? >If the strings looks

Re: Passing by reference

2007-12-21 Thread Sion Arrowsmith
Michael Sparks <[EMAIL PROTECTED]> wrote: >def bar(): >global x >x[0] += " another" >print id(x[0]) ... and for bonus marks, explain why the "global x" in this function is not required. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towar

Re: Another newbie design question

2007-12-18 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I've designed a language, Decaf, for beginners. I've got block >comments but not multi-line strings. > >If you can only have one or the other, which is more helpful? Given a one-or-the-other choice, any editor worth using can do "comment/uncomment region", and if only

Re: Newbie NameError problem

2007-12-12 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I don't understand what I don't understand in the following: > [ ... ] You've already got an answer as to what's causing your name error. But that's not your only problem. It looks like you need an introduction to enumerate(): for line_ptr, text in enumerate(file('sam

Re: which configparse?

2007-12-07 Thread Sion Arrowsmith
Neal Becker <[EMAIL PROTECTED]> wrote: >I've looked at configparse, cfgparse, iniparse. > >configparse looks like what I want, but it seems last commit was >2years >ago. > >What is the best choice? ConfigParser is the battery included in the standard library. If you're planning on distributing yo

Re: JSON

2007-12-07 Thread Sion Arrowsmith
Joshua Kugler <[EMAIL PROTECTED]> wrote: >Known issue. See: >http://blog.extracheese.org/2007/07/when-json-isnt-json.html > >Neither project has fixed it it seems. Not sure which is actually >the "correct" way to do it, but it would be nice if they would agree. I think it's pretty clear (not ju

Re: may be a bug in string.rstrip

2007-11-23 Thread Sion Arrowsmith
Scott SA <[EMAIL PROTECTED]> wrote: >>>> string.replace('120.exe','.exe','') >'120' Don't use string.replace(), use the replace method of strings: >>> '120.exe'.replace('.exe', '') '120' >... but it has a side-effect of mid-string replacements: > >>>> string.replace('123.exe.more','.

Re: attaching someconfusing results in webbrowser.open on gnulinux

2007-11-01 Thread Sion Arrowsmith
krishnakant Mane <[EMAIL PROTECTED]> wrote: > when I give webbrowser.open("file:///home/krishna/documents/tut.html") >on python prompt I get true as return value but web browser (firefox ) >opens with page not found. >and the address bar shows the following address which indeed is wrong. >file:///h

Re: Creating a temporary file in Python

2007-10-31 Thread Sion Arrowsmith
looping <[EMAIL PROTECTED]> wrote: >I want to create a temporary file, read it in an external command and >finally delete it (in Windows XP). > >I try to use tempfile module but it doesn't work, the file couldn't be >open by my other process (error like: SP2-0310: unable to open file "c: >\docume~

Re: Cross-platform GUI development

2007-10-26 Thread Sion Arrowsmith
bramble <[EMAIL PROTECTED]> wrote: > [ GTK is ] free >software, so contributors can try and make the L&F more native if it's >really that big a deal. But the people who care about Windows native L&F are not the people with the resources (time, money, probably experience) to address this issue. An

Re: "".join(string_generator()) fails to be magic

2007-10-11 Thread Sion Arrowsmith
Matt Mackal <[EMAIL PROTECTED]> wrote: >I have an application that occassionally is called upon to process >strings that are a substantial portion of the size of memory. For >various reasons, the resultant strings must fit completely in RAM. Do you mean physical RAM, or addressable memory? If the

Re: Python "implements " equivalent?

2007-10-05 Thread Sion Arrowsmith
Grant Edwards <[EMAIL PROTECTED]> wrote: > try: > myobj.feature1() > except AttributeError: > print "object doesn't implement feature1" > >isn't correct, since an unhandled AttributeError generated by >the feature1 method will print "object doesn't implement >feature1". I'd be

Re: super() doesn't get superclass

2007-09-19 Thread Sion Arrowsmith
Ben Finney <[EMAIL PROTECTED]> wrote: > If a function is named 'super' and operates on >classes, it's a pretty strong implication that it's about >superclasses. But it doesn't (under normal circumstances) operate on classes. It operates on an *instance*. And what you get back is a (proxy to) a su

Re: Sets in Python

2007-09-19 Thread Sion Arrowsmith
sapsi <[EMAIL PROTECTED]> wrote: > Why can't lists be hashed? Several people have answered "because they're mutable" without explaining why mutability precludes hashing. So: Consider a dict (dicts have been in Python a *lot* longer than sets, and have the same restriction) which allowed lists as

Re: printing list containing unicode string

2007-09-11 Thread Sion Arrowsmith
Xah Lee <[EMAIL PROTECTED]> wrote: > " It's very wasteful of space. In most texts, the majority of the >code points are less than 127, or less than 255, so a lot of space is >occupied by zero bytes. " > >Not true. In Asia, most chars has unicode number above 255. Considered >globally, *possibly*

Re: /dev/null as a file-like object, or logging to nothing

2007-09-10 Thread Sion Arrowsmith
Torsten Bronger <[EMAIL PROTECTED]> wrote: >Marc 'BlackJack' Rintsch writes: >> `os.devnull`? >Yes, but I wasn't really sure how portable it is, in particular, on >Windows. Windows has a NUL: device which behaves like /dev/null . os.devnull is a wrapper around whatever the system-provided null de

Re: FCGI app reloading on every request

2007-09-05 Thread Sion Arrowsmith
John Nagle <[EMAIL PROTECTED]> wrote: >Tried putting this in the .htaccess file: > > >SetHandler fcgid-script >Options ExecCGI >allow from all > > > >ErrorDocument 403 "File type not supported." > > > Even with that, a ".foo" file gets executed as a CGI script, >and so does a ".fcgi" file.

  1   2   3   4   >