Re: makepy.py not working
On Tue, Apr 8, 2008 at 4:18 PM, [EMAIL PROTECTED] wrote: Hallo, I've a problem getting makepy running. When I start the tool on my machine with doubleclick everything is fine. But when I try this in my Code: makepy.py -i Microsoft Excel 11.0 Object Library(1.5) This syntax is used to run makepy.py script from command line. I am getting an Syntax Error and command: makepy.py bring me this message on the screen: Traceback (most recent call last): File interactive input, line 1, in module NameError: name 'makepy' is not defined Any ideas what I am doing wrong? Python interpreter obviously accepts only valid python code, like this: import win32com.client.makepy win32com.client.makepy.ShowInfo(Microsoft Excel 11.0 Object Library(1.5)) -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Data Utils
On Sun, Apr 6, 2008 at 7:43 AM, Jesse Aldridge [EMAIL PROTECTED] wrote: In an effort to experiment with open source, I put a couple of my utility files up a href=http://github.com/jessald/python_data_utils/ tree/masterhere/a. What do you think? Would you search for, install, learn and use these modules if *someone else* created them? -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: UML reverse engineering
On Fri, Apr 4, 2008 at 6:51 PM, [EMAIL PROTECTED] wrote: Hello, Do you know a free software witch can compute a UML class diagram from a python code. I tested many free UML softwares like BoUML, ArgoUML, Dia, PNSource (not found) ... Did you mean /PyNSource/ ? (http://www.atug.com/andypatterns/pynsource.htm) -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib and bypass proxy
On Thu, Apr 3, 2008 at 9:21 PM, kc [EMAIL PROTECTED] wrote: If this has value, do I submit a bug report or does someone else? You do :) (http://bugs.python.org) -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: xlrd and cPickle.dump
On Wed, Apr 2, 2008 at 5:23 PM, [EMAIL PROTECTED] wrote: Still no luck: Traceback (most recent call last): File C:\Python24\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py, line 310, in RunScript exec codeObject in __main__.__dict__ File C:\text analysis\pickle_test2.py, line 13, in ? cPickle.dump(Data_sheet, pickle_file, -1) PicklingError: Can't pickle type 'module': attribute lookup __builtin__.module failed My code remains the same, except I added 'wb' and the -1 following your suggestions: import cPickle,xlrd, sys print sys.version print xlrd.__VERSION__ data_path = C:\\test\\test.xls pickle_path = C:\\test\\pickle.pickle book = xlrd.open_workbook(data_path) Data_sheet = book.sheet_by_index(0) pickle_file = open(pickle_path, 'wb') cPickle.dump(Data_sheet, pickle_file, -1) pickle_file.close() FWIW, it works here on 2.5.1 without errors or warnings. Ouput is: 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] 0.6.1 ... My code does this, except sort returns None, which is strange. list.sort() is documented to return None. See sorted(). -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: non-terminating regex match
On Wed, Apr 2, 2008 at 9:32 PM, Maurizio Vitale [EMAIL PROTECTED] wrote: Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes: On Wed, 02 Apr 2008 16:01:59 +, Maurizio Vitale wrote: And yes, I'm a total beginner when it comes to Python, but it seems very strange to me that a regex match on a finite length string doesn't terminate It does terminate, you just don't wait long enough. Try it with fewer characters and then increase the identifier character by character and watch the time of the runs grow exponentially. Ok. Now, my assumption was that re.compile would produce a DFA (or NFA) and the match would then being linear in the size of the string. No, it's easy to come up with regex that would perform exponentially by nesting repeated groups. Apparently this is not the case, so is there anything that can be done to the regex itself to make sure that whatever re.compile produces is more efficient? Avoid catastrophic backtracking: http://www.regular-expressions.info/catastrophic.html -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python queue madness
On Wed, Apr 2, 2008 at 4:52 PM, nnp [EMAIL PROTECTED] wrote: Is there any other way for data to get onto a queue Yes, by manipulating Queue.Queue's internal queue attribute directly. or are there any known bugs with Python's Queue module that could lead to this kind of behaviour? Much more likely your code has some unexpected behavior. Could you arrange a minimal example that reproduces the problem? -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: default method parameter behavior
On Wed, Apr 2, 2008 at 10:59 PM, [EMAIL PROTECTED] wrote: I ran into a similar situation like the following (ipython session). Can anyone please explain why the behavior? Of course. From http://docs.python.org/ref/function.html: Default parameter values are evaluated when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that that same ``pre-computed'' value is used for each call. This is especially important to understand when a default parameter is a mutable object, such as a list or a dictionary: if the function modifies the object (e.g. by appending an item to a list), the default value is in effect modified. -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Why prefer != over for Python 3.0?
On Tue, Apr 1, 2008 at 12:04 PM, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 01 Apr 2008 04:15:57 -0300, Jorge Vargas [EMAIL PROTECTED] escribió: as for the original question, the point of going unicode is not to make code unicode, but to make code's output unicode. thin of print calls and templates and comments the world's complexity in languages. sadly most english speaking people think unicode is irrelevant because ASCII has everything, but their narrow world is what's wrong. Python 3 is a good step in that direction. Strings are unicode, identifiers are not restricted to ASCII, and the default source encoding is not ASCII anymore (but I don't remember which one). UTF-8 (http://python.org/dev/peps/pep-3120/) -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a good time to start learning python?
Backward compatibility is important. C++ could break all ties with C to clean up as well, but it would be a braindead move that would break existing code bases upon upgrade. C++ is not C. No one upgrades from C to C++. You misunderstand. C++ has a lot of warts to maintain backwards compatibility with C. The standards committee could eliminate these warts to make the language cleaner, but it would break a lot of systems. Didn't C++ break all C programs that happened to use class for identifier? :) -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: XML Parsing
On Tue, Apr 1, 2008 at 10:42 PM, Alok Kothari [EMAIL PROTECTED] wrote: Hello, I am new to XML parsing.Could you kindly tell me whats the problem with the following code: import xml.dom.minidom import xml.parsers.expat document = token pos=nnLetterman/tokentoken pos=bezis/ tokentoken pos=jjrbetter/tokentoken pos=csthan/ tokentoken pos=npJay/tokentoken pos=npLeno/token This document is not well-formed. It doesn't have root element. ... Traceback (most recent call last): File C:/Python25/Programs/eg.py, line 20, in module p.Parse(document, 1) ExpatError: junk after document element: line 1, column 33 Told ya :) Try wrapping your document in root element, like tokenstoken.../tokentoken.../token/tokens -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: import multiple modules with same name
On Mon, Mar 31, 2008 at 11:52 PM, Christian Bird [EMAIL PROTECTED] wrote: Is it possible to import multiple modules with the same name from different locations? This might work: import imp util1 = imp.load_source('util1', 'mod1/util.py') util2 = imp.load_source('util2', 'mod2/util.py') But using packages is cleaner. -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Create executable from executable with py2exe
On Sat, Mar 29, 2008 at 3:23 PM, [EMAIL PROTECTED] wrote: Hello, Is there any example how can I create executable ... with py2exe Check out PyBuilder's source code (http://pybuilder.sourceforge.net/). -- kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and xml
On Sat, Mar 29, 2008 at 3:57 PM, Doran, Harold [EMAIL PROTECTED] wrote: I am a python neophyte who has used python to parse through text files using basic functions and no OOP experience. I have a need to process some xml files and from what I am now reading python is the exact tool I need to work through this issue. However, as I read online docs and peruse which books to buy, I am quickly becoming overwhelmed with the topic and could use some guidance on how to best tackle my task. You can start with this basic example (requires Python 2.5): spam.xml: monty episode number=14Dinsdale (Face the Press)/episode episode number=15The Spanish Inquisition/episode episode number=16Deja vu/episode episode number=17The Buzz Aldrin Show/episode episode number=18Live From the Grill-O-Mat Snack Bar/episode episode number=19It's a Living/episode episode number=20The Attila the Hun Show/episode episode number=21Archaeology Today/episode episode number=22How to Recognize Different Parts of the Body/episode episode number=23Scott of the Antarctic/episode episode number=24How Not to Be Seen/episode episode number=25Spam/episode episode number=26Royal Episode 13/episode /monty spam.py: from xml.etree.ElementTree import ElementTree as ET et = ET(file='spam.xml') for episode in et.findall('episode'): print episode.attrib['number'] + ':', '' + episode.text + '' Use standard csv module if you want to produce csv ouput ( http://docs.python.org/lib/module-csv.html). -- kv -- http://mail.python.org/mailman/listinfo/python-list
Decimal(1) 0.0 == False
Hello, I'm having hard time trying to justify this decimal quirk to my coworker (he calls it a bug): ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import decimal 2.0 decimal.Decimal(1) 0.0 False Why False? It's so counter-intuitive. I understand that it may not be possible to do precise comparison of decimal and float, but an exception would be so much better than silent False! - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
On 25 Jun 2005 12:17:20 -0700, George Sakkis [EMAIL PROTECTED] wrote: If they go to itertools, they can simply be: def map(f, *iterables): return list(imap(f,*iterables)) def filter(f, seq): return list(ifilter(f,seq)) from itertools import ifilter def filter(f, seq): ... return list(ifilter(f,seq)) filter(str.isalpha, 'not quite!') ['n', 'o', 't', 'q', 'u', 'i', 't', 'e'] __builtins__.filter(str.isalpha, 'not quite!') 'notquite' - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: noob question
On 6/26/05, Matt Hollingsworth [EMAIL PROTECTED] wrote: Seems like an _extremely_ elegent language that is very easy to read, so I suppose it's not really as much of an issue as it is with other languages. Still, I would like to see what other people do and what are some good ideas for this kind of thing. Nouns-for-variables vs. verbs-for-functions work for me equally well in Python, C++ and C#. I rarely feel the need for hungarian notation, but it has it's uses (and abuses); see http://joelonsoftware.com/articles/Wrong.html - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: windows service problem
On 6/24/05, Austin [EMAIL PROTECTED] wrote: def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.check = 1 Change last two lines to self.check = 1 self.hWaitStop = win32event.CreateEvent(None, 0, 1, None) (SvcDoRun is waiting for hWaitStop event, but you never signal it.) - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Office COM automatisation - calling python from VBA
On 6/25/05, Stephen Prinster [EMAIL PROTECTED] wrote: guy lateur wrote: If you are new to Python and want to use it with COM, definitely get yourself a copy of _Python Programming on Win32_ by Mark Hammond and Andy Robinson. ...or at least read the chapter available online: http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html It has an example of VBA / PythonCOM interaction. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Office COM automatisation - calling python from VBA
On 6/25/05, Josef Meile [EMAIL PROTECTED] wrote: You could try to do an addin/addon for Word, Excel, and Outlook. You don't need to code with VBA. Here you just need a language from where you can access the microsoft interop assemblies (ie: C++ or C#; IronPython maybe?) Hmm... Why jump through .NET hoops when all you need is COM? I suppose msoffice interops are no different than other .NET interops, which are just that - .NET/COM interoperability layer. There's no need for them unless you're calling COM from .NET. For CPython win32com should be enough. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: super problem
On 6/25/05, Uwe Mayer [EMAIL PROTECTED] wrote: AFAIK super only works with new-style classes, so I checked: from qtcanvas import * isinstance(QCanvasItem, object) True AFAIK, this is not the right way to check for new-styledness: class X: i'm an old-styler isinstance(X(), object) True But this is: isinstance(X, type) False - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
On 6/25/05, Mandus [EMAIL PROTECTED] wrote: It is really a consensus on this; that removing map, filter, reduce is a good thing? It will render a whole lot of my software unusable :( I think you'll be able to use from __past__ import map, filter, reduce or something like that :) They don't have to be built-in. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
On 6/25/05, Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 24 Jun 2005 14:29:37 -0700, James wrote: 2.) Contracts Explain please. James probably meant Eiffel's Design by Contract. My favourite Python implementation is Terence Way's http://www.wayforward.net/pycontract/ ;-) - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
On 6/25/05, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 25 Jun 2005 17:41:58 +0200, Konstantin Veretennicov wrote: On 6/25/05, Mandus [EMAIL PROTECTED] wrote: It is really a consensus on this; that removing map, filter, reduce is a good thing? It will render a whole lot of my software unusable :( I think you'll be able to use from __past__ import map, filter, reduce or something like that :) They don't have to be built-in. More likely they will be moved to something like itertools than __past__. Or just define them yourself: def map(f, seq): return [f(x) for x in seq] def filter(p, seq): return [x for x in seq if p(x)] def reduce(f, seq, zero): r = zero for x in seq: r = f(r, x) return r FWIW, these don't exactly reproduce behaviour of current built-ins. Filter, for instance, doesn't always return lists and map accepts more than one seq... Just my $.02. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: printing indented html code
On 6/24/05, Lowell Kirsh [EMAIL PROTECTED] wrote: Is there a module or library anyone knows of that will print html code indented? Depends on whether you have to deal with xhtml, valid html or just any, possibly invalid, pseudo-html that abounds on the net. Here's an example of (too) simple html processing using standard HTMLParser module: from HTMLParser import HTMLParser class Indenter(HTMLParser): def __init__(self, out): HTMLParser.__init__(self) self.out = out self.indent_level = 0 def write_line(self, text): print self.out, '\t' * self.indent_level + text def handle_starttag(self, tag, attrs): self.write_line( '%s %s' % (tag, ' '.join('%s=%s' % (k, v) for k, v in attrs)) ) self.indent_level += 1 def handle_endtag(self, tag): self.indent_level -= 1 self.write_line('/%s' % tag) handle_data = write_line # handle everything else... # http://docs.python.org/lib/module-HTMLParser.html if __name__ == '__main__': import sys i = Indenter(sys.stdout) i.feed('htmlheadfoobar/headbody color=0body/body/html') i.close() - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoiding deadlocks in concurrent programming
On 22 Jun 2005 17:50:49 -0700, Paul Rubin http://phr.cx@nospam.invalid wrote: Even on a multiprocessor system, CPython (because of the GIL) doesn't allow true parallel threads, ... . Please excuse my ignorance, do you mean that python threads are always scheduled to run on the same single CPU? Or just that python threads are often blocked waiting for GIL? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP ? os.listdir enhancement
On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: string capitalize sentence
On 6/24/05, dimitri pater [EMAIL PROTECTED] wrote: a = 'harry is a strange guy. so is his sister, but at least she is not a guy. i am.' b = a.replace('. ', '.') splitlist = b.split('.') newlist = [] for i in range(len(splitlist)): i = ''.join(splitlist[i].capitalize() + '.' newlist.append(i) cap = ' '.join(newlist).replace(' .', '') print cap A simpler version would be: s = 'harry is a strange guy. so is his sister, but at least she is not a guy . i am.' a = s.split('. ') # you can split at multicharacter strings b = (x.capitalize() for x in a) # you can use generator expressions to generate lists '. '.join(b) 'Harry is a strange guy. So is his sister, but at least she is not a guy. I am.' it doesn't work with: is harry a strange guy? so is his sister, but at least she is not a guy. i am. I believe you'll need re.split to accomplish that. Regards, - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: suggestions invited
On 23 Jun 2005 12:30:27 -0700, Aditi [EMAIL PROTECTED] wrote: Thanks for ur effort... And I apologise for being sloppy in writing. Well I agree the whole project sounds fictitious because it has been assigned to me in that spirit. The project was explained to me in just 5 minutes and so these are the only details I have and the only documentation I have is a list of the 31 applications used in the company and that the platform used in the company is OS 400. Pardon me, is it a real company or a fictious one? The reason why I posted this mail was to invite ideas as to how could I make the best use of these details and suggestions because I myself found these details way too less. I think I should have written about this in the first mail to avoid frustration to the people who are trying to help me. Anyways now that it is known that the project has been assigned to me just for the heck of it would like to make my project such that they want to use it...I would definately not let my work go wasted...So do let me know what you think could be done in this direction. If you have real users, your first step is to talk to them to define project goals. Everything else (xml, python, etc.) is irrelevant until you know *what* you want to build. Go talk to your potential users, know why (if at all) they need this monitoring system, learn their current tools and processes, see how your system could help them do their job more efficiently. Don't start coding until you have clear understanding of requirements. There are lots of nice intelligent people on this list, but they can't substitute people you are building this system for :) - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: suggestions invited
On 22 Jun 2005 02:47:06 -0700, Aditi [EMAIL PROTECTED] wrote: i have to make a system used by the IT department of a company which contains 31 applications and their details which are being used in a company ...the details are... Application sub application catagoryplatform languageversion IT owner functional ownerremarks source code documentation last updated dates i want to design a system such that it lets the it employee enter the name of the application and gives him all the details about it...please suggest an appropriate design Ahem... Create a directory appmon. In this directory create a text file for each application. Put application details in file and name it after application name. Users will be able to view details of a particular application by using cat appname on unix or type appname on windows, thus it is a portable solution. I believe this design fits your requirements :) - kv -- http://mail.python.org/mailman/listinfo/python-list
Re:
On 6/22/05, Doug Ly [EMAIL PROTECTED] wrote: Is there a good IDE for Python? See http://tinyurl.com/8jqjc - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python API to manipulate CAB files.
On 6/22/05, Peter Maas [EMAIL PROTECTED] wrote: Isaac Rodriguez schrieb: Does anyone know of a Python API to manipulate CAB files? I guess you'll have to interface with setupapi.dll (SetupIterateCabinet) via ctypes, or with Microsoft Cabinet utilities via subprocess module. Neither is what people call fun... - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Avoiding deadlocks in concurrent programming
On 6/23/05, Steve Horsley [EMAIL PROTECTED] wrote: It is my understanding that Pythons multithreading is done at the interpteter level and that the interpreter itself is single threaded. In this case, you cannot have multiple threads running truly concurrently even on a multi-CPU machine Python uses native threads. import thread, win32api win32api.GetCurrentThreadId() 1532 def t(): ... print win32api.GetCurrentThreadId() ... for i in range(10): ... thread.start_new_thread(t, ()) ... 1212 1804 804 1276 1792 ... - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Detect windows shutdown
On 6/22/05, Austin [EMAIL PROTECTED] wrote: My program is running on windows and it is wrritten by Python and wxPython, ... Is there any way to dectect windows shutdown or reboot? Will wx.EVT_END_SESSION or wx.EVT_QUERY_END_SESSION help? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: after transfer of data from MS-outlook(mail ids) to application, mail ids are consisting of strange characters
On 20 Jun 2005 22:24:09 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello all, ... I hope somebody will help me in this regard to unfold this mystery.Bye. I hope you will explain how this is related to Python. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: .dll files
On 20 Jun 2005 23:56:50 -0700, Sabin.A.K [EMAIL PROTECTED] wrote: Will the COM Object be a total solution for my problems? I just try to make a dll to encapsulate some 'icon and text' files for my application. Are you trying to create a windows resource dll? I believe Python isn't the tool for this job. What is your main application created with? How do you plan to extract 'icons and text' from this dll? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto access a enumeration in a COM TypeLib
On 6/21/05, Alexander Eisenhuth [EMAIL PROTECTED] wrote: Hello alltogether, I hope somebody can help me in that case. I bet I have overseen s.th.. I have a VC++ IDispatch Com-Server (ATL) and include for error handling issues a enumeration in the IDL-File. [...] enum PROG_ERROR { P_OK = 0, P_ERR_01 = 1, P_ERR_02 = 2, ... } typedef enum PROG_ERROR PROG_ERROR_T; [...] I can acess the COM object using : obj = win32com.client.Dispatch(...) and can Load the TypeLib: lib = pythonwin.LoadTypeLib(...) and see the enumeration in the OLE-Browser of Windows, but don't know how to access the enum in Python. Any help and hints are very welcome. Regards Alexander PS.: I use the actual version of ActivePython 2.4. Use site-packages/win32com/client/makepy.py to produce myserver.py from your typelib file, then import myserver print myserver.constants. P_OK 0 Maybe you can access constants without makepy, I don't know. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Using code objects?
On 6/21/05, Chinook [EMAIL PROTECTED] wrote: When I create the code objects though, it seems a couple different ways work and I'm wondering which is better and why (or is there a more correct technique in this situation)? The two different ways are illustrated below: ... obj1 = compile(exp1, 'whatever', 'single') ... obj2 = compile(exp2, 'whatever', 'exec') Are you essentially asking about difference between compile(..., 'single') and compile(..., 'exec'), which is described in http://docs.python.org/lib/built-in-funcs.html ? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
On 6/21/05, Charles Krug [EMAIL PROTECTED] wrote: Related question: What if I need to create/modify MS-Access or SQL Server dbs? You could use ADO + adodbapi for both. http://adodbapi.sourceforge.net/ - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Loop until condition is true
On 6/21/05, Magnus Lycka [EMAIL PROTECTED] wrote: I don't know anything about the Python compiler internals, but it doesn't seem very hard to identify simple literals following while and if, and to skip the runtime test. (Perhaps it's done already?) True doesn't seem to be a literal, it is looked up by name and can be rebound to, say, 0 anytime: import dis o = compile('while True: pass', 'string', 'exec') dis.dis(o) 1 0 SETUP_LOOP 12 (to 15) 3 LOAD_NAME0 (True) 6 JUMP_IF_FALSE4 (to 13) 9 POP_TOP 10 JUMP_ABSOLUTE3 ... OTOH, p = compile('while 1: pass', 'string', 'exec') dis.dis(p) 1 0 SETUP_LOOP 5 (to 8) 3 JUMP_ABSOLUTE3 ... - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 silly question
On 6/21/05, Jeff Epler [EMAIL PROTECTED] wrote: If you want to work with unicode, then write us = u\N{COPYRIGHT SIGN} some text ...and you can get unicode character names like that from unicodedata module: import unicodedata unicodedata.name(unichr(169)) 'COPYRIGHT SIGN' See also http://www.unicode.org/charts/charindex.html - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: JEP and JPype in a single process
On 6/20/05, skn [EMAIL PROTECTED] wrote: Hello, I have written a very simple java class file, which invokes a Python script using JEP. . . . Now inside this Python script I want to make Java calls using JPype. I am not familiar with either Jepp or JPype, but I spotted this snippet on Jepp page (http://jepp.sourceforge.net/): import jep FileInputStream = jep.findClass('java.io.FileInputStream') try: fin = FileInputStream('adsf') except jep.FileNotFoundException: print 'Invalid file' Are you sure you need to call JPype? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and encodings drives me crazy
On 6/20/05, Oliver Andrich [EMAIL PROTECTED] wrote: Does the following code write headline and caption in MacRoman encoding to the disk? f = codecs.open(outfilename, w, macroman) f.write(headline) It does, as long as headline and caption *can* actually be encoded as macroman. After you decode headline from utf-8 it will be unicode and not all unicode characters can be mapped to macroman: u'\u0160'.encode('utf8') '\xc5\xa0' u'\u0160'.encode('latin2') '\xa9' u'\u0160'.encode('macroman') Traceback (most recent call last): File stdin, line 1, in ? File D:\python\2.4\lib\encodings\mac_roman.py, line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u0160' in position 0: character maps to undefined - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about HTMLgen
On 6/20/05, Sebastian Bassi [EMAIL PROTECTED] wrote: Hello, I am using HTMLgen. It is very nice. But I can't make it to generate an arbitrary command. For example I want to output this: embed src=canvas_norelief.svg width=140 height=68 type=image/svg+xml name=wmap wmode=transparent Works for me... d = HTMLgen.BasicDocument() d.append('embed src=canvas_norelief.svg ... ') print d !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 3.2//EN HTML !-- This file generated using Python HTMLgen module. -- HEAD META NAME=GENERATOR CONTENT=HTMLgen 2.2.2 TITLE/TITLE /HEAD BODY embed src=canvas_norelief.svg ... /BODY /HTML - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: reading a list from a file
On 6/20/05, David Bear [EMAIL PROTECTED] wrote: I have a file that contains lists -- python lists. sadly, these are not pickled. These are lists that were made using a simple print list statement. Sad, indeed. But what kind of objects they held? Only ints? Ints and strings? Arbitrary objects? Is there an easy way to read this file into a list again? I'm thinking I would have to read until char = '[' read until char = ' Well, reading character by char until I have the list and then parse it all myself. At least you can leave tokenizing to python lib: import tokenize, token, pprint token_names = dict([ ... (value, name) for (name, value) ... in token.__dict__.iteritems() ... if isinstance(value, int)]) tokens = tokenize.generate_tokens( ... iter(['[1, 2, ab\'c,d]']).next) pprint.pprint([(token_names[t[0]], t[1]) for t in tokens]) [('OP', '['), ('NUMBER', '1'), ('OP', ','), ('NUMBER', '2'), ('OP', ','), ('STRING', 'ab\'c,d'), ('OP', ']')] - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: What makes an object uncopyable?
On 17 Jun 2005 15:41:07 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am trying to make a copy of a certain Python object using the copy.copy() function. When I try to perform this operation I get an error like the following: copy.Error: un(shallow)copyable object of type ... What factors determine whether an object can be copied? You are probably trying to copy an instance of a class implemented in C extension. AFAIK, Python classes have copy support by default, but extension classes need to implement copy/pickle protocol. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: thread.start_new_thread question
On 6/17/05, Brian [EMAIL PROTECTED] wrote: Hi KV, Here's a site that provides an easy, beginners example of how to do threading. You might find this useful too... :-) http://www.codesampler.com/python.htm (Look for the Spawning Threads section.) Thank you, but that doesn't answer my question. I was asking if there is a reason that args is not optional. Oftentimes functions I use to start_new_thread have no arguments (they may get data from bound instance or from closure), but still I have to pass empty args, always wondering, why? Python lib generally has a very nice and convenient interface and tries to supply sensible defaults when possible. That args is a required argument is a mystery to me :) - kv A. No. Q. Is top posting OK? -- http://mail.python.org/mailman/listinfo/python-list
Re: Set of Dictionary
On 6/16/05, Vibha Tripathi [EMAIL PROTECTED] wrote: Hi Folks, I know sets have been implemented using dictionary but I absolutely need to have a set of dictionaries... While you can't have a set of mutable objects (even dictionaries :)), you can have a set of immutable snapshots of those objects: d1 = {1: 'a', 2: 'b'} d2 = {3: 'c'} s = set([tuple(d1.iteritems()), tuple(d2.iteritems())]) s set([((3, 'c'),), ((1, 'a'), (2, 'b'))]) [dict(pairs) for pairs in s] [{3: 'c'}, {1: 'a', 2: 'b'}] - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Set of Dictionary
On 6/16/05, Vibha Tripathi [EMAIL PROTECTED] wrote: I need sets as sets in mathematics: That's tough. First of all, mathematical sets can be infinite. It's just too much memory :) Software implementations can't fully match mathematical abstractions. sets of any unique type of objects including those of dictionaries, I should then be able to do: a_set.__contains__(a_dictionary) and things like that. Maybe you can use a list for that: d1 = {1: 2} d2 = {3: 4} s = [d1, d2] {1: 2} in s True {5: 6} in s False Can sets in Python 2.4.1, be reimplemented from scratch to not have it work on top of dict? Sure, why not? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: which ports to use for SOAP?
On 6/17/05, Maurice LING [EMAIL PROTECTED] wrote: Hi, I'm writing something that specifies the use of SOAP. One requirement that fumbles me is the port number(s) to use. (I assume you're talking about TCP ports, not SOAP ports.) Is there any way to find out which ports are not used by the system? Try binding to a port and you'll get an 'Address already in use error' if it's occupied :) I've looked in the library reference and doesn't seems to get anything. Is there a problem with say 2 programs using the same ports? AFAIK, even the same process can't bind to the same port twice: import socket s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s1.bind(('localhost', 8000)) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.bind(('localhost', 8000)) Traceback (most recent call last): File stdin, line 1, in ? File string, line 1, in bind socket.error: (10048, 'Address already in use') - kv -- http://mail.python.org/mailman/listinfo/python-list
thread.start_new_thread question
Hi, Just curious: import thread help(thread.start_new_thread) . . . start_new_thread(function, args[, kwargs]) . . . Second argument is mandatory. Is it incidental or for a reason? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Single test for a class and all its subclasses?
On 6/15/05, Anthra Norell [EMAIL PROTECTED] wrote: class C: ... class C2 (C): ... # What I want to do: if x.__class__ in (C, C2): do_something_with (x) If you have an instance, you can use isinstance() built-in. - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: pyunit: remove a test case on the fly
On 15 Jun 2005 14:13:09 -0700, chris [EMAIL PROTECTED] wrote: We have a number of TestCase classes that have multiple test methods. We are interested in removing any of the individual test methods on the fly (dynamically, at runtime, whatever). Here's a simple approach imitating NUnit's CategoryAttribute. I don't know whether it'll work for you, it depends on what exactly isSupported() does. - kv import unittest def category(*test_categories): tc = frozenset(test_categories) def f(g): if tc frozenset(active_categories): return g # else return None, # effectively removing test from TestCase return f active_categories = ['mac', 'nt'] class T(unittest.TestCase): @category('mac') def test_a(self): print 'mac only' @category('posix') def test_b(self): print 'posix only' @category('posix', 'nt') def test_c(self): print 'posix or nt' def test_d(self): print 'platform-independent' if __name__ == '__main__': unittest.main() -- http://mail.python.org/mailman/listinfo/python-list