Re: While loop - print several times but on 1 line.

2006-01-26 Thread Sion Arrowsmith
Danny <[EMAIL PROTECTED]> wrote: >The programs output will be: >text >text >(etc) > >How could I make this print: texttexttexttexttext? >Ive researched and looked through google and so far I can't find >anything that will help (or revelent for that matter). I'm kind of surprised this isn't a FAQ

Re: Code Feedback

2006-02-07 Thread Sion Arrowsmith
mwt <[EMAIL PROTECTED]> wrote: >1) Is this good Python code? What should be changed to make it more >Pythonesque? >while not len(self.stacks) > 0: while not self.stacks: An empty list is considered to be false, hence testing the list itself is the same as testing len(l) > 0 . --

Re: apostrophe or double quote?

2006-02-08 Thread Sion Arrowsmith
Steve Holden <[EMAIL PROTECTED]> wrote: >Huy wrote: >> I've been unable to find information clarifying this but. What is the >> difference between 'somestring' and "somestring"? >It's just easier to have two permitted string quotes. That way, if your >string has an apostrophe in it you can say >

Re: 450 Pound Library Program

2006-02-08 Thread Sion Arrowsmith
mwt <[EMAIL PROTECTED]> wrote: >while len(self.stacks) == 0: To (kind of) repeat myself, the idiomatic Python would be: while not self.stacks: An empty list is considered to be false, hence testing the list itself is the same as testing len(l) > 0 . As someone else has noticed,

Re: Number Format function

2006-02-09 Thread Sion Arrowsmith
Rick Zantow <[EMAIL PROTECTED]> wrote: print number_format( 2312753.4450, 2 ) >2,312,753.44 print number_format( 2312753.4451, 2 ) >2,312,753.45 > >I would expect the first to produce the same results as the second, but, >I suppose because of one of floating point's features, it

Re: how to remove using replace function?

