Re: Recommendation please: forming an XML toolkit

2005-11-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I guess you're right... I think its just cold feet from the possibility > of getting involved and discovering specific gotchas later. > > What I'm hearing you tell me is *go and play it*. uche posted an interesting taxonomy here: http://article.gmane.org/gmane.comp

Re: weird problem with os.chmod

2005-11-12 Thread Fredrik Lundh
Mike Meyer wrote: > Strange that int doesn't recognize the leading 0. But you can use the > second argument to int: > > >>> int("0600", 16) > 1536 > >>> int is designed for humans, not C programmers. humans tend to view e.g. "08" as a valid decimal number (*), not a ValueError. to get programme

Re: about widget construction kit

2005-11-12 Thread Fredrik Lundh
"Shi Mu" wrote: > > > I tried again and got the follwoing message: > > > *** cannot find Tcl/Tk headers and library files > > > change the TCL_ROOT variable in the setup.py file > > > but i have already installed TCL under python23 > > > > hmm. I still think it would be easier if you used a p

Re: convert string to the "escaped string"

2005-11-12 Thread Fredrik Lundh
Petr Jakes wrote: > I am trying to convert string to the "escaped string". > example: from "0xf" I need "\0xf" > I am able to do it like: > > a="0xf" > escaped_a=("\%s" % a ).decode("string_escape") > > But it looks a little bit complicated in this beautiful language to me I suspect that optimiz

Re: newbie how do I interpret this?

2005-11-12 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > >>> help(m.groups) > Help on built-in function groups: > > groups(...) > > >>> > > My question is. How do I interpret the hiven help info > groups(...) > > alt1. Tough luck. There's no help. People are to busy to write > reference manuals. they're busy writing reference

Re: XUL behavior in Python via XPCOM, Mozilla

2005-11-12 Thread Fredrik Lundh
Terry Hancock wrote: >I recently saw a claim that Mozilla XUL behaviors (normally > scripted in Javascript) can (or perhaps will) be scriptable > in Python. > > Also, "other languages such as Java or Python are supported > through XPCOM", said about Mozilla (from Luxor website). > > Yes, I know se

Re: weird problem with os.chmod

2005-11-12 Thread Fredrik Lundh
Bengt Richter wrote: > >*) unless you're living in sweden, in which case "08" is quite often used > >as an insult. > > I am always curious about languages, and considering my name, I think I'd > like to know this definition ;-) Is it telephone-exchange-related? it's the area code for Stockholm. I

Re: the button of cancel

2005-11-13 Thread Fredrik Lundh
Ben Bush wrote: > When I click the button of cancel, > I got the follwoing message. I want to see "Goodbye" on the console screen. > What to do? > KeyboardInterrupt: operation cancelled > num = input( "Enter a number between 1 and 100: " ) > while num < 1 or num > 100: >print "Oops, your inp

Re: elementtree.ElemenTree barfs on my Safari Cookies file

2005-11-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Safari stores its cookies in XML format. Looking to try and add support for > it to cookielib I started by first trying to parse it with Fredrik Lundh's > elementtree package. It complained about an invalid token. Looking at the > spot it indicated in the file, I foun

Re: help make it faster please

2005-11-13 Thread Fredrik Lundh
Ron Adam wrote: > The \w does make a small difference, but not as much as I expected. that's probably because your benchmark has a lot of dubious overhead: > word_finder = re.compile('[EMAIL PROTECTED]', re.I) no need to force case-insensitive search here; \w looks for both lower- and uppercase

Re: HOW do you stop a print???

2005-11-14 Thread Fredrik Lundh
"john boy" <[EMAIL PROTECTED]> wrote: > ok...I am running the following program: > > def printMultiples (n): > i = 1 > while i <= 6: > print n*i, ' \t ', > i = i + 1 > i = 1 > while i <= 6: > printMultiples(i) > i = i + 1 > > this is supposed to return a simp

Re: Dictionary of tuples from query question

2005-11-14 Thread Fredrik Lundh
David Pratt wrote: > My code so far. I guess my problem is how to generate a tuple > dynamically when it is immutable? you can use tuple() to convert lists to tuples. >>> x = [] >>> x.append(1) >>> x.append(2) >>> x.append(3) >>> tuple(x) (1, 2, 3) but doesn't fetchall a

