Re: What is "self"?

2005-09-23 Thread Sion Arrowsmith
Rick Wotnaz <[EMAIL PROTECTED]> wrote: >I've long thought that Guido missed an opportunity by not choosing >to use 'i' as the instance identifier, and making it a reserved >word. For one thing, it would resonate with the personal pronoun >'I', and so carry essentially the same meaning as 'self'

Re: What python idioms for private, protected and public?

2005-09-30 Thread Sion Arrowsmith
Michael Schneider <[EMAIL PROTECTED]> wrote: >I have been coding in C++ since the late 80's and Java since the late 90's. > >I do use private in these languages, with accessors to get at internal >data. > >This has become an ingrained idiom for me. The question is, has it become a purely instinc

Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-03 Thread Sion Arrowsmith
Ron Adam <[EMAIL PROTECTED]> wrote: >So ... > > A if B else C + X * Y > >Would evaluate as... ? > > A if B else (C + X * Y) """In general, 'if' and 'else' bind less tight than everything except lambda.""" http://mail.python.org/pipermail/python-dev/2005-September/056846.html -- \S -- [EMAI

Re: how to send a SIGINT to a Python process?

2005-10-03 Thread Sion Arrowsmith
Michele Simionato <[EMAIL PROTECTED]> wrote: >Is there a way to send a SIGINT/KeyboardInterrupt to a >Python process (knowing the pid) that works both on Unix and Windows? No. Windows doesn't support the sending of signals between processes (with the exception of an equivalent of SIGKILL). I guess

Re: Python vs Ruby

2005-10-21 Thread Sion Arrowsmith
bruno modulix <[EMAIL PROTECTED]> wrote: >> "Casey Hawthorne" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >>>I have heard, but have not been able to verify that if a program is >>>about >>>10,000 lines in C++ >>>it is about >>>5,000 lines in Java >>>and it is about >>>3,000 lin

Re: Python and MySQL