2006-02-09 Thread Sion Arrowsmith
Duncan Booth <[EMAIL PROTECTED]> wrote: >Although I generally advise against overuse of regular expressions, this is >one situation where regular expressions might be useful: [ ... ] nobr = re.compile('\W*\W*', re.I) Agreed (on both counts), but r'\s*\s*' might be better (consider what happ

Re: apostrophe or double quote?

2006-02-09 Thread Sion Arrowsmith
Terry Hancock <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> Just to present a complete picture, not mentioned in this >> thread are triple-quoted strings: >> [ ... ] >Also in the mode of beating a dead horse ... ;-) > >Some people prefer to use single quotes for 'labels' (i.e. a >name wh

Re: Finding the public callables of self

2006-02-09 Thread Sion Arrowsmith
Russell Warren <[EMAIL PROTECTED]> wrote: >Is there any better way to get a list of the public callables of self >other than this? > >myCallables = [] >classDir = dir(self) >for s in classDir: > attr = self.__getattribute__(s) > if callable(attr) and (not s.startswith("_")): >

Re: Determining an operating system's default browser

2006-02-10 Thread Sion Arrowsmith
John McMonagle <[EMAIL PROTECTED]> wrote: >Is there a python module which can determine an operating system's >default web browser application. http://docs.python.org/lib/module-webbrowser.html -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings to

Re: Newbie Q: dynamically assigning object attribute

2006-02-10 Thread Sion Arrowsmith
Ben Wilson <[EMAIL PROTECTED]> wrote: >I would like to dynamically assign object attributes: > >dict = { > a : 1, > b : 2, >} > >for key,val in dict : > obj.key = val > >I've googled to no effect, or maybe I'm needing to be hit with the >appropriately sized clue-by-four. The conventional clue-by-

Re: Little tool - but very big size... :-(

2006-02-22 Thread Sion Arrowsmith
BJ in Texas <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >|| 11MB is seldom a concern for today's machine. >A good windows/microsoft attitude.. :-) I wish 8-( : PID USER PR NI VIRT RES SHR S %CPU %MEMTIME+ COMMAND 3715 root 15 0 288m 128m 154m S 1.0 6.3 14902:4

[OT] Re: number ranges

2006-02-22 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> Colin J. Williams <[EMAIL PROTECTED]> wrote: >>>1. Why not treat '2 to 5' or '(2 to 5)' as a semi-open interval? >I intellectually understand that semi-open intervals >are the only way to go. But reading the words, the part >of my brain that speaks E

Re: No

2006-02-22 Thread Sion Arrowsmith
Gaz <[EMAIL PROTECTED]> wrote: >So, they can not upload the photos by FTP because its too "geek" for >them. And i need to have a standarized form to handle the reports, >because otherwise its a organizational mess. Am I missing something here, or is all you need a on your form? Then you don't wor

Re: except clause not catching IndexError

2006-02-23 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >You mean to say that "except X,Y:" gives different >results to "except (X,Y):"? > [ ... ] >And here I was thinking that commas make tuples, not >brackets. What is happening here? Similar kind of thing to what's happening here: >>> print "Hello,", "wo

Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Sion Arrowsmith
Franz Steinhaeusler <[EMAIL PROTECTED]> wrote: >On Thu, 23 Feb 2006 13:54:50 +, Martin Franklin >>why not use string methods strip, rstrip and lstrip >because this removes only the last spaces, > [given r = 'erewr\r\nafjdskl '] >I want: >'erewr\r\nafjdskl' os.linesep.join(l.rstrip() f

Re: Exception not raised - May be the end

2006-03-03 Thread Sion Arrowsmith
Michele Petrazzo <[EMAIL PROTECTED]> wrote: >some days ago I posted here and say that python "forgot" to raise an >exception, but my code was too long for make some tries possible. >But now I can reproduce the problem into another, little, project: > >www.unipex.it/vario/wxFrameSchedule.py >www.un

Re: Advice needed on __del__

2005-05-10 Thread Sion Arrowsmith
=?ISO-8859-1?Q?Andr=E9_Roberge?= <[EMAIL PROTECTED]> wrote: >If I need to have the user call Evil.destroy() as Evil >is getting out of scope, it would miss the whole point >of teaching about the natural way scope and namespace >work. The problem, it seems to me, is that in Python "scope" applies

Re: Regarding Mail sending smtplib Module

2005-05-11 Thread Sion Arrowsmith
praba kar <[EMAIL PROTECTED]> wrote: >Here I want to avoid this line "Received: from unknown >(HELO prabahar.enmail.com) (59.92.13.47) by >mailserver with SMTP; 11 May 2005 10:09:11 - " How >can I do this? . Why python give this line? . Mail >sending Module in php will not give this type

Re: Just remember that Python is sexy

2005-05-25 Thread Sion Arrowsmith
Scott Kirkwood <[EMAIL PROTECTED]> wrote: >I often can't remember that to remove spaces from a string whether it's >strip() or trim(), and when finding patterns with the re library >whether it's find() or search() and when iterating over key, values of >a dictionary whether it's items() or entries(

Re: Just remember that Python is sexy

2005-05-26 Thread Sion Arrowsmith
Duncan Booth <[EMAIL PROTECTED]> wrote: >Ville Vainio wrote: >>>>>>> "Peter" == Peter Hansen <[EMAIL PROTECTED]> writes: >> Peter> Sion Arrowsmith wrote: >> >> But can you come up with a method for remembering which w

Re: "also" to balance "else" ?

2005-06-14 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Ron Adam wrote: >> True, but I think this is considerably less clear. The current for-else >> is IMHO is reversed to how the else is used in an if statement. >nope. else works in exactly the same way for all statements that >support it: if the controlling

Re: c[:]()

2007-06-01 Thread Sion Arrowsmith
Warren Stringer <[EMAIL PROTECTED]> wrote: >#-- >class do(list): >def __call__(self,*args,**kwargs): >return [f(*args,**kwargs) for f in self] > > >def a(): print 'a called' >def b(): print 'b called' >c = do() >c = [a,b] >do(c[:])() >do(c)()

Re: unknown host

2007-06-01 Thread Sion Arrowsmith
abcd <[EMAIL PROTECTED]> wrote: >I have a linux machine (ip = 10.10.10.8), which can ping other >machines on the same subnet...such as > [ ... ] >If I use socket.gethostbyaddr() I get back results when ip is >10.10.10.1 and 10.10.10.254 but for the other IP addresses >(10.10.10.5, .6, etc) I get b

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > 3/2 => 1 # Usual behavior > some_func(3, 2) => 2 # Wanted def some_func(a, b): return -(-a/b) And people complain about Python's behaviour regarding division of negative integers. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
Hamish Moffatt <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: > def div_ceil(a, b): >> ... if a%b: >> ... return ((a/b)+1) >> ... else: >> ... return (a/b) > >Yes, although it's not as short or as fast (probably as my version): > >def div_ceil(a, b): > return

Re: Python changing keywords name

2007-06-26 Thread Sion Arrowsmith
Gabriel Genellina <[EMAIL PROTECTED]> wrote: >(I hope nobody will abuse this technique... Y perd=F3n a los >hispanoparlantes por lo horrible de la traducci=F3n). Ah, I only spotted this when I came to post a response. And the reason I was going to post a response was that these: >'assert': '

Re: Too many 'self' in python.That's a big flaw in this language.

2007-06-27 Thread Sion Arrowsmith
Neil Cerutti <[EMAIL PROTECTED]> wrote: >On 2007-06-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> From My point,I think this only help python interpreter to >> deside where to look for. Is there anyone know's how to make >> the interpreter find instance name space first? Or any way to >> mak

Re: howto resend args and kwargs to other func?

2007-07-02 Thread Sion Arrowsmith
Frank Swarbrick <[EMAIL PROTECTED]> wrote: >dmitrey wrote: >> Thanks all, I have solved the problem. >Why do people do this without posting what the actual solution is Hey, if we're expected to magically deduce what the problem is without being told an error messages, surely we can magically

Re: Reversing a string

2007-07-05 Thread Sion Arrowsmith
Jan Vorwerk <[EMAIL PROTECTED]> wrote: > [ lots of sensible stuff to discover "reversed" ] > >>> print reversed.__doc__ See also: >>> help(reversed) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towards penguins one way or the other" -- Arth

Re: path backslash escaping trouble

2007-07-10 Thread Sion Arrowsmith
placid <[EMAIL PROTECTED]> wrote: >I have these files; [ ... ] > >MergeTypecodefromlabel >BLnameBUILDMODS >OldLname >BaseVersion6.9.1.24A >RequiredRelease6.10.1.3 >Description >FixRelation >Dependencies >LpAffectedNo >CodeRevi

Re: Interpreting os.lstat()

2007-07-19 Thread Sion Arrowsmith
Adrian Petrescu <[EMAIL PROTECTED]> wrote: print os.stat.__doc__ >stat(path) -> stat result > >Perform a stat system call on the given path. > >I checked the online Python documentation at >http://python.org/doc/1.5.2/lib/module-stat.html Someone else has already pointed out that this is ho

Re: Interpreting os.lstat()

2007-07-20 Thread Sion Arrowsmith
=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >> (a) Running 'stat' is *not the same* as a system call. >Why do you say that? It is *exactly* the same [ ... ] Maybe if stat were implemented as int main(int argc, char** argv) { struct stat so_what_am_I_supposed_to_do_

Re: Pickled objects over the network

2007-07-20 Thread Sion Arrowsmith
Rustom Mody <[EMAIL PROTECTED]> wrote: >Since pickle has problems >-- does not interface well with networking In what way does pickle not interface well with networking? Other than, possibly, security issues which you list as a separate problem with it. I've taken a working XML-RPC system and repl

Re: Interpreting os.lstat()

2007-07-21 Thread Sion Arrowsmith
=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >> But it obviously does a lot of other stuff, including formatting >> the results of the system call for display. >It most decisively does *not* format the results of the system call >"for display". "It" here refers to the p

Re: My python annoyances so far

2007-04-30 Thread Sion Arrowsmith
7stud <[EMAIL PROTECTED]> wrote: >I know what you mean. I always write: > >someStringVar.len > >and then I backspace and retype: > >len(someString). > >But then again, I can never remember whether length is a member or a >method in other languages. ... or whether it's called length, size, count

Re: N00b question on Py modules

2007-05-09 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Thanks a lot for the responses ppl. Python's treatment of global >variables was an eye-opener. I have coded in Java & C/C++ in the past >and there the behaviour is diametrically opposite. How so? Python style gurus discourage use of global variables. So does all the C+

Re: keyword checker - keyword.kwlist

2007-05-10 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: [ ... ] >> Try to change the 'input' variable name with other... >Changed input variable to myInput, but the result is still the same. That was good advice, but isn't going to help here. Because "input" isn't a keyword, it's a builtin. If

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Sion Arrowsmith
Aldo Cortesi <[EMAIL PROTECTED]> wrote: > [ ... ] There is no general way to detect homoglyphs and "convert them to >a normal form". Observe: > >import unicodedata >print repr(unicodedata.normalize("NFC", u"\u2160")) >print u"\u2160" >print "I" FYI, those come out as two very clearly distinct gly

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Sion Arrowsmith
Nick Craig-Wood <[EMAIL PROTECTED]> wrote: >b) Unicode characters would creep into the public interface of public >libraries. I think this would be a step back for the homogeneous >nature of the python community. One could decree that having a non-ASCII character in an identifier would have the

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-15 Thread Sion Arrowsmith
Stefan Behnel <[EMAIL PROTECTED]> wrote: >I don't think all identifiers in the stdlib are >a) well chosen >b) correct English words Never mind the standard library, by my count about 20% of keywords and builtins (excluding exception types) are either not correct English words ('elif', 'chr') or h

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >On Tue, 15 May 2007 09:09:30 +0200, Eric Brunel wrote: >> Joke aside, this just means that I won't ever be able to program math in >> ADA, because I have absolutely no idea on how to do a 'pi' character on >> my keyboard. >Maybe you should find out then?

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-16 Thread Sion Arrowsmith
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: >I still don't like the thought of the horrible mix of "foreign" >identifiers and English keywords, coupled with the English >sentence construction. How do you think you'd feel if Python had less in the way of (conventionally used) English keywords/bu

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-17 Thread Sion Arrowsmith
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: >"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote: >>Hendrik van Rooyen wrote: >>>I still don't like the thought of the horrible mix of "foreign" >>>identifiers and English keywords, couple

Re: How to convert a number to binary?

2007-05-18 Thread Sion Arrowsmith
Lyosha <[EMAIL PROTECTED]> wrote: >On May 17, 11:04 pm, Stargaming <[EMAIL PROTECTED]> wrote: >>dec2bin = lambda x: (dec2bin(x/2) + str(x%2)) if x else '' > [ ... ] >I guess the reason I couldn't come up with something like this was >being brainwashed that lambda is a no-no. > >And python2.5 f

Re: NEWBIE: Extending a For Statement.

2007-05-22 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >mosscliffe: >> if key in xrange (60,69) or key == 3: >I keep seeing again and again code like this, mostly from people not >much expert of Python, but the PEP 260 shows the fast in was removed, >so it's O(n). If you're going to point that out, you should at least also

Re: Rats! vararg assignments don't work

2007-05-30 Thread Sion Arrowsmith
samwyse <[EMAIL PROTECTED]> wrote: >> samwyse wrote: >>>I thought that I'd try this: >>> first, *rest = arglist >>>Needless to say, it didn't work. > [ ... ] >My use-case is (roughtly) this: > first, *rest = f.readline().split() > return dispatch_table{first}(*rest) first, rest = f.re

Re: Use variable in regular expression

2007-08-02 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I know I can use a variable in regular expressions. I want to use a >regex to find something based on the beginning of the string. You're coming from a Perl background, right? No-one else would think of using a regexp for such a simple thing. There are two things you n

Re: is it possible to improve traceback messages ?

2007-08-07 Thread Sion Arrowsmith
Zentrader <[EMAIL PROTECTED]> wrote: >This is the "standard" way AFAIK >.try : >. some_process >.except : >. import trackback, sys >. et, ev, tb = sys.exc_info() >. while tb : >.co = tb.tb_frame.f_code >.print "Filename = " + str(co.co_filename) >.print "Error Line

Re: Help with Dictionaries and Classes requested please.

2007-08-09 Thread Sion Arrowsmith
special_dragonfly <[EMAIL PROTECTED]> wrote: >if key in FieldsDictionary: >FieldsDictionary[key].append(FieldClass(*line.split(","))) >else: >FieldsDictionary[key]=[FieldClass(*line.split(","))] These four lines can be replaced by: FieldsDictionary.setdefau

Re: LEGB rule, totally confused ...

2007-08-14 Thread Sion Arrowsmith
stef mientki <[EMAIL PROTECTED]> wrote: >def Run (): >print X <=== UnboundLocalError: local variable >'X' referenced before assignment >X = X + 1 > >Why do I get the error ? >Printing isn't assigning anything or am I missing something. >Now if I remove "X =

Re: Code design problem

2007-08-29 Thread Sion Arrowsmith
Marco Nawijn <[EMAIL PROTECTED]> wrote: >I have a hard time figuring out an elegant and efficient design for >the following problem. What you want is known as the factory pattern. > [ ... ] I would >like the following (pseudo)-code to work: > >app = Application('patran') # Run o

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.

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: 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: Getting external IP address

2007-03-06 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >I have a PC behind a firewall, and I'm trying to programmatically >determine the IP address visible from outside the firewall. > [ ... ] >Can anyone help me fix that code snippet, or suggest another (better) way >to get the externally visible IP address

Re: Using wildcards with Popen in the Subprocess module

2007-03-16 Thread Sion Arrowsmith
William Hudspeth <[EMAIL PROTECTED]> wrote: > [ ... ] I need to pass multiple filenames to an >executable. The filenames are similar to one another, but differ only >slightly, hence the use of the wildcard. The executable works well from >the command line if I pass in a wildcard filename, but Pope

Re: Eureka moments in Python

2007-03-16 Thread Sion Arrowsmith
Paul McGuire <[EMAIL PROTECTED]> wrote: >On Mar 13, 2:16 am, Steven D'Aprano <[EMAIL PROTECTED]> >wrote: >> I'd be interested in hearing people's stories of Eureka moments in Python, >> moments where you suddenly realise that some task which seemed like it >> would be hard work was easy with Python

Re: Eureka moments in Python

2007-03-20 Thread Sion Arrowsmith
Sion Arrowsmith <[EMAIL PROTECTED]> wrote: >This is more a "batteries included" eureka moment than a Python one, >but writing a fetchmail substitute in 6 lines was an eye-opener. On Fri, Mar 16, 2007 at 01:23:14PM -0500, someone emailed: [This is a newsgroup/mailing list

Re: #!/usr/bin/env python > 2.4?

2007-03-21 Thread Sion Arrowsmith
Jon Ribbens <[EMAIL PROTECTED]> wrote: >You want: > > if sys.hexversion < 0x020400f0: >... error ... "Readability counts." if sys.version_info < (2, 4): ... error ... -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins o

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: 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: 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: "".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: 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: 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: 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: replacing substrings within strings

2007-02-14 Thread Sion Arrowsmith
amadain <[EMAIL PROTECTED]> wrote: >I was wondering if there was a nicer way to swap the first 2 >characters in a string with the 4th and 5th characters other than: > >darr=list("010203040506") >aarr=darr[:2] >barr=darr[4:6] >darr[:2]=barr >darr[4:6]=aarr >result="".join(darr) darr=list("010203040

Re: os.system and quoted strings

2007-02-28 Thread Sion Arrowsmith
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: import os.path os.path.join("c:", >..."Documents and Settings", >..."somepath") >'c:Documents and Settings\\somepath' > >Hmmm, a quick test with > >dir "e:userdata" > >worked, so the top level \ may not be needed... "drive:" is

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: 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: 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: 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: 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: 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: 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: items in an array

2006-04-19 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >I can get list to be how I want it if I use the index value as follows: > > list = ("%s" + "," + "%s", ...) % (list_array[0], list_array[1], ... > >However, the list_array will never contain a constant number of items. >So my dilema is how to loop/iter

Re: multiline comments

2006-04-19 Thread Sion Arrowsmith
Edward Elliott <[EMAIL PROTECTED]> wrote: >On top of that, the expressive power of nested comments seems greater than >an endless string of ^#s. Sometimes it's just easier to see what's going on. Really? Under what circumstances is it easier to see what's going on with start/end comments than w

Re: multiline comments

2006-04-19 Thread Sion Arrowsmith
Jorge Godoy <[EMAIL PROTECTED]> wrote: >Is it harder to remove "n" lines of code commented out with "#" than "n" >lines of multiline commented code? How? I'd say it's harder to remove the latter, due to having to search for the end of comment sequence, rather than simply looking for where the bl

Re: multiline comments

2006-04-20 Thread Sion Arrowsmith
Edward Elliott <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> Really? Under what circumstances is it easier to see what's going on >> with start/end comments than with comment-to-end-of-line? >Off the top of my head: > [ ... ] It appears to me that our fu

Re: how to append to a list twice?

2006-04-21 Thread Sion Arrowsmith
John Salerno <[EMAIL PROTECTED]> wrote: >If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] >(where each item is repeated twice after the first one), how might I do >that most efficiently? > >Right now I have this: > >series = [100] >for x in range(10): # just for testing

Re: The whitespaceless frontend

2006-04-26 Thread Sion Arrowsmith
Edward Elliott <[EMAIL PROTECTED]> wrote: >If compactness is all you want, shorten self to s. Personally I like 'me' >as it's both shorter and more vernacular: > >def do_GET (me): >me.send_response (200, "ok") Absolutely. I've written quite a lot of code (which I wasn't expecting anyone else

Re: Inherit from array

2006-04-26 Thread Sion Arrowsmith
TG <[EMAIL PROTECTED]> wrote [something like]: >from array import array >class Vector(array): >def __init__(self,size): >array.__init__('f') > >v = Vector('c') >print repr(v) > >will output : > >array('c') Is this a case of new-sytle classes being confusing? Because I'm certainly confu

Re: python strings

2006-05-04 Thread Sion Arrowsmith
Bryan <[EMAIL PROTECTED]> wrote: > >>> s = '\x00' > >>> s[0] == chr(0) >True That's a little excessive when: >>> s = '\0' >>> s[0] == chr(0) True Oh, and to reassure the OP that that null really is *in* the string: >>> len(s) 1 -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ _

Re: Python function returns:

2006-05-04 Thread Sion Arrowsmith
Michael Yanowitz <[EMAIL PROTECTED]> wrote: > In Python, there does not seem to be an easy way to have functions return >multiple values except it can return a list such as: >strHostname, nPortNumber, status = get_network_info (strIpAddress, >strHostname, >

Re: Swaying A Coder Away From Python

2006-05-04 Thread Sion Arrowsmith
>On 4 May 2006 05:24:40 -0700, BartlebyScrivener <[EMAIL PROTECTED]> wrote: >> I'm picking this up via clp on Google Groups. I can't tell what Mr. >> Lundh is referring to. The first line of his post is: "Tim Williams >> wrote" but there's nothing that comes before. Similarly, I'm reading this via

Re: Subclassing array

2006-05-04 Thread Sion Arrowsmith
Alex Martelli <[EMAIL PROTECTED]> wrote: >TG <[EMAIL PROTECTED]> wrote: >> When I call Vector.__init__() in Stimulus, doesn't it also call __new__ >> ? I don't understand the detail of callings to __new__ and __init__ in >> python inheritance ... >Calling a (new-style) class does __new__ first, THE

Re: Tuple assignment and generators?

2006-05-05 Thread Sion Arrowsmith
vdrab <[EMAIL PROTECTED]> wrote: >let's say there's a certain property P, for the sake of this lng >discussion, something >more or less like a class or type's property of "having immutable >values, such that any instance with value X has a single, unique >representation in memory and any two in

Re: how to remove 50000 elements from a 100000 list?

2006-05-05 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >Another attempt might be to try > > >>> a = [x for x in a if x not in b] > >However, this is still doing A*B checks, and will likely >degrade with as their sizes increase. Combine this with the use of sets others have suggested if the order of a matters, ie:

Re: releasing interpreter lock in custom code?

2006-05-11 Thread Sion Arrowsmith
Bram Stolk <[EMAIL PROTECTED]> wrote: >I've implemented, in C, a function that does a lot of I/O, and thus >can block for a long time. > >If I execute this function in my Python script, it does not >relinquish the global interpreter lock, like Python's native >blocking functions do, like I/O func

Re: Python memory deallocate

2006-05-11 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >If I write: > >a = range(500*1024) > >I see that python process allocate approximately 80Mb of memory. >What can i do for DEALLOCATE this memory, or good part of this? > [ ... ] >I've tried with Destroy, del command, but the memory don't show down. It won't (much). Whe

Re: Large Dictionaries

2006-05-16 Thread Sion Arrowsmith
Maric Michaud <[EMAIL PROTECTED]> wrote: >I don't see a use case where a python programmer should need a >dictionnary "that will be probably big" but can't predict what keys will be >in. I've recently been working on an app with precisely this characteristic, although there were enough other bott

Re: How to tell if function was passed a list or a string?

2006-05-18 Thread Sion Arrowsmith
rh0dium <[EMAIL PROTECTED]> wrote: > [ ... ] Since you have lots of answers to your real question: >an.append(re.sub(",","", str(a))) an.append(str(a).replace(",", "")) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings toward

Re: memory error with zipfile module

2006-05-19 Thread Sion Arrowsmith
Hari Sekhon <[EMAIL PROTECTED]> wrote: >import zipfile >zip=zipfile.ZipFile('d:\somepath\cdimage.zip') >zip.namelist() >['someimage.iso'] [ ... ] >B) content=zip.read('someimage.iso') > >Traceback (most recent call last): > File "", line 1, in ? > File "D:\u\Python24\lib\zipfile.py", line 357

Re: memory error with zipfile module

2006-05-19 Thread Sion Arrowsmith
bruno at modulix <[EMAIL PROTECTED]> wrote: >http://mail.zope.org/pipermail/zope/2004-October/153882.html >""" >MemoryError is raised by Python when an underlying (OS-level) allocation >fails. >(...) >Normally this would mean that you were out of even virtual memory >(swap), but it could also be a

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

<    1   2   3   4   >