Re: Dictionary of tuples from query question

2005-11-14 Thread Fredrik Lundh
David Pratt wrote: > Hi Fredrik. Many thanks for your reply and for the tuple tip. The > cursor.fetchall returns a list of lists in this instance with each list > in the main list containing the field values. With the tip, I > simplified my code to: > > vlist_dict = {} > record_count = 0 > for rec

Re: newbie help needed

2005-11-14 Thread Fredrik Lundh
"john boy" <[EMAIL PROTECTED]> wrote: > I am running the following program: > > def print Multiples (n, high): > i = 1 > while i <= high: > print n*i, ' \t' , > i = i + 1 > print > def printMultTable (high): > i = 1 > while i <= high: > print Multip

Re: more newbie help needed

2005-11-14 Thread Fredrik Lundh
"john boy" <[EMAIL PROTECTED]> wrote: > using the following program: > > fruit = "banana" > index = 0 > while index < len (fruit): > letter = fruit[index-1] > print letter > index= index -1 > after spelling "banana" it gives an error message: > refering to line 4: letter = fruit[in

Re: more newbie help needed

2005-11-14 Thread Fredrik Lundh
Steve Holden wrote: > Note, however, that there are more pythonic ways to perform this task. > You might try: > > for index in range(len(fruit)): > letter = fruit[-index-1] > print letter > > as one example. I'm sure other readers will have their own ways to do > this, many of them more elegan

Re: more newbie help needed

2005-11-14 Thread Fredrik Lundh
Craig Marshall wrote: > Or, if you're *really* just trying to reverse the string, then the > following might read more easily (although it's probably longer): > fruit = list(fruit) > fruit.reverse() > fruit = ''.join(fruit) same thing, on one line: fruit = "".join(reversed(fruit)) same thi

Re: Configure failing why?