2005-11-03 Thread Sion Arrowsmith
Aquarius <[EMAIL PROTECTED]> wrote: >I want to know if there is a way to interface a MySQL database without >Python-MySQL or without installing anything that has C files that need >to be compiled. The reason for this, is that I want to develop a >certain web application, but my hosting provider ([E

Re: strange sockets

2005-11-04 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Skink <[EMAIL PROTECTED]> wrote: >% python client.py client.py client.py client.py server.py server.py >init 0.00066089630127 >client.py 0.000954866409302 >client.py 0.0408389568329 >client.py 0.0409188270569 >server.py 0.0409059524536 >server.py 0.0409259796143 > >

Re: which feature of python do you like most?

2005-11-08 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >which feature of python do you like most? A different thing every time I encounter the corresponding misfeature in another language. But a lot of it boils down to the cleanliness of syntax when handling complex datastructures aggregated from basic type

Re: What do you use as symbols for Python ?

2005-11-11 Thread Sion Arrowsmith
Gary Herron <[EMAIL PROTECTED]> wrote: >Another similar approach that keeps those values together in a single >namespace is this (my favorite): > > class State: > OPENED, CLOSED, ERROR = range(3) > >Then you can refer to the values as >State.OPENED >State.CLOSED >State.ERROR > >

Re: help make it faster please

2005-11-11 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Oh sorry indentation was messed here...the >wordlist = countDict.keys() >wordlist.sort() >should be outside the word loop now >def create_words(lines): >cnt = 0 >spl_set = '[",;<>{}_&?!():-[\.=+*\t\n\r]+' >for content in lines: >words=content.spl

Re: How to convert a "long in a string" to a "long"?

2005-11-18 Thread Sion Arrowsmith
Steven Bethard <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> s = long("0xL") >> ValueError: invalid literal for long(): 0xL > >>> int("0x", 0) >4294967295L So why does the base argument to int() (or long()) default to 10 and not 0? -- \S -- [EMAIL PROTECTED] --

Re: about sort and dictionary

2005-11-23 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >OKB (not okblacke) wrote: >> Fredrik Lundh wrote: >> > [EMAIL PROTECTED] wrote: [ ... ] >> >> > so what would an entry-level Python programmer expect from this >> >> > piece of code? >> >> > >> >> > for item in a.reverse(): >> >> > print ite

Re: i=2; lst=[i**=2 while i<1000]

2005-12-06 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> >>> list(iter(lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or >> None, None)) >> [2, 4, 16, 256] >out of curiosity, what stops the iterator ? : iter(o, sentinel) [ ... ] The iterato

Re: Bitching about the documentation...

2005-12-08 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >>> "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo." > >S >P >O >I >L >E >R > >S >P >A >C >E > (Good grief, I've not done that in *years*.) >Buffalo from the city of Buffalo, which are intimidated by buffalo >from Buffalo, also inti

Re: What YAML engine do you use?

2005-01-24 Thread Sion Arrowsmith
Paul Rubin wrote: >YAML looks to me to be completely insane, even compared to Python >lists. I think it would be great if the Python library exposed an >interface for parsing constant list and dict expressions, e.g.: > [1, 2, 'Joe Smith', 8237972883334L, # comment >

Re: What is print? A function?

2005-01-24 Thread Sion Arrowsmith
Michael Hoffman <[EMAIL PROTECTED]> wrote: >Frans Englich wrote: >> Nah, I don't think it's a function, but rather a builtin "statement". But >> it's >> possible to invoke it as an function; print( "test" ) works fine. >That is not invoking it as a function. The parentheses are only for >orderi

Re: What YAML engine do you use?

2005-01-25 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> I'm probably not thinking deviously enough here, but how are you >> going to exploit an eval() which has very tightly controlled >> globals and locals (eg. eval(x, {"__builtins__": None},

Re: RE:"private" variables a.k.a. name mangling (WAS: What is print? A function?)

2005-01-25 Thread Sion Arrowsmith
Jeremy Bowers <[EMAIL PROTECTED]> wrote: > [ ... ] the Python community, and in general the dynamic language >community, has become increasingly confident that private variables don't >solve *real* problems. Years of writing and maintaining others' C++ and Java code (plus one year of maintaining

Re: Inheriting from object

2005-06-30 Thread Sion Arrowsmith
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Fuzzyman a écrit : >> *Should* I in fact write : >> >> class foo(object): >> def __init__(self, *args, **kwargs): >> object.__init__(self) >> >> ? >Nope. And if you were to do so, surely: class foo(object): def __init__(self, *arg

Re: map vs. list-comprehension

2005-07-01 Thread Sion Arrowsmith
Tom Anderson <[EMAIL PROTECTED]> wrote: >On Thu, 30 Jun 2005, Roy Smith wrote: >> Even some of the relatively recent library enhancements have been kind >> of complicated. The logging module, for example, seems way over the >> top. >Exactly the same thing happened with Java. I was under the im

Re: Strange os.path.exists() behaviour

2005-07-07 Thread Sion Arrowsmith
Jeff Epler <[EMAIL PROTECTED]> wrote: >Pierre wrote: >> Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on wi= >n32 > = >^^^ >Here's the bug. You're using Windows. It's a filesystem, but not as we kn= >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Sion Arrowsmith
=?ISO-8859-2?Q?Pawe=B3?= Sakowski <[EMAIL PROTECTED]> wrote: ll=[[1,2],[3,4,5],[6]] sum(ll,[]) >[1, 2, 3, 4, 5, 6] That's a great argument for list.__add__ having the semantics of extend rather than append 8-) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Fra

Re: more newbie list questions

2005-07-14 Thread Sion Arrowsmith
Bernhard Holzmayer <[EMAIL PROTECTED]> wrote: >googleboy wrote: >> I have a cell.txt file that looks like this: >> >> ++ >> The title is %title%. >> The author is %author1% %author2% >> The Publisher is %publisher1% %publisher2% >> The ISBN is %ISBN% >> ++ > >This looks like a DOS-batch-file

Re: Consecutive Character Sequences

2005-07-14 Thread Sion Arrowsmith
Aries Sun <[EMAIL PROTECTED]> wrote: >I used Python 2.4.1, the following are the command lines. >But the reslut was still False. Is there anything wrong with below >codes? import itertools as it def hasConsequent(aString, minConsequent): > for _,group in it.groupby(aString): >

Re: multiple inheritance super()

2005-07-28 Thread Sion Arrowsmith
Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: >Michele Simionato wrote: >> was I >> going to design a new language >> I would implement it *without* multiple inheritance). That way lies Java. The number of times I've wished an interface were actually a mixin *shudder* >Multiple inheritance

Re: Dabo in 30 seconds?

2005-08-02 Thread Sion Arrowsmith
James Stroud <[EMAIL PROTECTED]> wrote: >Perhaps some of us are writing software with non-developer end-users in mind >and we kind of keep that mentality when evaluating modules our code uses. In the commercial environment I'm working in, non-developer end-users get a frozen executable. They don'

Re: searching a list of dictionaries for an element in a list.

2005-08-10 Thread Sion Arrowsmith
Dan <[EMAIL PROTECTED]> wrote: >> [ someone else wrote: ] >> I want to search list1, and the result should be all dictionaries where >> primarycolor is in input. I can do this using a double for-loop, but is >> there a more efficent way? > >Of course.:-) > >L = [dict for dict in list1 if dict[

Re: What are modules really for?

2005-08-10 Thread Sion Arrowsmith
infidel <[EMAIL PROTECTED]> wrote: >> [ somebody else wrote: ] >> To my mind, although one CAN put many classes in a file, it is better to >> put one class per file, for readability and maintainability. >Personally I find it easier to maintain a set of related classes when >they're all in the same

Re: Newbie Question

2005-08-19 Thread Sion Arrowsmith
Tom Strickland <[EMAIL PROTECTED]> wrote: >I have a file that contains many lines, each of which consists of a string >of comma-separated variables, mostly floats but some strings. Each line >looks like an obvious tuple to me. How do I save each line of this file as a >tuple rather than a string

Re: Network performance

2005-08-23 Thread Sion Arrowsmith
Roland Hedberg <[EMAIL PROTECTED]> wrote: > [ ... ] >The client sends a number of lines (each ending with \n) and ends one >set of lines with a empty line. >When the client sends a line with only a "." it means "I'm done close >the connection". > >Letting the client open the connection and sen

Re: newbie question: convert a list to one string

2005-08-25 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I'm searching for the fastest way to convert a list to one big string. The join() method of strings. The string instance in question being the separator you want, so: " ".join(test) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I ha

Re: RE Despair - help required

2005-08-25 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Yoav <[EMAIL PROTECTED]> wrote: >Fredrik Lundh wrote: >> "Yoav" wrote: >>>I am trying the following: >>> >>>re.search(r'\\[^"\\]+(?=("?$))', "c:\ret_files") >> instead of struggling with weird REs, why not use Python's standard >> filename manipulation library inste

Re: Is my thread safe from premature garbage collection?

2005-09-01 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Benjamin Niemann <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> However, in my current project I'm creating a bunch of threads which >> are supposed to run until they've completed their run() method, and I'm >> worried that if I do not keep references to th

Re: Creating custom event in WxPython

2005-09-01 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >Now when my socket thread detects an incoming message, I need my main >thread to interpret the message and react to it by updating the GUI. >IMO the best way to achieve this is by having my socket thread send a >custom event to my application's event loop for the main t

Re: round() wrong in Python 2.4?

2005-09-13 Thread Sion Arrowsmith
Nils Grimsmo <[EMAIL PROTECTED]> wrote: >Why did round() change in Python 2.4? > >$ python2.3 >Python 2.3.5 (#2, Jun 19 2005, 13:28:00) >[GCC 3.3.6 (Debian 1:3.3.6-6)] on linux2 round(0.0225, 3) >0.023 "%.3f" % round(0.0225, 3) >'0.023' >$ python2.4 >Python 2.4.1 (#2, Jul 12 2005, 09

Re: turing machine in an LC

2005-02-10 Thread Sion Arrowsmith
Greg Ewing <[EMAIL PROTECTED]> wrote: >As a fellow named Church once pointed out, lambdas are really >*all* you need in a language... ... where as others argue that it is impractical not to have some form of runtime data storage, thereby giving rise to the separation of Church and state. -- \S

Re: Install MySQLdb on Mac OS X (10.3)

2005-02-11 Thread Sion Arrowsmith
Skip Montanaro <[EMAIL PROTECTED]> wrote: >Try a more recent version of mysql-python. I think 1.1.7 is the latest. 1.2.0 -- it appears to be moving extremely rapidly (especially given how long it was at 0.9.2 -- although "Waiting for MySQL 4.1 to become stable" would be a good explanation for th

Re: Stable GUI + wxPython memory leak

2005-02-17 Thread Sion Arrowsmith
Peter Hansen <[EMAIL PROTECTED]> wrote: >Viktor wrote: >> I just noticed that wxPython is leaking memory?! Playing with >> wxPython-demo, I started with 19MB used, and ended whith almost 150MB >> used?! >> It's wxPython 2.5.3.1 running on Python 2.4. >On which platform? > >And how are you measurin

Re: Why doesn't join() call str() on its arguments?

2005-02-17 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, ! Nick Vargish <[EMAIL PROTECTED]> wrote: > If a non-string-type has managed to >get into my list-of-strings, then something has gone wrong and I would >like to know about this potential problem. Thinking about where I use join(), I agree. If there's something ot

Re: Problem with the sort() function

2005-02-22 Thread Sion Arrowsmith
clementine <[EMAIL PROTECTED]> wrote: >Thanx Nick...I forgot to mention im using python 2.2 and along with a host >of other things it doesnt seem to have the enumarate built in function >:(:(:(...is it possible to replace it by something else? I dont think >simulating it will be feasible Here'

Re: injecting "set" into 2.3's builtins?

2005-03-11 Thread Sion Arrowsmith
Stephen Thorne <[EMAIL PROTECTED]> wrote: >I have: >try: >set >except NameError: >from sets import Set as set > >in my code in a few places. Is there any reason to prefer this over the idiom I have: if sys.version_info < (2, 4): from sets import Set as set ? (I've also used the same

Re: wxPython bug

2004-12-10 Thread Sion Arrowsmith
Jive <[EMAIL PROTECTED]> wrote: >In wxPython 2.5, run the demo, samples/wxProject/wxProject.py > [ ... ] >TypeError: TreeCtrl_GetFirstChild() takes exactly 2 arguments (3 given) GetFirstChild() changed from taking 2 arguments in wxPython 2.4 to (the more sensible) 1 in wxPython 2.5. Clearly wxProj

Re: Why no list heritable type?

2004-12-17 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: >And before Python 2.2 there was the UserList class in the standard >library. Which is still there in 2.4. Shouldn't it be depreciated by >this point? Apart from compatibility issues as mentioned in the UserList documentation,

Re: curious problem with large numbers

2005-04-08 Thread Sion Arrowsmith
Michael Spencer <[EMAIL PROTECTED]> wrote: >Terry Reedy wrote: >> "Chris Fonnesbeck" <[EMAIL PROTECTED]> wrote >>>However, on Windows (have tried on Mac, Linux) I get the following >>>behaviour: >>inf = 1e1 >>inf >>>1.0 >> On my Windows machine with 2.2.1, I get exactly what you expec

Re: Why Python does *SLICING* the way it does??

2005-04-20 Thread Sion Arrowsmith
Raymond Hettinger <[EMAIL PROTECTED]> wrote: ><[EMAIL PROTECTED]> >> Many people I know ask why Python does slicing the way it does. >Python's way has some useful properties: > >* s == s[:i] + s[i:] > >* len(s[i:j]) == j-i # if s is long enough The latter being particularly helpful when i

Re: what is the best way to determine system OS?

2005-04-25 Thread Sion Arrowsmith
Philippe C. Martin <[EMAIL PROTECTED]> wrote: >How about popen of 'uname -r' ? os.uname()[2] is probably a better way (ie it doesn't spawning another process) of getting this information. I don't think it will help the original poster though (depending on *what* it is about FC3 which is breaking t

Re: flatten a level one list

2006-01-12 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Paul Rubin wrote: >Robin Becker <[EMAIL PROTECTED]> writes: >> >reduce(operator.add,a) >> ... >That's what I hoped "sum" would do, but instead it barfs with a type >error. So much for duck typing. sum(...) sum(sequence, start=0)

Re: Python linker

2006-07-18 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >I love python - I use it as a utility language to complement my C# >programming every day. However, the reason I do not use it as my >primary language is - surprise, surprise - not its lack of static type >checking, but the size of standalone executes (which embed the

Re: CSV with comments

2006-07-19 Thread Sion Arrowsmith
Daniel Dittmar <[EMAIL PROTECTED]> wrote: > if line [:1] == '#': What's wrong with line[0] == '#' ? (For one thing, it's fractionally faster than [:1].) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the oth

Re: [Newbie] List from a generator function

2006-07-24 Thread Sion Arrowsmith
Paul Rubin wrote: > print list(islice(starmap(random.choice, repeat((possible_notes,))), length)) Why the use of starmap() rather than imap(random.choice, repeat(possible_notes)) ? -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have

Re: Possible error in 'dive into Python' book, help!

2006-07-31 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Ben Edwards (lists) <[EMAIL PROTECTED]> wrote: >I have been going through Dive into Python which up to now has been >excellent. I am now working through Chapter 9, XML Processing. I am 9 >pages in (p182) in the 'Parsing XML section. The following code is >supposed

Re: What is the best way to print the usage string ?

2006-08-04 Thread Sion Arrowsmith
There's been a good lot of response to the problem originally stated, but no-one's pointed out that: >print reduce(lambda x, y: x + ':' + y, sys.argv[1:]) is a confusing (and slow) way of writing: print ':'.join(sys.argv[1:]) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___

Re: How to reverse tuples in a list?

2006-08-09 Thread Sion Arrowsmith
Robert Kern <[EMAIL PROTECTED]> wrote: >Python 2.4+: > > y = [tuple(reversed(t)) for t in y] > Python 2.3: y = [ t[::-1] for t in y ] Obviously works in 2.4 as well, where I make it faster than using tuple(reversed(t)). Which isn't surprising, as it's not constructing the intermediate list

Re: Class data being zapped by method

2006-08-09 Thread Sion Arrowsmith
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >fpath = os.path.join('datafiles', filename + ".tabdata") fpath = os.path.join('datafiles', filename + os.path.extsep + "tabdata") 8-) I'm a bit bemused by extsep -- it didn't appear until 2.2, by which time there can't have been many people with an

Re: Two Classes In Two Files

2006-08-10 Thread Sion Arrowsmith
Pedro Werneck <[EMAIL PROTECTED]> wrote: >"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >> Wasn't so much a worry, just trying to figure out how to think the >> python way. >Seems like you're thinking the Java way... if you don't want to do it, >put both classes in the same file. OP: think of a

Re: datetime to timestamp

2006-08-11 Thread Sion Arrowsmith
John Machin <[EMAIL PROTECTED]> wrote: >On 11/08/2006 11:35 PM, John Machin wrote: >> On 11/08/2006 11:10 PM, Simen Haugen wrote: >>> How can I convert a python datetime to a timestamp? It's easy to convert >>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the >>> other way aroun

Re: dictionary update

2006-08-15 Thread Sion Arrowsmith
Chris <[EMAIL PROTECTED]> wrote: >I have a instance attribute self.xds and a local variable xds in the >instance . Both are dictionaries. I understand that I can update >self.xds with xds as follows: self.xds.update(xds) > >However I have many instance attributes, self.i, and local variables i.

Re: Printing n elements per line in a list

2006-08-16 Thread Sion Arrowsmith
In article <[EMAIL PROTECTED]>, Dan Sommers <[EMAIL PROTECTED]> wrote: >Perhaps not the prettiest, but I can't think of anything simpler to read >six months from now: > >counter = 0 >for an_element in the_list: >print an_element, >counter = counter + 1 >if counter =

Re: what is the keyword "is" for?

2006-08-16 Thread Sion Arrowsmith
Simon Forman <[EMAIL PROTECTED]> wrote: >Python 2.4.3 (#2, Apr 27 2006, 14:43:58) >[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 >Type "help", "copyright", "credits" or "license" for more information. > >|>> a = b = 1e1000 / 1e1000 >|>> a is b >True >|>> a == b >False I agree with you: $ python P

Re: Problem of function calls from map()

2006-08-22 Thread Sion Arrowsmith
Dasn <[EMAIL PROTECTED]> wrote: ># size of 'dict.txt' is about 3.6M, 154563 lines >f = open('dict.txt', 'r') >print "Reading lines..." >lines = f.readlines() >print "Done." [ ... ] >def sp1(lines): > """> sp1() -- List-comprehension""" > return [s.split('\t') for s in lines] [ ..

Re: Problem of function calls from map()

2006-08-22 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> I think there's something weird going on -- sp4 should be making >> 154563 calls to str.split. So no wonder it goes faster -- it's not doing >> any work. >the problem is that he's usin

Re: key not found in dictionary

2006-08-23 Thread Sion Arrowsmith
Chaz Ginger <[EMAIL PROTECTED]> wrote: >KraftDiner wrote: >> desc = self.numericDict[k][2] >> KeyError: 589824 < This is the error that is being produced, >As stated you can wrap the access in the try - except - else statement, >as in > >try: > foo['bar'] >except : > # Handle the erro

Re: Output from subprocess.Popen()

2006-10-16 Thread Sion Arrowsmith
Clodoaldo Pinto Neto <[EMAIL PROTECTED]> wrote: >Fredrik Lundh wrote: >> this works for me: >> >> >>> f = subprocess.Popen("set | grep IFS", shell=True, >> stdout=subprocess.PIPE) >> >>> f.stdout.readlines() >> ["IFS=$' \\t\\n'\n"] >> >> what does the above return on your machine? > f = subp

Re: implementation of "in" that returns the object.

2006-10-23 Thread Sion Arrowsmith
Jorge Vargas <[EMAIL PROTECTED]> wrote: >I need to check if an object is in a list AND keep a reference to the >object I have done it this way but is there a better one? > def inplusplus(value,listObj): >... for i in listObj: >... if i is value: >... return

Re: Sorted and reversed on huge dict ?

2006-11-06 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >so i just have tried, even if i think it will not go to the end => i >was wrong : it is around 1.400.000 entries by dict... > >but maybe if keys of dicts are not duplicated in memory it can be done >(as all dicts will have the same keys, with different (count) values)?

Re: Really strange behavior

2006-11-06 Thread Sion Arrowsmith
IloChab <[EMAIL PROTECTED]> wrote: [this works] >def main(): >app = QtGui.QApplication(sys.argv) >qt4reactor.install(app) >MainWindow = QtGui.QMainWindow() >win = Window(MainWindow) >MainWindow.show() >from twisted.internet import reactor >reactor.run() [this doesn't] >

Re: httplib.InvalidURL: nonnumeric port: For characters in the proxypassword in URL

2006-11-13 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: urllib.quote > urllib2.quote > >>> urllib.quote >>> urllib2.quote Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'quote' >>> sys.version '2.4.1 (#2, May 5 2005, 11:32:06) \n[GCC 3.3.5

Re: ini files and plugins

2006-11-16 Thread Sion Arrowsmith
tool69 <[EMAIL PROTECTED]> wrote: >I've made a basic LaTeX file editor in wxPython, but now I wanted to add >it some features : >1 - create a sort of ini file where I can put the user configuration >that will load itself on the application startu

[OT] whitespace (was Re: stupid perl question)

2006-05-31 Thread Sion Arrowsmith
John Machin <[EMAIL PROTECTED]> wrote: > Whitespace is a silly term, anyway (IMHO); is there such a >thing as a space that is not white? Yes, if you go back to the term's origins in printshops. A solid block of ink is space, not print, but it's not whitespace. We've kept the word alive, even if

Re: DB-API: how can I find the column names in a cursor?

2006-06-01 Thread Sion Arrowsmith
A.M <[EMAIL PROTECTED]> wrote: >The other problem is accessing data in each row by column name. In Ruby I >can say: > >Print row["ColName"] > >In Python; however, I must access to row contents by integer index, like >PRINT ROW[0], which reduces my program's readability. > >Can I access to row's con

Re: integer to binary...

2006-06-02 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >bitCount = len([c for c in "01001010101" if c=="1"]) bitCount = "01001010101".count("1") -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ |-- Arthur C. Clark

Re: New to Python: Do we have the concept of Hash in Python?

2006-06-02 Thread Sion Arrowsmith
gregarican <[EMAIL PROTECTED]> wrote: >I came from using Ruby about a year or so [ ... ] That's an interesting way round. Why did you consider Python if you already knew Ruby, and which is now your preferred language? (I've no interest in learning Ruby, but from what I've seen of it I similarly ca

Re: Using print instead of file.write(str)

2006-06-02 Thread Sion Arrowsmith
A.M <[EMAIL PROTECTED]> wrote: >I found print much more flexible that write method. "more flexible"? More convenient, yes. More powerful, maybe. But I don't see more flexible. Everything print can to stdout.write() can do. The reverse isn't true. eg (this appears to be a FAQ on this group, althoug

Re: Bug in list comprehensions?

2006-06-07 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Iain King wrote: >> I'm guessing I'm the one confused here... but I'm confused! What's >> going on? >the clauses nest from left to right, not from right to left, so "[x for >x in y for y in beta]" is equivalent to > > out = [] > for x in y: >

Re: Instead of saving text files i need as html

2006-06-09 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >> [ ... ] >> urllib.urlretrieve(lines.strip('/n'), 'c:\\temp\\' \ >> + outfilename.strip('\n')[7:] + '.html') > [ ... ] I'm not sure what the odd >slicing is for, but I'll presume the OP knows what they're doing. It's taking the "http://"; o

Re: How to extract 2 integers from a string in python?

2006-06-09 Thread Sion Arrowsmith
Stephen Prinster <[EMAIL PROTECTED]> wrote: a, b, c, d = 'Total size: 173233 (371857)'.split() first_int, second_int = int(c), int(d[1:-1]) int(d[1:-1]) can be replaced by d.strip("()"), which may or may not be clearer in intent. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~

Re: Searching and manipulating lists of tuples

2006-06-12 Thread Sion Arrowsmith
Steve Holden <[EMAIL PROTECTED]> wrote: >def algorith(d, s): > if s in d: > d[s] += 1 > else: > d[s] = 1 def algorith(d, s): d[s] = d.get(s, 0) + 1 And the OP should note that converting between dict d and list of pairs L is simply a matter of L = d.items() and d = di

Re: determining file type

2006-06-14 Thread Sion Arrowsmith
Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: >Also, >f =3D file ('some_file.jpg') > >throws an error. >"str object is not callable" You know all the times people say in this group "Don't use list or str or file[HINT] or anything else that shadows a built in as a variable name"? Now you know why.

Re: Having problems with strings in HTML

2006-06-27 Thread Sion Arrowsmith
Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > Kiana Toufighi <[EMAIL PROTECTED]> wrote: > >>print ''' >>>href="http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?inp >>ut=&max=2&values_off=no&remove_bracket=no&show_line_nr=yes&show_link_out=yes >> [ ... ] ">Graphi

Re: Having problems with strings in HTML

2006-06-27 Thread Sion Arrowsmith
Richard Brodie <[EMAIL PROTECTED]> wrote: >"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] > [ ... ] >>>By the way, you _do_ realize that your "&" characters should be escaped >>>as "&", d

Re: Immutability

2006-06-28 Thread Sion Arrowsmith
Nick Maclaren <[EMAIL PROTECTED]> wrote: >Georg Brandl <[EMAIL PROTECTED]> writes: >|> [ attributions lost ] >|> > Thanks very much. And, what's more, I have even found its documentation! >|> > Whatsnew2.2. The 2.4.2 reference is, er, unhelpful. >|> Is it? >|> http://docs.python.org/lib/built-in-

Re: Immutability

2006-06-28 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Sion Arrowsmith wrote: >> What I've not seen documented anywhere is the: >>@property >>def fset(self, value): >>... >> idiom. It's not obvious from the documentation of the proper

Re: eval to dict problems NEWB going crazy !

2006-07-10 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >Ant wrote: >> It seems that there must be a way to use eval safely, as there are >> plenty of apps that embed python as a scripting language - and what's >> the point of an eval function if impossible to use safely, and you have >> to write your own Python

Re: function that modifies a string

2006-07-10 Thread Sion Arrowsmith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >Of course, another right way would be to have mutable strings in Python. What significant advantage would mutable strings have over StringIO and wrapping list manipulation in list(s) and ''.join(l). Other than that pleasing symmetry with sets/frozensets

Re: split a line, respecting double quotes

2006-07-10 Thread Sion Arrowsmith
Jim <[EMAIL PROTECTED]> wrote: >Is there some easy way to split a line, keeping together double-quoted >strings? > >I'm thinking of > 'a b c "d e"' --> ['a','b','c','d e'] >. I'd also like > 'a b c "d \" e"' --> ['a','b','c','d " e'] >which omits any s.split('"')-based construct that I could c

Re: Is there an elegant way to dir() module from inside?

2006-08-24 Thread Sion Arrowsmith
volcano <[EMAIL PROTECTED]> wrote: >I am looking for a way to discover which classes a module contains from >"inside". I am building a testing class that should, when instatntiated >within any module, locate certain classes within the containing module. globals().keys() -- \S -- [EMAIL PROTECTED

Re: efficient text file search -solution

2006-09-12 Thread Sion Arrowsmith
noro <[EMAIL PROTECTED]> wrote: >OK, am not sure why, but > >fList=file('somefile').read() >if fList.find('string') != -1: > print 'FOUND' > >works much much faster. > >it is strange since i thought 'for line in file('somefile')' is >optemized and read pages to the memory, Step back and think ab

"Directory this source file is in (and a sibling)"

2006-09-22 Thread Sion Arrowsmith
I have a module which needs to know what directory it's in, and to refer to files in a sibling directory, something like App/src/foo.py wants to read App/data/conf.xml . But I have no idea in what context foo.py is going to be run -- it could be being run as a script, it could be being imported as

Re: A critique of cgi.escape

2006-09-26 Thread Sion Arrowsmith
Jon Ribbens <[EMAIL PROTECTED]> wrote: >In article <[EMAIL PROTECTED]>, Duncan Booth wrote: >> I guess you've never seen anyone write tests which retrieve some generated >> html and compare it against the expected value. If the page contains any >> unescaped quotes then this change would break i

Re: where are isinstance types documented?

2006-09-26 Thread Sion Arrowsmith
Fredrik Lundh <[EMAIL PROTECTED]> wrote: >based on http://docs.python.org/ref/types.html, here's a list of the >most commonly used core types: > [ ... ] >Sequences: > str > unicode > tuple > list And set, presumably. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/

Re: Top and Bottom Values [PEP: 326]

2006-09-27 Thread Sion Arrowsmith
Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: >In message <[EMAIL PROTECTED]>, Antoon Pardon wrote: >> I need this Top value in >> a context where it can be used as a start or stop value >> in a slice. >But the only valid values allowed for indices are 0 >>> range(5)[:-1] [0, 1, 2, 3] > up to

Re: Finding the file referred to in a Python traceback

2006-09-28 Thread Sion Arrowsmith
<[EMAIL PROTECTED]> wrote: >In this traceback, the path to 3 different SQL Alchemy source files is >a relative directory. However, no such directory is below my current >working directory. > >Traceback (most recent call last): > File "", line 1, in ? > File "conf/__init__.py", line 34, in __init

Re: Whither binary search?

2006-09-28 Thread Sion Arrowsmith
John Machin <[EMAIL PROTECTED]> wrote: >Fredrik Lundh wrote: >> well, people tend to use dictionaries when they need to look things up >> quickly... >... like those paper dictionaries with the words in alphabetical order >:-) ... where you'll notice that the really big ones are divided up into buc

Re: for: else: - any practical uses for the else clause?

2006-09-28 Thread Sion Arrowsmith
Ben Sizer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> Yeah, I use it from time to time: >> >> for foo in bar: >> if foo matches some condition: >> print "sail to tahiti!" >> break >> else: >> print "abandon ship!" > >As a C++ programmer (w

Re: The del statement

2006-12-05 Thread Sion Arrowsmith
Marco Aschwanden <[EMAIL PROTECTED]> wrote: [ ... ] >> so what about >> >> del x > >Ups. I never used it for an object. So far I only used it for deletion of >elements of a container. In that case del has two purposes: > >1. Deletes an item from a container (and of course destructs it) -->

Re: Fall of Roman Empire

2006-12-20 Thread Sion Arrowsmith
Ben Finney <[EMAIL PROTECTED]> wrote: >"John Machin" <[EMAIL PROTECTED]> writes: >> Ben Finney wrote: >> > \ "...one of the main causes of the fall of the Roman Empire was | >> > `\that, lacking zero, they had no way to indicate successful | >> > _o__) termination of

Re: Backreferences in python ?

2006-01-24 Thread Sion Arrowsmith
Pankaj <[EMAIL PROTECTED]> wrote: >search for :for ( i = 0; i < 10; i++) >Replace with: for( printf( "10" ), i =0; i < 10; i++) >Where 10 is the line no. >f = open( "./1.c", "r") >fNew = open( "./1_new.c", "w") >for l in f: >print l >lineno = lineno + 1 >strToFind = "f

Re: append to the end of a dictionary

2006-01-24 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >unless you have a way of doing an in-line sort, in which you >would be able to do something like > > orderedDict = [(k,mydict[k]) for k in mydict.keys().sort()] > >Unfortunately, the version I've got here doesn't seem to support >a sort() method for the li

Re: append to the end of a dictionary

2006-01-25 Thread Sion Arrowsmith
Magnus Lycka <[EMAIL PROTECTED]> wrote: >orderedListOfTuples = [(k,mydict[k]) for k in sorted(mydict.keys())] Or: orderedListOfTuples = [(k,v) for k,v in sorted(mydict.items())] (k, mydict[k]) sets off warning bells for me that mydict.items() should be in use, which are nearly as loud as the on

Re: append to the end of a dictionary

2006-01-25 Thread Sion Arrowsmith
I wrote: >orderedListOfTuples = [(k,v) for k,v in sorted(mydict.items())] > >(k, mydict[k]) sets off warning bells for me that mydict.items() >should be in use [ ... ] But apparently [ x for x in mylist ] doesn't yet trigger such a warning. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~

  1   2   3   4   >