Re: Else statement executing when it shouldnt
On 23/01/2013 15:35, Jussi Piitulainen wrote: Thomas Boell writes: Using a keyword that has a well-understood meaning in just about every other programming language on the planet *and even in English*, redefining it to mean something completely different, and then making the syntax look like the original, well-understood meaning -- that's setting a trap out for users. The feature isn't bad, it's just very, very badly named. I believe it would read better - much better - if it was "for/then" and "while/then" instead of "for/else" and "while/else". I believe someone didn't want to introduce a new keyword for this, hence "else". There is a scenario, which I use from time to time, where 'else' makes perfect sense. You want to loop through an iterable, looking for 'something'. If you find it, you want to do something and break. If you do not find it, you want to do something else. for item in iterable: if item == 'something': do_something() break else: # item was not found do_something_else() Not arguing for or against, just saying it is difficult to find one word which covers all requirements. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: XML validation / exception.
Andrew Robinson writes: > On xml.etree, > When I scan in a handwritten XML file, and there are mismatched tags -- > it will throw an exception. > and the exception will contain a line number of the closing tag which > does not have a mate of the same kind. > > Is there a way to get the line number of the earlier tag which caused > the XML parser to know the closing tag was mismatched, so I can narrow > down the location of the mismatches for a manual repair? This is parser dependent -- and likely not the case for the standard parsers. In order to check for the correspondence between opening and closing tags, that parser must maintain a stack of open tags. Your request can be fullfilled when the parser keeps associated line numbers in this stack. I expect that most parser will not do that. Python's "xml" framework is highly modularied - with each component having only a minimal task. Especially, the parser is responsible for parsing only: it parses and generated events for what is sees (opening tag, closing tag, text, comment, entity, error, ...). The events are consumend by a separate component (when I remember right, a so called "handler"). Such a component is responsible to create the "ETree" during the parsing. You might be able to provide an alternative for this component which captures (in addition) line information for opening tags. Alternatively, you could provide an alternative parser. -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On 24/01/2013 19:34, Leonard, Arah wrote: It's just a text file after all. True indeed, let's not worry about trivial issues like indentation, mixing tabs and spaces or whatever. Notepad anybody? :) -- Cheers. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
> I think PyCharm is ideal for you. > http://www.jetbrains.com/pycharm/ +1 for PyCharm. I used many editors, and PyCharm (IDEA) is just perfect. -- http://mail.python.org/mailman/listinfo/python-list
How to debug pyd File in Vs???
Recently, I build a hybrid system with C++ and python. First,I encapsulate a class(I can't guarantee the robustness of this class ) with boost.python which can implement some functions that can not be implemented by C++, I get a .pyd File in result. Second,I embed a python interpreter in c++. Third, use the embed interpreter to execute a .py File.The .py File include the module that in .pyd File I created. Here, the problem comes out! When I start my main project. I can only debug the problems in my main project, when my main project use the python interpreter to execute the python interpreter, I can't see what happened in my pyd File, the whole project collapsed.I know the error is in the pyd File, and if I set a break point in my resource files of pyd File, either the project will go to the break point. Is there any methods to debug the resource file in this condition! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to debug pyd File in Vs???
Junze Liu: Third, use the embed interpreter to execute a .py File.The .py File include the module that in .pyd File I created. Here, the problem comes out! When I start my main project. I can only debug the problems in my main project, when my main project use the python interpreter to execute the python interpreter, I can't see what happened in my pyd File, the whole project collapsed.I know the error is in the pyd File, and if I set a break point in my resource files of pyd File, either the project will go to the break point. This normally works unless Visual Studio can't understand the relationship between the .pyd and source files. Make sure you have built the .pyd using a release configuration but with debugging information turned on for both compiling and linking. Or use a debug build of python along with a debug build of the .pyd. Is there any methods to debug the resource file in this condition! You can call DebugBreak() somewhere in the .pyd code which will start up Visual Studio as a debugger. It normally works out where the source code is and then you can add more breakpoints and step through. http://msdn.microsoft.com/en-us/library/windows/desktop/ms679297(v=vs.85).aspx Neil -- http://mail.python.org/mailman/listinfo/python-list
create object base on text file
Hi All Python 2.6.x on AIX Data file PrinterA print Production batch1 xx print Production batch2 xx print Production batch3 xxx PrinterB print Production batch4 xxx print Production batch5 What to using python create object base on date file ? I know how to read text file. object["PrinterA"] have batch1, batch2, batch3 object["PrinterB"] have batch4, batch5 moonhkt -- http://mail.python.org/mailman/listinfo/python-list
Re: create object base on text file
On 01/25/2013 07:06 AM, moonhkt wrote: Hi All Python 2.6.x on AIX Data file PrinterA print Production batch1 xx print Production batch2 xx print Production batch3 xxx PrinterB print Production batch4 xxx print Production batch5 What to using python create object base on date file ? I know how to read text file. object["PrinterA"] have batch1, batch2, batch3 object["PrinterB"] have batch4, batch5 moonhkt What Python version are you targeting? It would save everyone a lot of time if you quoted the homework assignment directly. Also, be more careful about typos. Is it a date file, or a data file? You can create an object very easily. a = object(). You can add attributes to many objects by simply saying a.attrib = 42 Unfortunately you can't do that to an "object" class instance. So you need to clarify. Now, you used dictionary syntax, so perhaps you didn't mean create an object, but create a dict. a = dict() a["PrinterA"] = "batch1", "batch2", "batch3" print a produces {'PrinterA': ('batch1', 'batch2', 'batch3')} What part of the assignment is giving you trouble? What have you written so far? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: monolithic apps
..snipped... > > 2) Manipulate multiple gui apps while having the same UI as though there > was just one main window, and other windows all belong to it. Multiple > GUI processes, but some central control to change the user experience > into resembling a single GUI app. ...snipped > > You say this a topic for study, but there's a lot of other things you > may need to specify before you get to implementing. What OS, what > version of Python, what GUI, are these apps modifiable, or are you just > allowed to write glue, ... > -- > DaveA Hey Thanks, Dave! Definitely (2). However: you say "and other windows all belong to it." That is not such a great idea as long as the main window can close the other windows. But that's the point. I have a humongous commercial app in C++ on Win32. (It could require porting at some time because main tools it uses could get ported by separate vendor) So what I'd like to do is write real-time imaging functions separately and control them using python scripting with whatever windows or overlayed images are needed. Debug these separately and call+control them as individual stand alone, and glue together as needed. glue being mainly python, and what is being glued would also be controlled as separate python modules. This ends up running as one monolithic application that looks the same (better I hope) as the previous huge monolithic win32 app. thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Re: using split for a string : error
On 2013-01-25, Oscar Benjamin wrote: > On 24 January 2013 11:35, Chris Angelico wrote: >> It's usually fine to have int() complain about any >> non-numerics in the string, but I must confess, I do sometimes >> yearn for atoi() semantics: atoi("123asd") == 123, and >> atoi("qqq") == 0. I've not seen a convenient Python function >> for doing that. Usually it involves manually getting the >> digits off the front. All I want is to suppress the error on >> finding a non-digit. Oh well. > > I'm interested to know what the situations are where you want > the behaviour of atoi(). Right. atoi is no good even in C. You get much better control using the sprintf family. int would need to return a tuple of the number it found plus the number of characters consumed to be more useful for parsing. >>> intparse("123abc") (123, 3) But that would make it might inconvenient for general use. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: monolithic apps
Glue not just python but whatever is needed to communicate back and forth. lots of data, but whatever could be glue in python of course. The C++ glue and functions would be controlled as python data and communicated between different modules. todd. -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
You could try ninja-ide or Sublime Text 2. This message was send from my phone Flick Ritchie On 25 Jan 2013 10:45, "Kirill Pekarov" wrote: > > I think PyCharm is ideal for you. > > http://www.jetbrains.com/pycharm/ > > +1 for PyCharm. > I used many editors, and PyCharm (IDEA) is just perfect. > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On Thursday, January 24, 2013 2:34:45 AM UTC-8, mik...@gmail.com wrote: > On Thursday, January 24, 2013 9:43:31 AM UTC, Hazard Seventyfour wrote: > > for all senior can you suggest me the best, friendly and easy use with nice > > GUI editor for me, and have many a good features such as auto complete/auto > > correct. > I personally like Eclipse as I use it for most of my projects (not only > Python) so I use Eclipse + PyDev plug-in for Python. Aptana is doing a great job bundling Eclipse + PyDev (+ other goodies). -- http://mail.python.org/mailman/listinfo/python-list
Re: using split for a string : error
On 25/01/13 15:04:02, Neil Cerutti wrote: > On 2013-01-25, Oscar Benjamin wrote: >> On 24 January 2013 11:35, Chris Angelico wrote: >>> It's usually fine to have int() complain about any >>> non-numerics in the string, but I must confess, I do sometimes >>> yearn for atoi() semantics: atoi("123asd") == 123, and >>> atoi("qqq") == 0. I've not seen a convenient Python function >>> for doing that. Usually it involves manually getting the >>> digits off the front. All I want is to suppress the error on >>> finding a non-digit. Oh well. >> >> I'm interested to know what the situations are where you want >> the behaviour of atoi(). > > Right. atoi is no good even in C. You get much better control > using the sprintf family. I think you meant sscanf. It's true that sscanf gives you more control. That being said, sometimes the one option atoi gives you, just happens to be what you need. > int would need to return a tuple of the > number it found plus the number of characters consumed to be more > useful for parsing. > intparse("123abc") > (123, 3) > > But that would make it might inconvenient for general use. If the new function is nameed intparse, and the existing int function remains available, then most use cases would be served by int, and intparse would be available as a building block for other use cases. For example atoi could be defined as: def atoi(s): return intparse(s)[0] intparse("xyz") should return (0, 0), and leave it to the caller to decide whether a ValueError shoud be raised. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: using split for a string : error
Don't forget to look at csv reader. http://docs.python.org/2/library/csv.html On Fri, Jan 25, 2013 at 9:31 AM, Hans Mulder wrote: > On 25/01/13 15:04:02, Neil Cerutti wrote: > > On 2013-01-25, Oscar Benjamin wrote: > >> On 24 January 2013 11:35, Chris Angelico wrote: > >>> It's usually fine to have int() complain about any > >>> non-numerics in the string, but I must confess, I do sometimes > >>> yearn for atoi() semantics: atoi("123asd") == 123, and > >>> atoi("qqq") == 0. I've not seen a convenient Python function > >>> for doing that. Usually it involves manually getting the > >>> digits off the front. All I want is to suppress the error on > >>> finding a non-digit. Oh well. > >> > >> I'm interested to know what the situations are where you want > >> the behaviour of atoi(). > > > > Right. atoi is no good even in C. You get much better control > > using the sprintf family. > > I think you meant sscanf. > > It's true that sscanf gives you more control. That being said, > sometimes the one option atoi gives you, just happens to be what > you need. > > > int would need to return a tuple of the > > number it found plus the number of characters consumed to be more > > useful for parsing. > > > intparse("123abc") > > (123, 3) > > > > But that would make it might inconvenient for general use. > > If the new function is nameed intparse, and the existing int > function remains available, then most use cases would be served > by int, and intparse would be available as a building block for > other use cases. For example atoi could be defined as: > > def atoi(s): return intparse(s)[0] > > intparse("xyz") should return (0, 0), and leave it to the caller > to decide whether a ValueError shoud be raised. > > > -- HansM > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- http://mail.python.org/mailman/listinfo/python-list
Re: using split for a string : error
On 2013-01-25, Hans Mulder wrote: >> Right. atoi is no good even in C. You get much better control >> using the sprintf family. > > I think you meant sscanf. Yes, thanks for knocking that huge chunk of rust off of me. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: create object base on text file
On Friday, January 25, 2013 9:04:31 PM UTC+8, Dave Angel wrote: > On 01/25/2013 07:06 AM, moonhkt wrote: > > > Hi All > > > > > > Python 2.6.x on AIX > > > > > > Data file > > > > > > PrinterA > > >print Production batch1 > > > xx > > >print Production batch2 > > > xx > > >print Production batch3 > > > xxx > > > > > > PrinterB > > > print Production batch4 > > > xxx > > >print Production batch5 > > > > > > > > > > > > What to using python create object base on date file ? I know how to > > > read text file. > > > > > > object["PrinterA"] have batch1, batch2, batch3 > > > > > > object["PrinterB"] have batch4, batch5 > > > > > > moonhkt > > > > > > > What Python version are you targeting? > > > > It would save everyone a lot of time if you quoted the homework > > assignment directly. Also, be more careful about typos. Is it a date > > file, or a data file? > > > > You can create an object very easily. a = object(). You can add > > attributes to many objects by simply saying > > a.attrib = 42 > > > > Unfortunately you can't do that to an "object" class instance. So you > > need to clarify. > > > > Now, you used dictionary syntax, so perhaps you didn't mean create an > > object, but create a dict. > > > > a = dict() > > a["PrinterA"] = "batch1", "batch2", "batch3" > > print a > > > > produces > > {'PrinterA': ('batch1', 'batch2', 'batch3')} > > > > > > What part of the assignment is giving you trouble? What have you > > written so far? > > > > > > -- > > DaveA Thank I get the methods. Python 2.6.2 I just leaning python , before using gawk/ksh. #!/usr/bin/env python a= dict() a["PrintA"]= ["batch1","batch2","batch3"] a["PrintB"] = ["batch4","batch5"] a["PrintA"].append("batch6") print a for k in sorted(a.keys()): for j in sorted(a[k]): print k , j Output {'PrintA': ['batch1', 'batch2', 'batch3', 'batch6'], 'PrintB': ['batch4', 'batch5']} PrintA batch1 PrintA batch2 PrintA batch3 PrintA batch6 PrintB batch4 PrintB batch5 -- http://mail.python.org/mailman/listinfo/python-list
Re: mysql solution
Τη Πέμπτη, 24 Ιανουαρίου 2013 10:43:59 μ.μ. UTC+2, ο χρήστης Dennis Lee Bieber έγραψε: > On Thu, 24 Jan 2013 03:04:46 -0800 (PST), Ferrous Cranus > > declaimed the following in > > gmane.comp.python.general: > > > > > # insert new page record in table counters or update it if already exists > > > try: > > > cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, > > %s) > > > ON DUPLICATE > > KEY UPDATE hits = hits + 1''', (htmlpage, 1) ) > > > except MySQLdb.Error, e: > > > print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] ) > > > > > > # update existing visitor record if same pin and same host found > > > try: > > > cursor.execute( '''UPDATE visitors SET hits = hits + 1, useros > > = %s, browser = %s, date = %s WHERE pin = %s AND host = %s''', (useros, > > browser, date, pin, host)) > > > except MySQLdb.Error, e: > > > print ( "Error %d: %s" % (e.args[0], e.args[1]) ) > > > > > > # insert new visitor record if above update did not affect a row > > > if cursor.rowcount == 0: > > > cursor.execute( '''INSERT INTO visitors(hits, host, useros, > > browser, date) VALUES(%s, %s, %s, %s, %s)''', (1, host, useros, browser, > > date) ) > > > > > > > Seeing the database schema would help. At present I have no idea > > what is defined as a key, what may be a foreign key, etc. > > > > For example: you show a "counters" table in which you are saving > > "hits" per page (I presume the URL is being saved). But the very next > > thing you are doing is something with a hit count in a "visitors" table > > which appears to be keyed by the combination of "host" and "pin" -- but > > you've failed to provide "pin" on the INSERT. > > > > Furthermore, your "visitors" table is only saving the most recent > > "useros" and "browser" data... Is that what you really want -- or do you > > want to log ALL users that visit the page. > > > > Making presumptions, I'd probably have something like: > > > > SCHEMA: > > > > create table counters > > ( > > ID integer not null auto_increment primary key, > > URL varchar(255) not null, > > hits integer not null default 1, > > unique index (URL) > > ); > > > > create table visitors > > ( > > ID integer not null auto_increment primary key, > > counterID integer not null, > > host varchar(255) not null, > > userOS varchar(255) not null, > > browser varchar(255) not null, > > hits integer not null default 1, > > lastVisit datetime not null, > > foreign key (counterID) references counters (ID), > > unique index (counterID, host) > > ); > > > > -=-=-=- > > > > con = db.connection() > > > > cur = con.cursor() > > > > try: > > #find the needed counter for the page URL > > cur.execute("select ID from counters where URL = %s", (htmlpage, ) ) > > data = cur.fetchone() #URL is unique, so should only be one > > if not data: > > #first time for page; primary key is automatic, hit is defaulted > > cur.execute("insert into counters (URL) values (%s)", > > (htmlpage,) ) > > cID = cur.lastrowid #get the primary key value of the new > record > > else: > > #found the page, save primary key and use it to issue hit update > > cID = data[0] > > cur.execute("update counters set hits = hits + 1 where ID = %s", > > (cID,) ) > > > > #find the visitor record for the (saved) cID and current host > > cur.execute("""select ID from visitors > > where counterID = %s > > and host = %s""", > > (cID, host) ) > > data = cur.fetchone() #cID&host are unique > > if not data: > > #first time for this host on this page, create new record > > cur.execute("""insert into visitors > > (counterID, host, userOS, > browser, lastVisit) > > values (%s, %s, %s, %s, %s)""", > > (cID, host, useros, browser, > date) ) > > #primary key and hits are defaulted, don't care about key > > else: > > #found the page, save its primary key for later use > > vID = data[0] > > #update record using retrieved vID > > cur.execute("""update visitors set > > userOS = %s, > > browser = %s, > >
Re: Need Pattern For Logging Into A Website
On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote: > I need to write a Python script to do the following: > > > >- Connect to a URL and accept any certificate - self-signed or > authoritative > >- Provide login name/password credentials > >- Fill in some presented fields > >- Hit a "Submit" button > > > > Why? Because I don't want to have to start a browser and do this > > interactively every time I authenticate with a particular server. > > I want to do this at the command line with no interactive intervention. > > > > I know Python pretty well. I don't quite know how to do this and > > was hoping someone had a simple pattern they could share for > > doing this. > > > > TIA, > > -- > > > > Tim Daneliuk tun...@tundraware.com > > PGP Key: http://www.tundraware.com/PGP/ The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start. I've done something similar with code like this: response = mechanize.urlopen(login_form_url) forms = mechanize.ParseResponse(response, backwards_compat=False) response.close() form = forms[0] # might be more than one, though # fill the form form.set_value(username, name='userName') form.set_value(password, name='password') # set headers - user-agent, etc. login_request = form.click() login_response = mechanize.urlopen(login_request) login_response_content = login_response.read() ... -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
> for all senior can you suggest me the best, friendly and easy use > with nice GUI editor for me, and have many a good features such as > auto complete/auto correct. Depends on what you are used to. If you're used to bare-bones editors such as emacs, vim etc, they can be used for Python. If you're used to IDEs, WingIDE is one long-standing competitor. The "101" version is free. There are also editors implemented *in* Python, which can be used for programming Python, such as Editra, which features quite a few useful plugins. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Pattern For Logging Into A Website
On 01/25/2013 10:01 AM, Steve Petrie wrote: On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote: I need to write a Python script to do the following: - Connect to a URL and accept any certificate - self-signed or authoritative - Provide login name/password credentials - Fill in some presented fields - Hit a "Submit" button Why? Because I don't want to have to start a browser and do this interactively every time I authenticate with a particular server. I want to do this at the command line with no interactive intervention. I know Python pretty well. I don't quite know how to do this and was hoping someone had a simple pattern they could share for doing this. TIA, -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start. I've done something similar with code like this: response = mechanize.urlopen(login_form_url) forms = mechanize.ParseResponse(response, backwards_compat=False) response.close() form = forms[0] # might be more than one, though # fill the form form.set_value(username, name='userName') form.set_value(password, name='password') # set headers - user-agent, etc. login_request = form.click() login_response = mechanize.urlopen(login_request) login_response_content = login_response.read() ... Thanks. -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Python GUI able to display a spatial image
Hello, does python have capabilities to display a spatial image and read the coordinates from it? If so, what modules or extension do I need to achieve that? I'll appreciate any help. Thanks, Alex -- http://mail.python.org/mailman/listinfo/python-list
RE: The best, friendly and easy use Python Editor.
>> >> It's just a text file after all. >> > > True indeed, let's not worry about trivial issues like indentation, mixing > tabs and spaces or whatever. Notepad anybody? :) > Hey, I didn't say Notepad was the *best* tool for the job, just that Python scripts are merely text files. Though, that said, I have used Notepad and Wordpad any number of times in the past to edit Python files, all without bringing the universe to an untimely end. Even used DOS Edit once. You use what you have at the time. A good craftsman never blames the tools. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On Sat, Jan 26, 2013 at 4:35 AM, Leonard, Arah wrote: >>> >>> It's just a text file after all. >>> >> >> True indeed, let's not worry about trivial issues like indentation, mixing >> tabs and spaces or whatever. Notepad anybody? :) >> > > Hey, I didn't say Notepad was the *best* tool for the job, just that Python > scripts are merely text files. > > Though, that said, I have used Notepad and Wordpad any number of times in the > past to edit Python files, all without bringing the universe to an untimely > end. Even used DOS Edit once. You use what you have at the time. A good > craftsman never blames the tools. ;) I've edited files using any number of poor tools, but that doesn't mean I'd choose them for daily work. Blame your tools no, but choose which ones you carry around on your belt. I have a couple of special-purpose editors that absolutely *suck* for general work, but have a specific feature that makes them good for one particular situation... one editor has a 32KB limit, no spiffy features, and sometimes mishandles line endings, but it edits files on my remote server, and can sometimes work when SSHing isn't an option. But there's no way I'd use that for any other purpose than remote editing. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
finding abc's
Hi all, i was writing a function to determine the common base class of a number classes: def common_base(classes): if not len(classes): return None common = set(classes.pop().mro()) for cls in classes: common.intersection_update(cls.mro()) while len(common) > 1: cls1 = common.pop() cls2 = common.pop() if issubclass(cls1, cls2): common.add(cls1) elif issubclass(cls2, cls1): common.add(cls2) return common.pop() and ran common_base(int, float), hoping to get numbers.Number. this did not work because abstract base classes are not always in the mro() of classes. My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)? Cheers, Lars -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On 01/24/2013 02:14 PM, Tetsuya wrote: > Vim has everything, you just need a bunch of plugins. > I code mainly in python and django, and I use these plugins (among others): > > powerline (status bar indicating git branch, etc..) > syntastic (support for pep8, flake8, pyflakes, etc..) > ctrlp (fuzzy search for filenames) > jedi (*awesome* python smart autocompletion) > tagbar (support for ctags, tags in a side window, jump around, etc) > fugitive (git with vim commands, very useful) > nerdcommenter (smart comment management) > nerdtree (filesystem management, tree of files, etc) > snipmate (snippets and autoexpanding of boilerplates) > gundo (undo management - vim has a smarter-than-others undo system) > supertab (autocomplete everything with TAB, smartly depending on > language and context). > > Is this enough? :-) > I can continue, but I think that, just to start, is enough. Vim wins. Awesome. I'm checking out these plugins right now, especially jedi and supertab. Thanks so much! -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On 2013-01-25, Leonard, Arah wrote: > Though, that said, I have used Notepad and Wordpad any number > of times in the past to edit Python files, all without bringing > the universe to an untimely end. Even used DOS Edit once. You > use what you have at the time. A good craftsman never blames > the tools. ;) DOS Edit was great for quick edits. The file size limit is a pity, though. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On 01/25/2013 12:54 PM, Neil Cerutti wrote: On 2013-01-25, Leonard, Arah wrote: Though, that said, I have used Notepad and Wordpad any number of times in the past to edit Python files, all without bringing the universe to an untimely end. Even used DOS Edit once. You use what you have at the time. A good craftsman never blames the tools. ;) DOS Edit was great for quick edits. The file size limit is a pity, though. I once had to write a text editor that would run in a 32k machine without a disk drive. The editor had to fit in RAM with the data, so the text files were limited to 320 lines. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: finding abc's
On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > [...] > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always in the mro() > of classes. > > My question is: is there a way to obtain the abc's of a class or otherwise a > way to make the function above take abc's into account (maybe via a > predefined function)? If the abstract base class's module has not been imported, it may not even be loaded into memory, even though it is technically considered a superclass. Consider this: Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def common_base(classes): ... common = set() ... for cls in object.__subclasses__(): ... if all(issubclass(c, cls) for c in classes): ... common.add(cls) ... return common ... >>> common_base([int, float]) set([]) >>> import numbers >>> common_base([int, float]) set([, ]) If you're okay with that, then the approach above might work. > while len(common) > 1: > cls1 = common.pop() > cls2 = common.pop() > if issubclass(cls1, cls2): > common.add(cls1) > elif issubclass(cls2, cls1): > common.add(cls2) There is a flaw with your set reduction code here. If neither class is a subclass of the other, then both will be removed. There may not actually be a single closest common base class, however. What would you expect the function to return in the following situation? class A(object): pass class B(object): pass class C(A, B): pass class D(A, B): pass print common_base([C, D]) -- http://mail.python.org/mailman/listinfo/python-list
Re: finding abc's
lars van gemerden wrote: > Hi all, > > i was writing a function to determine the common base class of a number > classes: > > def common_base(classes): > if not len(classes): > return None > common = set(classes.pop().mro()) > for cls in classes: > common.intersection_update(cls.mro()) > while len(common) > 1: > cls1 = common.pop() > cls2 = common.pop() > if issubclass(cls1, cls2): > common.add(cls1) > elif issubclass(cls2, cls1): > common.add(cls2) > return common.pop() > > and ran common_base(int, float), hoping to get numbers.Number. > > this did not work because abstract base classes are not always in the > mro() of classes. > > My question is: is there a way to obtain the abc's of a class or otherwise > a way to make the function above take abc's into account (maybe via a > predefined function)? The abstract base classes may run arbitrary code to determine the subclass relationship: >>> from abc import ABCMeta >>> import random >>> class Maybe(metaclass=ABCMeta): ... @classmethod ... def __subclasshook__(cls, C): ... print("processing", C) ... return random.choice((False, True)) ... >>> isinstance(1.1, Maybe) processing True >>> isinstance(1.1, Maybe) True >>> isinstance(1, Maybe) processing False >>> issubclass(float, Maybe) True You'd have to check every pair of classes explicitly and might still miss (for example) numbers.Number as the module may not have been imported. I think you are out of luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Pattern For Logging Into A Website
On 01/25/2013 09:18 AM, Tim Daneliuk wrote: > On 01/25/2013 10:01 AM, Steve Petrie wrote: >> On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk >> wrote: The mechanize module >> (http://wwwsearch.sourceforge.net/mechanize/) might be a place to >> start. I've done something similar with code like this: > Thanks. I've had good luck using urllib2 and a cookiejar. Just post your login credentials against the login url, keep all the cookies and then make your other requests using that cookiejar. Besides the Python standard library docs on urllib2 and cookielib, here's an article that gives an overview of how to use it: http://www.techchorus.net/using-cookie-jar-urllib2 This technique has the advantage of not requiring anything outside of the standard library. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding abc's
On Friday, January 25, 2013 8:04:32 PM UTC+1, Ian wrote: > On Fri, Jan 25, 2013 at 10:40 AM, lars van gemerden > > wrote: > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number > > classes: > > > > > [...] > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the mro() > > of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise > > a way to make the function above take abc's into account (maybe via a > > predefined function)? > > > > > > If the abstract base class's module has not been imported, it may not > > even be loaded into memory, even though it is technically considered a > > superclass. Consider this: > > > > > > Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit > > (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> def common_base(classes): > > ... common = set() > > ... for cls in object.__subclasses__(): > > ... if all(issubclass(c, cls) for c in classes): > > ... common.add(cls) > > ... return common > > ... > > >>> common_base([int, float]) > > set([]) > > >>> import numbers > > >>> common_base([int, float]) > > set([, ]) > > > > > > If you're okay with that, then the approach above might work. > > > > > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > > There is a flaw with your set reduction code here. If neither class > > is a subclass of the other, then both will be removed. There may not > > actually be a single closest common base class, however. What would > > you expect the function to return in the following situation? > > > > class A(object): pass > > class B(object): pass > > class C(A, B): pass > > class D(A, B): pass > > > > print common_base([C, D]) thanks, good catch, and very concise answer. I'll give up on trying to get abc's and improve my algorithm. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding abc's
On Friday, January 25, 2013 8:08:18 PM UTC+1, Peter Otten wrote: > lars van gemerden wrote: > > > > > Hi all, > > > > > > i was writing a function to determine the common base class of a number > > > classes: > > > > > > def common_base(classes): > > > if not len(classes): > > > return None > > > common = set(classes.pop().mro()) > > > for cls in classes: > > > common.intersection_update(cls.mro()) > > > while len(common) > 1: > > > cls1 = common.pop() > > > cls2 = common.pop() > > > if issubclass(cls1, cls2): > > > common.add(cls1) > > > elif issubclass(cls2, cls1): > > > common.add(cls2) > > > return common.pop() > > > > > > and ran common_base(int, float), hoping to get numbers.Number. > > > > > > this did not work because abstract base classes are not always in the > > > mro() of classes. > > > > > > My question is: is there a way to obtain the abc's of a class or otherwise > > > a way to make the function above take abc's into account (maybe via a > > > predefined function)? > > > > The abstract base classes may run arbitrary code to determine the subclass > > relationship: > > > > >>> from abc import ABCMeta > > >>> import random > > >>> class Maybe(metaclass=ABCMeta): > > ... @classmethod > > ... def __subclasshook__(cls, C): > > ... print("processing", C) > > ... return random.choice((False, True)) > > ... > > >>> isinstance(1.1, Maybe) > > processing > > True > > >>> isinstance(1.1, Maybe) > > True > > >>> isinstance(1, Maybe) > > processing > > False > > >>> issubclass(float, Maybe) > > True > > > > You'd have to check every pair of classes explicitly and might still miss > > (for example) numbers.Number as the module may not have been imported. > > > > I think you are out of luck. Thank you, interesting example. Added confirmation that trying to get the abc's is a bad idea. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the font size of anOptionMenu widget
Den fredagen den 25:e januari 2013 kl. 06:57:00 UTC+1 skrev Rick Johnson: > > menu = optMenu.nametowidget(optMenu.menuname) > That was what I was missing, the '.nametowidget'. It worked like a charm: o1=Tkinter.OptionMenu(t,v3, "€", "$") o1.config(font=self.font) o1.nametowidget(o1.menuname).config(font=self.font) Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: The best, friendly and easy use Python Editor.
On 01/25/2013 06:47 PM, Michael Torrie wrote: On 01/24/2013 02:14 PM, Tetsuya wrote: Vim has everything, you just need a bunch of plugins. [...] jedi (*awesome* python smart autocompletion) [...] supertab (autocomplete everything with TAB, smartly depending on language and context). Awesome. I'm checking out these plugins right now, especially jedi and supertab. Thanks so much! ;-) you're welcome! -- http://mail.python.org/mailman/listinfo/python-list
Retrieving an object from a set
Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to retrieve y, without going through the whole set. Here is a simple illustration with tuples (my actual scenario is not with tuples but with a custom class): >>> y = (1, 2, 3) # This is the 'hidden object' >>> S = set([y] + range(1)) >>> x = (1, 2, 3) >>> x in S True >>> x is y False I haven't found y. It's a very simple problem, and this is the simplest solution I can think of: class FindEqual(object): def __init__(self, obj): self.obj = obj def __hash__(self): return hash(self.obj) def __eq__(self, other): equal = self.obj == other if equal: self.lastequal = other return equal >>> yfinder = FindEqual(x) >>> yfinder in S True >>> yfinder.lastequal is y True I've found y! I'm not happy with this as it really is a trick. Is there a cleaner solution? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. You could use a dict. >>> y = (1, 2, 3) >>> S = {x: x for x in [y] + range(1)} >>> x = (1, 2, 3) >>> x in S True >>> x is y False >>> S[x] is y True -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On Fri, Jan 25, 2013 at 4:30 PM, Ian Kelly wrote: > On Fri, Jan 25, 2013 at 4:14 PM, Arnaud Delobelle wrote: >> Dear Pythoneers, >> >> I've got a seemingly simple problem, but for which I cannot find a >> simple solution. >> >> I have a set of objects (say S) containing an object which is equal to >> a given object (say x). So >> >> x in S >> >> is true. So there is an object y in S which is equal to x. My >> problem is how to retrieve y, without going through the whole set. > > You could use a dict. > y = (1, 2, 3) S = {x: x for x in [y] + range(1)} x = (1, 2, 3) x in S > True x is y > False S[x] is y > True Or you could use a set intersection: >>> S = set([y] + list(range(1))) >>> S.intersection([x]).pop() (1, 2, 3) In my testing, the time needed for this is small and does not seem to depend on the size of the set. -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On 2013-01-25 23:14, Arnaud Delobelle wrote: Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to retrieve y, without going through the whole set. Here is a simple illustration with tuples (my actual scenario is not with tuples but with a custom class): y = (1, 2, 3) # This is the 'hidden object' S = set([y] + range(1)) x = (1, 2, 3) x in S True x is y False You could first limit the search to only those which it could be: S & set([y]) A search would be: >>> f = [m for m in S & set([y]) if m is y][0] >>> f is y True -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On 01/25/2013 03:14 PM, Arnaud Delobelle wrote: I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to retrieve y, without going through the whole set. Here is a simple illustration with tuples (my actual scenario is not with tuples but with a custom class): y = (1, 2, 3) # This is the 'hidden object' S = set([y] + range(1)) x = (1, 2, 3) x in S True x is y False I haven't found y. It's a very simple problem, and this is the simplest solution I can think of: class FindEqual(object): def __init__(self, obj): self.obj = obj def __hash__(self): return hash(self.obj) def __eq__(self, other): equal = self.obj == other if equal: self.lastequal = other return equal yfinder = FindEqual(x) yfinder in S True yfinder.lastequal is y True I've found y! I'm not happy with this as it really is a trick. Is there a cleaner solution? I don't know if there is a cleaner solution, and I quite like yours. Can you tell us, though, why you have to have y if x == y? Is there some subtle difference between the two equal objects? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On 01/25/2013 06:14 PM, Arnaud Delobelle wrote: Dear Pythoneers, I've got a seemingly simple problem, but for which I cannot find a simple solution. I have a set of objects (say S) containing an object which is equal to a given object (say x). So x in S is true. So there is an object y in S which is equal to x. My problem is how to retrieve y, without going through the whole set. Here is a simple illustration with tuples (my actual scenario is not with tuples but with a custom class): y = (1, 2, 3) # This is the 'hidden object' S = set([y] + range(1)) x = (1, 2, 3) x in S True x is y False I haven't found y. Baloney. You've got the item y which is equal to x, not identical to x. So just what did you expect? "is" is the wrong comparator. What exactly is your problem? -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Pattern For Logging Into A Website
On 01/25/2013 01:18 PM, Michael Torrie wrote: On 01/25/2013 09:18 AM, Tim Daneliuk wrote: On 01/25/2013 10:01 AM, Steve Petrie wrote: On Thursday, January 24, 2013 8:29:51 PM UTC-5, Tim Daneliuk wrote: The mechanize module (http://wwwsearch.sourceforge.net/mechanize/) might be a place to start. I've done something similar with code like this: Thanks. I've had good luck using urllib2 and a cookiejar. Just post your login credentials against the login url, keep all the cookies and then make your other requests using that cookiejar. Besides the Python standard library docs on urllib2 and cookielib, here's an article that gives an overview of how to use it: http://www.techchorus.net/using-cookie-jar-urllib2 This technique has the advantage of not requiring anything outside of the standard library. Does it handle self-signed SSL certs? -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PGP/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: > You could first limit the search to only those which it could be: > > S & set([y]) > > A search would be: > f = [m for m in S & set([y]) if m is y][0] f is y > True But in practice he won't have y, only x. So that would have to be: >>> f = [m for m in S & set([x]) if m is x][0] >>> f is y False And it turns out that my earlier "intersection" suggestion fails for the same reason. -- http://mail.python.org/mailman/listinfo/python-list
Re: finding abc's
for future reference, i decided to go with 2 functions: def common_bases(classes): if not len(classes): return None common = set(classes.pop().mro()) for cls in classes: common.intersection_update(cls.mro()) #all subclasses in common return [cls for cls in common if not any(sub in common for sub in cls.__subclasses__())] #the classes of which no subclasses are present def unique_common_base(classes): while len(classes) > 1: classes = common_bases(classes) return classes.pop() if i tested and understood correctly, they only take classes in the mro() into account (which might include abc's), the first gives all common base classes, the second recursively reduces further to one single class (the latter might not make to much sense, but in my program it is a safe bet for rare cases). Thanks again for the help, Cheers, Lars -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
On 2013-01-26 00:26, Ian Kelly wrote: On Fri, Jan 25, 2013 at 4:45 PM, MRAB wrote: You could first limit the search to only those which it could be: S & set([y]) A search would be: f = [m for m in S & set([y]) if m is y][0] f is y True But in practice he won't have y, only x. So that would have to be: f = [m for m in S & set([x]) if m is x][0] f is y False And it turns out that my earlier "intersection" suggestion fails for the same reason. It turns out that both S & {x} and {x} & S return {x}, not {y}. OK, so... The members that don't equal x are S - {x}. Remove those and you get the members that _do_ equal x: >>> (S - (S - {x})).pop() is y True -- http://mail.python.org/mailman/listinfo/python-list
Toontown
Hi i am working on tryin to import texture into Toontown. It involves PyDatagrams, Billboard 3d textures and the tt server if anyone could help please post below or aim me at: gamerboy1...@yahoo.com :) Thanks. ps: For those of you that do not know toontown runs on python coding. -- http://mail.python.org/mailman/listinfo/python-list
doctests/unittest problem with exception
Hello. I converted doctests into DocTestSuite() to use with unittest. And try it under Python 3. And, sure, I get errors with unmatched exceptions details (mismatched name of exception class: a.b.c.MyError instead of MyError). So, I have 2 questions: 1) how to turn on option IGNORE_EXCEPTION_DETAIL for all doctests in DocStestSuite (like 'optionflags' argument in doctest.testmod()) 2) Is a way to ignore all 'package path' of exception but not message? Something like: ---cut--- Traceback (most recent call last): ... ...MyError: 'details are not ignored!' ---cut--- see, ellipsis-prefix in MyError -- http://mail.python.org/mailman/listinfo/python-list
Fonts & Tinker
I am changing the default font for a Tkinter application: class FuelControl(Tkinter.Frame): def __init__(self,master): self.version='0.02' self.font=tkFont.Font(family="Helvetica",size=18) print self.font.actual() . . . and everything looks ok: {'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18} and the size of the text are 18 on the screen. Then a button creates a new window through this callback: def loc_add(self): addw=Tix.Tk() addw.title('Add location') print self.font.actual() Tkinter.Label(addw,text='Nickname:', font=self.font).grid(row=0,column=0) Tkinter.Label(addw,text='Fullname:', font=self.font).grid(row=1,column=0) Tkinter.Label(addw,text='Address:', font=self.font).grid(row=2,column=0) Tkinter.Label(addw,text='Fuel name:',font=self.font).grid(row=3,column=0) ... The self.font stays with the right value: {'family': 'Nimbus Sans L', 'weight': 'normal', 'slant': 'roman', 'overstrike': 0, 'underline': 0, 'size': 18} but the real displayed fonts in the window are smaller (default size of 12, maybe). Am I missing something? Thanks in advance, A. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fonts & Tinker
Dammm it should be Tkinter for subject..:D -- http://mail.python.org/mailman/listinfo/python-list
Re: Fonts & Tinker
class FontSpec: """Wrapper for something like 'Arial 10 bold #red' """ tkf = None # Tk Font spec = "" # specification tkspec = "" # specification for Tk family = None size = 0 color = "black" weight = "normal" slant = "roman" underline = 0 overstrike = 0 linespace = 0 descent = 0 ascent = 0 def __init__(self, spec=None): """spec: familty with capital letter, color with # (#red, ##FF00FF), size - int, other are styles""" try: if not spec: return spec = spec.split() family = [s for s in spec if s.istitle()] if family: self.family = family[0] spec.remove(self.family) color = [s for s in spec if s.startswith('#')] if color: self.color = color[0] spec.remove(self.color) self.color = self.color[1:] size = [s for s in spec if s.isdigit()] if size: self.size = size[0] spec.remove(self.size) self.size = int(self.size) if "bold" in spec: self.weight = "bold" if "italic" in spec: self.slant = "italic" if "underline" in spec: self.underline = 1 if "overstrike" in spec: self.overstrike = 1 # create tkFont for metrics self.tkf = tkFont.Font(family=self.family, size=self.size, weight=self.weight, slant=self.slant, underline=self.underline, overstrike=self.overstrike) self.ascent = self.tkf.metrics("ascent") self.descent = self.tkf.metrics("descent") self.linespace = self.tkf.metrics("linespace") # tkspec - specific. of font in Tk standard self.tkspec = [] if self.family: self.tkspec.append(self.family) if self.size: self.tkspec.append(str(self.size)) if self.weight == "bold": self.tkspec.append("bold") if self.slant == "italic": self.tkspec.append("italic") if self.underline: self.tkspec.append("underline") if self.overstrike: self.tkspec.append("overstrike") self.tkspec = " ".join(self.tkspec) except: raise ValueError("invalid font specification") def __str__(self): return self.tkspec --- only for ideas -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
Arnaud Delobelle wrote: > Dear Pythoneers, > > I've got a seemingly simple problem, but for which I cannot find a > simple solution. > > I have a set of objects (say S) containing an object which is equal to > a given object (say x). So > > x in S > > is true. So there is an object y in S which is equal to x. My > problem is how to retrieve y, without going through the whole set. Why do you care? Since x == y, what benefit do you get from extracting the actual object y? I'm not necessarily saying that you *should not* care, only that it is a very rare occurrence. The only thing I can think of is interning objects, which is best done with a dict, not a set: CACHE = {} def intern(obj): return CACHE.setdefault(obj, obj) which you could then use like this: py> s = "hello world" py> intern(s) 'hello world' py> t = 'hello world' py> t is s False py> intern(t) is s True However, there aren't very many cases where doing this is actually helpful. Under normal circumstances, object equality is much more important than identity, and if you find that identity is important to you, then you probably should rethink your code. So... now that I've told you why you shouldn't do it, here's how you can do it anyway: def retrieve(S, x): """Returns the object in set S which is equal to x.""" s = set(S) # make a copy of S s.discard(x) t = S.difference(s) if t: return t.pop() raise KeyError('not found') S = set(range(10)) y = (1, 2, "hello world") x = (1, 2, "hello world") assert x is not y and x == y S.add(y) z = retrieve(S, x) assert z is y By the way, since this makes a copy of the set, it is O(n). The straight-forward approach: for element in S: if x == element: x = element break is also O(n), but with less overhead. On the other hand, the retrieve function above does most of its work in C, while the straight-forward loop is pure Python, so it's difficult to say which will be faster. I suggest you time them and see. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Pattern For Logging Into A Website
On 01/25/2013 05:15 PM, Tim Daneliuk wrote: > Does it handle self-signed SSL certs? No idea. you'd have to try it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving an object from a set
MRAB wrote: > It turns out that both S & {x} and {x} & S return {x}, not {y}. curious. $ python Python 2.7.3 (default, Jul 3 2012, 19:58:39) [GCC 4.7.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = (1,2,3) >>> y = (1,2,3) >>> s = set([y]) >>> (s & set([x])).pop() is y False >>> (set([x]) & s).pop() is y True maybe it's implementation-defined? -- ZeD -- http://mail.python.org/mailman/listinfo/python-list