2005-11-15 Thread Fredrik Lundh
Samuel M. Smith wrote: >I am trying to build python2.4.2 on an arm 9 running Debian 3 Sarge > configure:1842: ./a.out > ./configure: line 1: ./a.out: Permission denied > configure:1845: $? = 126 > configure:1854: error: cannot run C++ compiled programs. > If you meant to cross compile, use `--hos

Re: Default method arguments

2005-11-15 Thread Fredrik Lundh
Steven D'Aprano wrote: >> Another solution to this is the use of a 'marker' object and identity test: >> >> _marker = [] >> class A(object): >> def __init__(self, n): >> self.data =n >> def f(self, x = _marker): >> if x is _marker: >> x = self.data >> pr

Re: Is there any Iterator type example?

2005-11-16 Thread Fredrik Lundh
Thomas Moore wrote: > But what I really want to know is how to use __iter()__ and next() in a > class with an example. here's a simple iterator class that iterators over itself once: class Iterator1: def __init__(self, size=10): self.count = 0 self.size = size def __iter_

Re: Python/ASP local characters and 500 server error

2005-11-16 Thread Fredrik Lundh
Martin wrote: > Using Python / ASP on a IIS server with Mark Hammond's win32 extensions, > i have the following problem. > > All occurences of local characters (fx. danish æøå) in comments or in > strings result in a HTTP/1.1 500 Server Error. > > Is there a solution to this problem? the first th

Re: how to bypass firewall

2005-11-16 Thread Fredrik Lundh
Gregory Bond wrote: > I need help getting my college degree. I downloaded a hack to bypass > the college internet firewall and the college system admins found out > and I got expelled. http://www.google.com/search?q=buy+a+degree (if not else, that link will show you how many sponsored links goo

Re: Default method arguments

2005-11-16 Thread Fredrik Lundh
Duncan Booth wrote: > What you really want is for the marker to exist only in its own little > universe, but the code for that is even messier: > > class A(object): >def __init__(self, n): >self.data =n >def make_f(): >marker = object() >def f(self, x = _marker): N

Re: special method in module

2005-11-16 Thread Fredrik Lundh
Jan Procházka wrote: > can have modules special methods? no, but you can replace the module object with something that can have special methods: $ more module.py import sys class Module: def __getitem__(self, value): return value sys.modules[__name__] = Module() $ python >>> impor

Re: initialising a list of lists

2005-11-16 Thread Fredrik Lundh
Peter Kleiweg wrote: > This does not what I want it to do: > >>>> a = [[]] * 6 >>>> a[3].append('X') >>>> a >[['X'], ['X'], ['X'], ['X'], ['X'], ['X']] > > This does what I want: > >>>> b = [[] for _ in range(6)] >>>> b[3].append('X') >>>> b >[[], [], [], ['X'], [],

Re: initialising a list of lists

2005-11-16 Thread Fredrik Lundh
Peter Kleiweg wrote: >> http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list > > In other words: no there isn't. For people who actually knows Python, a list comprehension is clear and obviously correct. For people who actually knows Python, your first solution

Re: is parameter an iterable?

2005-11-16 Thread Fredrik Lundh
Rick Wotnaz wrote. > ... which leads me to belive that 'msg' is not type(str). It can be > coerced (str(msg).find works as expected). But what exactly is msg? > It appears to be of , and does not test equal to a > string. it's an instance of the exception type, of course. ::: if you do rai

Re: Quitting a Tkinter application with confirmation

2005-11-16 Thread Fredrik Lundh
Peter Kleiweg wrote: > I want the program to behave identical if the 'close' button of > the application window is clicked. I tried the code below, > using a class derived from Tk that redefines the destroy > method. That seems to work. At least on Linux. > > My questions: > > Is this the correct

Re: Can anyone tell me if pygame and Tkinter can work together?

2005-11-16 Thread Fredrik Lundh
Nathan Pinno wrote: > It's a warning that says: > > Can only use * in top level or something like that. > > It's kind of annoying why? importing tons of unknown stuff into a local namespace is rather silly, and makes it impossible for the compiler to properly analyze your code -- which means tha

Re: repeating regular expressions in one string

2005-11-16 Thread Fredrik Lundh
"Shane" wrote > I have a bunch of strings that looks like this: > > 'blahblah_sf1234-sf1238_blahblah' > > and I would like to use the re module to parse all the 'sf' parts > of the string. Each 'sf' needs to be its own string when I am > through. How do I compile a regular expression that

Re: subprocess terminate help

2005-11-16 Thread Fredrik Lundh
Ernesto wrote > I've been searching for ways to terminate this process so I can exit my > program. program.exe is a text based interface which I'm running with > python subprocess in a DOS command window. I tried using 'sys.exit()' > to end my program, but nothing works. I think I have to someh

Re: subprocess terminate help

2005-11-16 Thread Fredrik Lundh
Ernesto wrote: > Yeah I know. I posted it b/c I was having the same problems and I'm > investigating ways to do this. None of those methods gave me desired > results for my program. All I want to do is end my python program and > return to the DOS prompt. what about the other program? do you

Re: is parameter an iterable?

2005-11-16 Thread Fredrik Lundh
Steven D'Aprano wrote: > This means we're no longer assuming what the error message will be, > which makes our code a lot more future-proof and implementation-proof: if > some version of Python changes the error string from "iteration over > non-sequence" to something else, the code should continu

Re: is parameter an iterable?

2005-11-16 Thread Fredrik Lundh
> Alex has already posted the right way to do this. can you please stop posting crappy non-solutions to a problem that has a very simple solution (split things up), that should be obvious to anyone who didn't sleep through exceptions 101. -- http://mail.python.org/mailman/listinfo/python-l

Re: subprocess terminate help

2005-11-16 Thread Fredrik Lundh
Ernesto wrote > program.exe ? I was looking at the Windows task manager after I used a > Cntrl + C to manually terminate the running python program. The > program.exe is apparently ending when I end the python program. I have to admit that I have no idea what you're doing, really. The code you

Re: strange file.write() behavior on windows: $ConvertToNonresident, $ReplaceAttribute2

2005-11-17 Thread Fredrik Lundh
"welch" <[EMAIL PROTECTED]> wrote: > while taking some rough disk performance measures on windows machines, > and snooping with FileMon, i've noticed some odd behavior > sometimes, depending on the phase of the moon, instead of > $ReplaceAttribute2 the write goes to $ConvertToNonresident. within

Re: sqlite utf8 encoding error

2005-11-17 Thread Fredrik Lundh
Greg Miller wrote: > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 13-18: > unsupported Unicode code range > > does anyone have any idea on what could be going wrong? The string > that I store in the database table is: > > 'Keinen Text für Übereinstimmungsfehler gefunden' $ mor

Re: searching for files on Windows with Python

2005-11-17 Thread Fredrik Lundh
Shane wrote: > I've been giving Google a good workout with no luck. I would like to be > able to search a Windows filesystem for filenames, returning a list off > absolute > paths to the found files, something like: maybe some variation of http://article.gmane.org/gmane.comp.python.general/

Re: Hashing Function

2005-11-17 Thread Fredrik Lundh
Dave wrote: > I'm wondering what hashing function Python uses for > dictionaries. use the source, luke: http://svn.python.org/view/python/trunk/Objects/dictobject.c?rev=39608&view=markup http://svn.python.org/view/python/trunk/Objects/dictnotes.txt?rev=35428&view=markup -- http://mail.pyt

Re: os.spawnl error

2005-11-17 Thread Fredrik Lundh
Salvatore wrote: > Does someone already had ths problem ? > os.spawnl(os.P_NOWAIT,'c:\windows\notepad.exe') > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python24\lib\os.py", line 565, in spawnl >return spawnv(mode, file, args) > OSError: [Errno 22] Invalid arg

Re: newb ?

2005-11-17 Thread Fredrik Lundh
Chad Everett wrote: > I am back. > No I am not a high school or college student. your subject lines still suck. please read this http://www.catb.org/~esr/faqs/smart-questions.html#bespecific before you post your next question. (the entire article is worth reading, if you haven't done so

Re: Newbie question: does file("text.txt', "w").write("stuff") ever get closed?

2005-11-18 Thread Fredrik Lundh
"John Doe" <[EMAIL PROTECTED]> wrote: > In an effort to avoid another potential mistake, I am wondering if the > anonymous file object/class/thingy that I create when I do file("text.txt', > "w").write("stuff") gets closed properly on exit or garbage collection or > something yes. > or if I alwa

Re: Adding through recursion

2005-11-18 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I still don't get it. I tried to test with x = 0 and found that to > work. How come since the value of y is right and it is printed right it > "turns into" None when returned by the return statement ? because you're not returning the value to the print statement; you're

Re: Newbie question. Pyexpat fails on make

2005-11-18 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I want to build pyexpat and link it statically in Python. Im using > Python 2.4.2. This is just a straight forward build using ./configure > and then make > > I change *shared* to *static* and then uncoment these two lines: > > EXPAT_DIR=/usr/local/src/expat-1.95.2 > pye

Re: Can you set a class instance's attributes to zero by setting theinstance to zero?

2005-11-19 Thread Fredrik Lundh
Gerard Flanagan wrote: > If I have the Vector class below, is there a means by which I can have > the following behaviour > A = Vector(1, 2) print A > (1, 2) A = 0 that operation rebinds A; it doesn't affect the Vector instance in any way. more here: http://effbot.org/zone/pyth

Re: what happens when the file begin read is too big for all lines to beread with "readlines()"

2005-11-19 Thread Fredrik Lundh
Ross Reyes wrote: > When I use readlines, what happens if the number of lines is huge?I have > a very big file (4GB) I want to read in, but I'm sure there must be some > limitation to readlines and I'd like to know how it is handled by python. readlines itself has no limitation, but it reads

Re: Where can I find string.translate source?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > The module string has a function called translate. I tried to find the > source code for that function. In: > > C:\Python24\Lib > > there is one file called > > string.py > > I open it and it says > > """A collection of string operations (most are no longer used

Re: PATH environment variable

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Based on a search of other posts in this group, it appears as though > os.environ['PATH'] is one way to obtain the PATH environment variable. > > My questions: > 1) is it correct that os.environ['PATH'] contains the PATH environment > variable? yes. > 2) are there othe

Re: Can a function access its own name?

2005-11-20 Thread Fredrik Lundh
"B Mahoney" wrote: > Decorate any function with @aboutme(), which > will print the function name each time the function is called. > > All the 'hello' stuff is in the aboutme() decorator code. > There is no code in the decorated functions themselves > doing anything to telling us the function name

Re: Can a function access its own name?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Look at the code below: > > # mystringfunctions.py > > def cap(s): > print s > print "the name of this function is " + "???" > > cap ("hello") > > > Running the code above gives the following output > > >>> > hello > the name of th

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I am writing a web applications(simple forms) which has a number of > fields. Each field naturally has a name and a number of > attributes(formatting etc.), like this : > > d = {'a':{...}, 'b':{}} > > This dict would be passed to the Kid template system which would l

Re: Type-checking unpickled objects

2005-11-20 Thread Fredrik Lundh
Gordon Airporte wrote: >I have this class, and I've been pickling it's objects as a file format > for my program, which works great. The problems are a.) how to handle > things when the user tries to load a non-pickled file, and b.) when they > load a pickled file of the wrong class. > > a. I can

Re: line order

2005-11-20 Thread Fredrik Lundh
Ben Bush wrote: > I run the following code and the red line and black line show at the > same time. is there anyway to show the red line first, then the black > line? for example, after I click the 'enter' key? > > from Tkinter import * > tk = Tk() > canvas = Canvas(tk, bg="white", bd=0, highlight

Re: How to draw a dash line in the Tkinter?

2005-11-20 Thread Fredrik Lundh
Ben Bush wrote: > How to draw a dash line in the Tkinter? use the dash option. e.g. canvas.create_line(xy, fill="red", dash=(2, 4)) canvas.create_line(xy, fill="red", dash=(6, 5, 2, 4)) (the tuple contains a number of line lengths; lengths at odd positions are drawn, lengths at even po

Re: email separation

2005-11-20 Thread Fredrik Lundh
"john boy" wrote: > Does anyone know if I can somehow separate all mails coming > from the python forum from all of my other mail, so I can open > it from another folder or something like that under the same > address...I have a yahoo account... look under "filters" on this page: http://help

Re: what happens when the file begin read is too big for all linestobe?read with "readlines()"

2005-11-20 Thread Fredrik Lundh
Ross Reyes wrote: > Maybe I'm missing the obvious, but it does not seem to say what happens when > the input for readlines is too big. Or does it? readlines handles memory overflow in exactly the same way as any other operation: by raising a MemoryError exception: http://www.python.org/doc/cur

Re: PATH environment variable

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Do these observations fit with what is stated in section 6.1.1 of the > Python Library Reference? yes. what part of your observations makes you think that the environment isn't "captured" (i.e. copied from the process environ- ment) when the os module is imported ? (h

Re: Speeding up multiple regex matches

2005-11-20 Thread Fredrik Lundh
"Talin" wrote: > I've run in to this problem a couple of times. Say I have a piece of > text that I want to test against a large number of regular expressions, > where a different action is taken based on which regex successfully > matched. The naive approach is to loop through each regex, and sto

Re: Command line

2005-11-20 Thread Fredrik Lundh
"amfr" wrote: > Hoe would I call something on the command line from python, e.g. "ls > -la"? os.system(cmd), or some relative: http://docs.python.org/lib/os-process.html http://docs.python.org/lib/os-newstreams.html#os-newstreams or http://docs.python.org/lib/module-subprocess.html

Re: func(*params)

2005-11-20 Thread Fredrik Lundh
David Duerrenmatt wrote: > For some reasons, I've to use Python 1.5.2 and am looking for a workaround: > > In newer Python versions, I can call a function this way: > > func = some_function > func(*params) > > Then, the list/tuple named params will automatically be "expanded" and > n=len(params) a

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
Christoph Zwerschke wrote: > The example above is a bit misleading, because using 'a', 'b' as keys > can give the impression that you just have to sort() the keys to have > what you want. So let's make it more realistic: > > d = { 'pid': ('Employee ID', 'int'), >'name': ('Employee name', 'varc

Re: Delays getting data on sys.stdin.readline() ?

2005-11-20 Thread Fredrik Lundh
Christian Convey wrote: > So here's what I don't get: If "producer" was retaining its output for > a while for the sake of efficiency, I would expect to see that effect > when I just run "producer" on the command line. That is, I would > expect the console to not show any output from "producer" un

Re: ownership problem?

2005-11-20 Thread Fredrik Lundh
Jeffrey Schwab wrote: > > Is it correct to say that the typical ownership problem, which > > frequently arises in C++, does not occur normally in Python? > > What "typical ownership problem" do you feel frequently arises in C++? > If you are referring to the sometimes difficult task of determining

Re: ownership problem?

2005-11-20 Thread Fredrik Lundh
Jeffrey Schwab wrote: > > the problem isn't determining who owns it, the problem is determining > > who's supposed to release it. that's not a very common problem in a > > garbage-collected language... > > Yes it is. Memory is only one type of resource. Python's garbage collector deals with obj

Re: setattr for secondary attribute

2005-11-20 Thread Fredrik Lundh
Alex wrote: > I apologize for asking maybe a very trivial question. > I have a new class object A with slots. One of the slots is, for > example, object spam. Object spam, in turn, also has slots and one of > them is attribute eggs. I need to assign a new value to eggs. In other > words, I need t

Re: Why are there no ordered dictionaries?

2005-11-20 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Fredrik Lundh wrote: > > but you can easily generate an index when you need it: > > > > index = dict(d) > > > > name, type = index["pid"] > > print name > > > > the index should take less than a

Re: How to draw a dash line in the Tkinter?

2005-11-21 Thread Fredrik Lundh
"Shi Mu" wrote: > > > How to draw a dash line in the Tkinter? > > > > use the dash option. e.g. > > > >canvas.create_line(xy, fill="red", dash=(2, 4)) > >canvas.create_line(xy, fill="red", dash=(6, 5, 2, 4)) > > > > (the tuple contains a number of line lengths; lengths at odd positions >

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > If I need the dict feature 90% of the time, and the list feature 10% of > the time. Wasn't your use case that you wanted to specify form fields in a given order (LIST), render a default view of the form in that order (LIST), and, later on, access the field specifiers in

Re: unittest can not use function name 'test' ?

2005-11-21 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I found something strange in my unittest : > This code is ok (will report error ): > > class MyTest1(unittest.TestCase): > > def runTest(self): > self.assertEqual(2,3) > pass > > if __name__ == '__main__': > unittest.main() > > But if I add a func

Re: Aproximative string matching

2005-11-21 Thread Fredrik Lundh
Tim Roberts wrote: > >I'm searching for a library which makes aproximative string matching, > >for example, searching in a dictionary the word "motorcycle", but > >returns similar strings like "motorcicle". > > > >Is there such a library? > > There is an algorithm called Soundex that replaces each

Re: duplicate items in a list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote: > I used the following method to remove duplicate items in a list and > got confused by the error. > > >>> a > [[1, 2], [1, 2], [2, 3]] > >>> noDups=[ u for u in a if u not in locals()['_[1]'] ] that's not portable, relies on CPython 2.4 implementation details, and shouldn't be used

Re: duplicate items in a list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote: > I used the following method to remove duplicate items in a list and > got confused by the error. > > >>> a > [[1, 2], [1, 2], [2, 3]] > >>> noDups=[ u for u in a if u not in locals()['_[1]'] ] > Traceback (most recent call last): > File "", line 1, in ? > TypeError: iterable argu

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
Ben Sizer wrote: > > No, that's not the same logic. The dict() in my example doesn't convert be- > > tween data types; it provides a new way to view an existing data structure. > > This is interesting; I would have thought that the tuple is read and a > dictionary created by inserting each pair s

Re: sort the list

2005-11-21 Thread Fredrik Lundh
Shi Mu wrote: > I have a list like [[1,4],[3,9],[2,5],[3,2]]. How can I sort the list > based on the second value in the item? > That is, > I want the list to be: > [[3,2],[1,4],[2,5],[3,9]] since you seem to be using 2.3, the solution is to use a custom compare function: >>> L = [[1,4],[3,9

Re: ownership problem?

2005-11-21 Thread Fredrik Lundh
Jeffrey Schwab wrote: > >>>the problem isn't determining who owns it, the problem is determining > >>>who's supposed to release it. that's not a very common problem in a > >>>garbage-collected language... > >> > >>Yes it is. Memory is only one type of resource. > > > > Python's garbage collector

Re: is parameter an iterable?

2005-11-21 Thread Fredrik Lundh
Steven D'Aprano wrote: > Alas and alack, I have to write code which is backwards > compatible with older versions of Python: > > Python 2.1.1 (#1, Aug 25 2001, 04:19:08) > [GCC 3.0.1] on sunos5 > Type "copyright", "credits" or "license" for more > information. > >>> iter > Traceback (most recent

Re: sort the list

2005-11-21 Thread Fredrik Lundh
Daniel Schüle wrote: > > what does let cmp = .. away mean? > > it means > lst.sort(lambda x,y: cmp(x[1], y[1])) note that cmp= isn't needed under 2.4 either. if you leave it out, your code will be more portable. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fredrik Lundh
"Fuzzyman" wrote: > [snip..] > > (as an example, on my machine, using Foord's OrderedDict class > > on Zwerschke's example, creating the dictionary in the first place > > takes 5 times longer than the index approach, and accessing an > > item takes 3 times longer. you can in fact recreate the ind

Re: Backwards compatibility [was Re: is parameter an iterable?]

2005-11-21 Thread Fredrik Lundh
Alex Martelli wrote: > > In the specific case of iter(), are there good > > alternative ways of detecting an iterable without > > consuming it? > > Not a problem I've had often, but when I did, if I recall correctly, I > did something like: > > try: > iter > except NameError: > def isiterable(

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Tom Anderson wrote: > Incidentally, can we call that the "Larosa-Foord ordered mapping"? The implementation, sure. > Then it sounds like some kind of rocket science discrete mathematics stuff But math folks usually name things after the person(s) who came up with the idea, not just some random

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Alex Martelli wrote: > What about PHP? Thanks! according to some random PHP documentation I found on the intarweb: An array in PHP is actually an ordered map. A map is a type that maps values to keys. and later: A key may be either an integer or a string. If a key is the standard

Re: ownership problem?

2005-11-22 Thread Fredrik Lundh
Alex Martelli wrote: > Python 2.5 should introduce a 'with' statement that may go partways > towards meeting your qualms; it's an approved PEP, though I do not > recall its number offhand. http://www.python.org/peps/pep-0343.html (this is one in a series of PEP:s based on the observation that th

Re: How to paste python code on wordpress?

2005-11-22 Thread Fredrik Lundh
Dan Lowe wrote > Replace < with < > > Replace > with > > > (where those abbreviations stand for "less than" and "greater than") > > Before: if x < 5: > > After: if x < 5: > > Another common character in code that you "should" do similarly is > the double quote ("). For that, use " > > Before: if x

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > > so what would an entry-level Python programmer expect from this > > piece of code? > > > > for item in a.reverse(): > > print item > > for item in a.reverse(): > > print item > > > I would expect it to first print a in reverse then a as it was.

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Since python's '=' is just name binding and that most objects(other > than those like int/float/string?) are mutable, I don't quite > understand why this is a gotcha that is so worrying. > > a = [1,2,3] > a.sorted() > b = a > > even an entry level python programmer can'

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Fredrik Lundh
"metiu uitem" wrote: > Say you have a flat list: > ['a', 1, 'b', 2, 'c', 3] > > How do you efficiently get > [['a', 1], ['b', 2], ['c', 3]] simplest possible (works in all Python versions): L = ['a', 1, 'b', 2, 'c', 3] out = [] for i in range(0, len(L), 2): out.append(L[i:i+

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > so what would an entry-level Python programmer expect from this > piece of code? > > for item in a.reverse(): > print item > for item in a.reverse(): > print item > > I would expect it to first print a in reverse then a as it was. > > a=[1,2,3] > > I expect it to pri

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Fredrik Lundh
Duncan Booth wrote: > That's funny, I thought your subject line said 'list of tuples'. I'll > answer the question in the subject rather than the question in the body: > > >>> aList = ['a', 1, 'b', 2, 'c', 3] > >>> it = iter(aList) > >>> zip(it, it) > [('a', 1), ('b', 2), ('c', 3)] yesterday, we g

Re: matching a string to extract substrings for which some functionreturns true

2005-11-22 Thread Fredrik Lundh
Amit Khemka wrote: > Well actually the problem is I have a list of tuples which i cast as > string and then put in a html page as the value of a hidden variable. > And when i get the string again, i want to cast it back as list of tuples: > ex: > input: "('foo', 1, 'foobar', (3, 0)), ('foo1', 2, '

Re: sort in the list

2005-11-22 Thread Fredrik Lundh
"Shi Mu" wrote: >I use Python 2.3 to run the following code: a=[[1,2],[4,8],[0,3]] a.sort() a > [[0, 3], [1, 2], [4, 8]] > I wonder whether the sort function automatically consider the first > element in the list of list as the sorting criteria or it just happens > to be? the

Re: the first element in the list of list

2005-11-22 Thread Fredrik Lundh
Ben Bush wrote: > I have a lis: > [[1,3],[3,4],[5,6],[8,9],[14,0],[15,8]] > I want a code to test when the difference between the first element in > the list of list is equal to or larger than 6, then move the previous > lists to the end of the list. that is: > [[14,0],[15,8],[1,3],[3,4],[5,6],[8,

Re: about sort and dictionary

2005-11-22 Thread Fredrik Lundh
> Still don't see why even you ask it again. fyi, I'm not " [EMAIL PROTECTED] ", and I've never, as far I know, posted from "readfreenews.net" -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary string parser

2005-11-22 Thread Fredrik Lundh
Sebastjan Trepca wrote: > is there any library or some way to parse dictionary string with list, > string and int objects into a real Python dictionary? > > For example: > > >>> my_dict = dict_parser("{'test':'123','hehe':['hooray',1]}") > > I could use eval() but it's not very fast nor secure. i

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Stuart McGraw wrote > > What would improve the Cheese Shop's interface for you? > > Getting rid of those damn top level links to old versions. > Seeing a long list of old versions, when 99% of visitors are > only interested in the current version, is just visual noise, > and really lame. Move the

Re: the first element in the list of list

2005-11-22 Thread Fredrik Lundh
"Ben Bush" wrote: > This question just came to my mind and not assigned by anyone. given that you and "Shi Mu" are asking identical questions, and that you've both started to send questions via direct mail, can you please ask your course instructor to contact me asap. thanks /F -- http://ma

Re: Timeout for regular expression

2005-11-22 Thread Fredrik Lundh
<[EMAIL PROTECTED]> wrote > Is there a way to set a timeout interval when executing with a > re.search ? Sometimes (reason being maybe a "bad" pattern), > the search takes forever and beyond... not directly. the only reliable way is to run it in a separate process, and use the resource module to

Re: Entry widget -- how to prevent change

2005-11-22 Thread Fredrik Lundh
"wanwan" <[EMAIL PROTECTED]> wrote: > let's say I already have some content. How do I set the widget so user > cannot change it/? assuming that you're talking about the Tkinter Entry widget, setting the state option to "readonly" should do the trick: e = Entry(...) e.config(state="reado

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fredrik Lundh
Stuart McGraw wrote: > Hmm, so two versions means one is a development version, > and the other is a stable version? I did not know that, and did > not see it documented on the site. I would say documenting > that would be an interface improvement. well, that's up to the developer. when you up

Re: PIL FITs image decoder

2005-11-22 Thread Fredrik Lundh
"jbrewer" wrote: > I'm trying to read in a FITs image file for my research, and I decided > that writing a file decoder for the Python imaging library would be the > easiest way to accomplish this for my needs. FITs is a raw data format > used in astronomy. > > Anyway, I followed the example in t

Re: matching a string to extract substrings for which somefunctionreturns true

2005-11-22 Thread Fredrik Lundh
I wrote: > if you cannot cache session data on the server side, I'd > recommend inventing a custom record format, and doing your > own parsing. turning your data into e.g. > >"foo:1:foobar:3:0+foo1:2:foobar1:3:1+foo2:2:foobar2:3:2" > > is trivial, and the resulting string can be trivially par

<    1   2   3   4   5   6   7   8   9   10   >