Re: Doubt
On Jul 24, 1:13 am, Fredrik Lundh [EMAIL PROTECTED] wrote: ജഗന്നാഥ് wrote: I am a Perl programmer new to Python. I have a small doubt. I suspect you mean question, not doubt. It's not quite the same thing. How to convert the perl notation $a = ; expression in Python ? Thank you for all to giving suggestions . With regards Jaganadh G How to represent the loop for ($a = $b; $a=$c;$a++){ } in Python Start here: http://www.lucasmanual.com/mywiki/PerlPythonPhrasebook and then read either of these (preferably both): http://www.swaroopch.com/byteofpython/ http://docs.python.org/tut/ /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing VHDL with python, where to start.
On Jul 23, 1:03 pm, [EMAIL PROTECTED] (c d saunter) wrote: How much of VHDL are you looking to parse? Are you just looking at files intended for synthesis, or at simulation/testbench files as well? As a start I want to parse VHDL which is going to be synthesised, and I am limiting myself to the entities and the structural component placement. I will drop the processes and the concurrent assignments even if that will mask important information. It is a design viewer tool, not a design tool that I am writing. Xilinx ISE do give me the opportunity to browse my synthesised netlist, but there is simply too much information. Later the app can be extended with more functionality, depends on my success with the initial problems that I have. If I started again I'd use pyparsing:http://pyparsing.wikispaces.com/ Looks like someone is already there in part:http://pyparsing.wikispaces.com/message/view/home/103973 I also got a pointer to SimpleParse and now try to translate the parts of the VHDL BNF that I need into a definition that SimpleParse can understand. But looking at the BNF it is clear that VHDL is no easy language to parse, just as it is no easy language to do structural design in. -- Svenn -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 1:41 pm, Jordan [EMAIL PROTECTED] wrote: Hi everyone, I'm a big Python fan who used to be involved semi regularly in comp.lang.python (lots of lurking, occasional posting) but kind of trailed off a bit. I just wrote a frustration inspired rant on my blog, and I thought it was relevant enough as a wider issue to the Python community to post here for your discussion and consideration. [...snip...] +1 for most of your opinion. I was also bitten by the __eq__/__ne__ problem this morning. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting cookies into a web session
John Gordon wrote: I'm developing a web application that needs a semi-persistent way to store information. I've looked at some options such as writing entries to a database table or creating small textfiles, but I'm not thrilled with anything I've come up with so far. What's the problem? Then a coworker suggested that I could just insert a cookie into the current session, which would store whatever information I wanted. This seems like a really good solution. That's what cookies are *for*, right? Before using cookies keep in mind that the cookies returned by the browser are not trustworthy! You have to validate the values each time. But I've never worked with cookies before. Is there a Python package for handling cookies? http://docs.python.org/lib/module-Cookie.html And are there any back-end requirements? No. I assume you would have to be running a webserver that supports sessions. You can do this all within your web application. Do you also have to be running some sort of web container or servlet engine? No. Ciao, Michael. -- http://mail.python.org/mailman/listinfo/python-list
EXCEL API
Hello, Does any one have a sample piece of code to search for a keyword in Excel sheet? if so plz post it.. Thanks, Girish.. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem doing unpickle in an exec statement
Danny Shevitz wrote: Howdy, In my app I need to exec user text that defines a function. I want this function to unpickle an object. Pickle breaks because it is looking for the object definition that isn't in the calling namespace. I have mocked up a simple example that shows the problem. Run this first code (from create_pickle.py) to create the pickle. create_pickle.py: (run this first) # import cPickle # the pickle file name file_name = 'd:\\temp\\test1.pickle' # define a class class Tree(object): pass def main(): # instantiate t = Tree() # create the sweet pickle fp = open(file_name, 'wb') cPickle.dump(t, fp) fp.close() # try to unpickle directly fp = open(file_name, 'rb') result = cPickle.load(fp) fp.close() print unpickling directly works just fine, result = , result if __name__=='__main__': main() # run this second: exec_pickle.py # # this file shows a problem with sweet pickle in an exec statement # the pickle file name file_name = 'd:\\temp\\test1.pickle' # code to be turned into a function code_text = ''' def include(): print this works! ''' # a function for creating functions def create_fun(code_text): clean_dict = {} exec code_text in clean_dict return clean_dict['include'] # include_fun is a bona fide function include_fun = create_fun(code_text) # this works include_fun() # now try to load the pickle in an exec statement code_text = ''' def include(file_name): print processing file_name: , file_name import cPickle fp = open(file_name, rb) result = cPickle.load(fp) fp.close() print result = , result ''' # create the new include_fun include_fun = create_fun(code_text) # run it include_fun(file_name) # Can anyone enlighten me what I need to do to exec_pickle.py to get this to work? Pickling saves the name of the module and the class (and of course the instance data). Because you put the class in your main script the module name is __main__, and when you unpickle later pickle imports __main__ which unfortunately is now a different script that doesn't contain the/a Tree class. To solve that problem put the Tree class in a separate module, say tree.py, that can be imported by both create_pickle.py and exec_pickle.py. You only need an explicit from tree import Tree in create_pickle. Peter -- http://mail.python.org/mailman/listinfo/python-list
parameterized classes
Is there is a better way to create parameterized classes than defining and returning a class in a closure? I ask because I want to create arbitrary BaseRequestHandler subclasses that delegate line handling to a given line handler, as in this example: from SocketServer import * class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass def LineRequestHandler(handler): class __LineRequestHandler(BaseRequestHandler): def handle(self): for line in self.lines(): handler.handle(line) def lines(self): line = self.line() while line: yield line line = self.line() def line(self): parts = [] while not parts or parts[-1] and not parts[-1][-1] == \n: parts.append(self.request.recv(2**10)) if parts: return ''.join(parts)[0:-1] return __LineRequestHandler class SomeLineHandler: def handle(self, line): print I got a line: %s % line if __name__ == '__main__': s = ThreadingTCPServer((, 2005), LineRequestHandler(SomeLineHandler())) s.serve_forever() I really wish I could create a class whose instances were classes that subclassed BaseRequestHandler. Is this possible, or is there a better way than my approach here? Or am I crazy? And I may be dense, so if there is an easier way to stream sockets as line streams, please let me know. I honestly don't think it should be this difficult to implement a socket handler this simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* This cannot be any longer blamed as a hangover from Java - I've written a ton more code, more recently in Python than in Java or any other OO language. What's more, every time I go back to Python after a break of more than about a week or so, I start making this 'mistake' again. The perennial justification for this 'feature' of the language? That old Python favourite, Explicit is better than implicit. Do you seriously think that Python is designed by mindless application of a set of humorous and somewhat self-deprecating observations posted to a newsgroup a number of years ago? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: parameterized classes
John Tantalo wrote: I really wish I could create a class whose instances were classes that subclassed BaseRequestHandler. Is this possible, or is there a better way than my approach here? Or am I crazy? no you so much as your code. unfortunately, it fails the decipher in allocated time slot test, though, so I hope someone else will have time to untangle it for you. And I may be dense, so if there is an easier way to stream sockets as line streams, please let me know. I honestly don't think it should be this difficult to implement a socket handler this simple. there's a StreamRequestHandler class in SocketServer that buffered streams via the rfile and wfile attributes. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: python.exe crash and ctypes use
On Jul 23, 4:39 pm, Thomas Heller [EMAIL PROTECTED] wrote: waldek schrieb: Hi, I have module A.py and B.dll which exports C functions by cdecl_ In A.py I pass callback (py callable) to dll. Next, thread inside dll simply calls my callback (in a loop). After few secs I got crash of python.exe. How to debug it? I'm using winxp and py 2.5.2 === def mycallback(data, size) return 0 CBFUNC = CFUNCTYPE(c_int,POINTER(c_int), c_int) dll = cdll.mydll if dll.RegisterCallback(CBFUNC(mycallback)) != 0: print Error. === You need the callback function instance - what the CBFUNC(mycallback) call returns - alive as long as some C code is calling it. If you don't sooner or later the Python garbage collector will free it since it seems to be no longer used. ctypes does NOT keep the callback function alive itself. Thomas In fact ctypes does not keep references to callback passed directly to dll. Now it works. Thanks Thomas. Waldek -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
Anthony wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily Python's IDLE has only half of the first of these features. I did a lot of searching and found the PyDev extensions for Eclipse's Python IDE, and found that they've got Intellisense. I'm still missing b and c, and am getting extremely frustrated programming so slowly.. So two questions: Is there any package, gui, IDE, anything that will do FoxPro-style code completion? If it works in Eclipse, even better.. I can't find a good screenshot, but here's a better description: You type BROW and it pops up a window that says BROWSE ..at this point if you hit enter it completes the word.. and How can I view open SPSS data in one of the Python GUIs? Again, Eclipse would be the preference. Here's an example of how I'd like to browse the data: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=vfptoolkit_figure02.tif I don't want to have to switch back and forth between Python and SPSS while I'm programming; I just want to stay in one of them.. What can I do? I feel extremely inefficient when I don't have these three features.. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list You might want to try vim. It has a steep learning curve, but definitely increases productivity _alot_. Here is a tutorial on setting up vim with : 1) Code completion (intellisense) - including tooltips (!!!) 2) Jump between your python code and the python class libraries. 3) Syntax checking 4) A handy source browser 5) Debugging (using pdb) 6) [All the other vim goodies - already included] Above instructions available here http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ I have been using the above setup for a while and find it superior to _any_ IDE I've ever worked with. I'm not sure what you mean by 'Data-Orientation' but I'm sure there's a suitable alternative/replacement for it in vim. Regards Nicolaas -- The three things to remember about Llamas: 1) They are harmless 2) They are deadly 3) They are made of lava, and thus nice to cuddle. -- http://mail.python.org/mailman/listinfo/python-list
Re: EXCEL API
On Jul 24, 5:15 pm, Girish [EMAIL PROTECTED] wrote in comp.lang.python: Hello, Does any one have a sample piece of code to search for a keyword in Excel sheet? if so plz post it.. 8--- xlkwsearch.py import xlrd, sys, glob def xlkwsearch(fname, query): book = xlrd.open_workbook(fname) for sheet in book.sheets(): for rowx in xrange(sheet.nrows): for colx in xrange(sheet.ncols): cell = sheet.cell(rowx, colx) if cell.ctype == xlrd.XL_CELL_TEXT and query in cell.value: yield fname, sheet.name, rowx, colx, cell.value if __name__ == '__main__': for fname in glob.glob(sys.argv[1]): for result in xlkwsearch(fname, sys.argv[2]): print result 8--- Sample output: D:\junkpython xlkwsearch.py *search*.xls hello ('search_demo.xls', u'Sheet1', 0, 0, u'hello') ('search_demo.xls', u'Sheet1', 2, 6, u'hello world') D:\junkpython xlkwsearch.py *search*.xls world ('search_demo.xls', u'Sheet1', 1, 1, u'world') ('search_demo.xls', u'Sheet1', 2, 6, u'hello world') ('search_demo.xls', u'2nd Sheet', 0, 0, u'underworld') ('search_demo.xls', u'2nd Sheet', 0, 2, u'worldly') -- http://mail.python.org/mailman/listinfo/python-list
Re: parameterized classes
John Tantalo wrote: Is there is a better way to create parameterized classes than defining and returning a class in a closure? I ask because I want to create arbitrary BaseRequestHandler subclasses that delegate line handling to a given line handler, as in this example: Oh, now I get it. Maybe. Wouldn't it be easier to just use subclassing for parametrization: class LineRequestHandler(StreamRequestHandler): ... self.handle_line(line) ... class SomeLineHandler(LineRequestHandler): def handle_line(self, line): print I got a line: %s % line Alternatively, note that the SocketServer framework doesn't require the request handler baseclass to actually be a class; it works with any factory object that takes the same three arguments and returns an handler instance. You can use a plain function closure as a factory, if you prefer that. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Of course not. I just think Explicit is better than Implicit is taken seriously by a large segment the Python community as a guiding principle, and overall its influence does more harm than good. Clearly self being in every argument list was a decision arrived at long before the Zen was ever coined. Its merely an example of what I feel is a shortcoming in the conventional 'pythonic' approach to thinking about problems. The reluctance to admit that the __eq__ behaviour is a poor design choice is further evidence; its something (unlike self) that quite conceivably could be changed, and should be changed, but its somehow seen (by certain people) as the way that Python should do things. -- http://mail.python.org/mailman/listinfo/python-list
Re: parameterized classes
John Tantalo wrote: I really wish I could create a class whose instances were classes that subclassed BaseRequestHandler. Is this possible, or is there a better way than my approach here? Or am I crazy? You may use type: type('MuSubclass', (Base, ), dict(a1=1, a2=2, ...)) -- http://mail.python.org/mailman/listinfo/python-list
instance comparison
I am facing a problem where I am really confused about it. I am trying to compare to instances using: if inst1 == inst2 These instances have a overridden method __str__ which returns same string. The condition result is true although they are different instances. If I use: if id(inst1) == id(inst2) The results is false. What's happening here? If I am trying to store this pair in a set where other instances are already stored, but it's not storing it. Although I am sure that there is no pair already stored of same but even if Set is comparing by using string return by __str__ method then it won't. How do I solve this? Is this mean when you have overridden __str__ method then it comapre with results of __str__ or else it will comapre whether they are the same instances? -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion Performance Question
B wrote: Now it works, but it runs quite slow (compared to the c++ app). I changed gwl from strait recursion to use a generator and that helped, but it still takes 0.5-1.0 seconds to populate the tree. What I'm wondering is am I doing it in a really inefficient way, or is it just python? Well I did just enough to get your code to work and ran it through timeit on my respectable but hardly bleeding-edge desktop PC. dump C:\temppython -m timeit import get_windows; get_windows.run () 100 loops, best of 3: 17.1 msec per loop /dump So it's not that slow. Full code is posted below; uncomment the print_tree bit to see the results to confirm that it's doing what you think. I did this really quickly so it's possibly I've misunderstood what your code's up to. I'm not saying there aren't other ways to do this, but your code (at least inside my guessed-at wrapper) seems to do an adequate job in a reasonable time. get_windows.py import time from win32gui import GetWindow, GetWindowText, GetDesktopWindow from win32con import GW_CHILD, GW_HWNDNEXT class Node (object): def __init__ (self, hwnd): self.hwnd = hwnd self.children = [] def addChild (self, hwnd): self.children.append (Node (hwnd)) def gwl(node, hwnd): if hwnd: yield node, hwnd for nd, wnd in gwl(node.children[-1], GetWindow(hwnd, GW_CHILD)): yield nd, wnd for nd, wnd in gwl(node, GetWindow(hwnd, GW_HWNDNEXT)): yield nd, wnd def generateTree(self): t = time.clock() if self is not None: self.children = [] for nd, wnd in gwl(self, GetWindow(self.hwnd, GW_CHILD)): nd.addChild(wnd) def print_tree (root, level=0): print level * , GetWindowText (root.hwnd) or hex (root.hwnd) for child in root.children: print_tree (child, level + 1) def run (): desktop = Node (GetDesktopWindow ()) generateTree (desktop) #~ print_tree (desktop) /get_windows.py The second problem is reseting the list. In C++ I would use the STL Vector's clear() method. In python, I can't think of a good way to free all the nodes, so there is a large memory leak. I'm not clear here what you're getting at. Memory handling in Python is usually best left to Python unless you've got a very specific case -- and they do crop up occasionally. Just to be clear on something: Python does its own internal memory management, alloc-ing and free-ing with a variety of policies broadly managed by an internal pool. You're unlikely to see much memory released back to the system while Python's running. But this isn't a memory leak as such. You don't need to (and, in effect, can't) release the memory explicitly. But I'd be surprised if you had enough windows open for this to be even noticeable. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
On Wed, Jul 23, 2008 at 5:28 PM, Anthony [EMAIL PROTECTED] wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily Python's IDLE has only half of the first of these features. I did a lot of searching and found the PyDev extensions for Eclipse's Python IDE, and found that they've got Intellisense. I'm still missing b and c, and am getting extremely frustrated programming so slowly.. So two questions: Is there any package, gui, IDE, anything that will do FoxPro-style code completion? If it works in Eclipse, even better.. I can't find a good screenshot, but here's a better description: You type BROW and it pops up a window that says BROWSE ..at this point if you hit enter it completes the word.. and How can I view open SPSS data in one of the Python GUIs? Again, Eclipse would be the preference. Here's an example of how I'd like to browse the data: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=vfptoolkit_figure02.tif I don't want to have to switch back and forth between Python and SPSS while I'm programming; I just want to stay in one of them.. What can I do? I feel extremely inefficient when I don't have these three features.. I don't know of any python IDE that provides the data orientation feature, but there may be an Eclipse plugin for that sort of thing. Otherwise, if you're on windows, check out PyScripter, which is free: http://mmm-experts.com/Products.aspx?ProductId=4 and WingIDE which is quite nice and cross-platform (not free, though): http://www.wingware.com/ I use Vim, which is worth learning IMHO, but somewhat difficult to get started with especially if you're coming from FoxPro. -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
On Wed, Jul 23, 2008 at 5:28 PM, Anthony [EMAIL PROTECTED] wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily Python's IDLE has only half of the first of these features. I did a lot of searching and found the PyDev extensions for Eclipse's Python IDE, and found that they've got Intellisense. I'm still missing b and c, and am getting extremely frustrated programming so slowly.. So two questions: Is there any package, gui, IDE, anything that will do FoxPro-style code completion? If it works in Eclipse, even better.. I can't find a good screenshot, but here's a better description: You type BROW and it pops up a window that says BROWSE ..at this point if you hit enter it completes the word.. and How can I view open SPSS data in one of the Python GUIs? Again, Eclipse would be the preference. Here's an example of how I'd like to browse the data: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=vfptoolkit_figure02.tif I don't want to have to switch back and forth between Python and SPSS while I'm programming; I just want to stay in one of them.. What can I do? I feel extremely inefficient when I don't have these three features.. BTW, if you're developing for windows, you may also want to check out IronPython which plugs into the Visual Studio framework, I believe: http://www.codeplex.com/IronPython http://www.codeplex.com/IronPythonStudio -- http://mail.python.org/mailman/listinfo/python-list
Re: instance comparison
On Jul 24, 6:50 pm, King [EMAIL PROTECTED] wrote: I am facing a problem where I am really confused about it. I am trying to compare to instances using: if inst1 == inst2 These instances have a overridden method __str__ which returns same string. The condition result is true although they are different instances. If I use: if id(inst1) == id(inst2) The results is false. What's happening here? If I am trying to store this pair in a set where other instances are already stored, but it's not storing it. Although I am sure that there is no pair already stored of same but even if Set is comparing by using string return by __str__ method then it won't. How do I solve this? Is this mean when you have overridden __str__ method then it comapre with results of __str__ No. Do you have a __cmp__ method, or an __eq__ method? Any other __twounderscores__ methods? It is impossible to tell what is going on from your description. Please supply the source of a *short* class that demonstrates the problem, and demonstrate it. -- http://mail.python.org/mailman/listinfo/python-list
Requires a character ... !!
Hi, I am new to python . I am face few problems related with python and iam trying to resolve it. The below is the error that i get when i invoke my application by giving the necessary input file. [EMAIL PROTECTED] hello]# Analyzer hello_input Loading debug info: hello_input Traceback (most recent call last): File /usr/local/SDK/host/bin/Analyzer, line 694, in ? app.dbg.readObjectInfo(elf) File /usr/local/SDK/host/bin/debugprocessor.py, line 427, in readObjectInfo self.privateProcessorDwarfTree.readProcessorDwarfTree(filename) File /usr/local/SDK/bin/debugprocessor.py, line 314, in readDwarfTree if DW_OP_reg in value: TypeError: 'in string' requires character as left operand Is this related with the version conflicts ? Should i need to configure any environment variables or change some source code. Any ideas ? Thx in advans, Karthik Balaguru -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
karthikbalaguru wrote: I am new to python . I am face few problems related with python and iam trying to resolve it. The below is the error that i get when i invoke my application by giving the necessary input file. [EMAIL PROTECTED] hello]# Analyzer hello_input Loading debug info: hello_input Traceback (most recent call last): File /usr/local/SDK/host/bin/Analyzer, line 694, in ? app.dbg.readObjectInfo(elf) File /usr/local/SDK/host/bin/debugprocessor.py, line 427, in readObjectInfo self.privateProcessorDwarfTree.readProcessorDwarfTree(filename) File /usr/local/SDK/bin/debugprocessor.py, line 314, in readDwarfTree if DW_OP_reg in value: TypeError: 'in string' requires character as left operand Is this related with the version conflicts ? Should i need to configure any environment variables or change some source code. You should run the code on a Python version that supports the features your code is using. Support for arbitrary strings on the left side of the in operator was added in Python 2.3, which was released in 2003. What software is this? If you've written it yourself, make sure to use only features supported by the Python version you're actually using. If it's written by someone else, please read the requirements section for the software you're using, and follow the instructions in there. (hasn't people been telling you this about a hundred times before in this forum? or was that some other guy who also kept insisting on running some program on a python version it didn't support?) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: instance comparison
King wrote: Is this mean when you have overridden __str__ method then it comapre with results of __str__ or else it will comapre whether they are the same instances? Comparisons uses __cmp__ or the rich comparison set; see http://docs.python.org/ref/customization.html for details. Sets and dictionaries, also relies on hashing (the __hash__ method, also described on the linked page). The __str__ method only affects printing and conversion to string. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan a écrit : (snip rant about self and __eq__ / __ne__) 1/ about the __eq__ / __ne__ stuff: Please get your facts, the behaviour *is* actually fully documented: There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__() so that the operators will behave as expected. http://docs.python.org/ref/customization.html FWIW, the __lt__ / __le__ / __eq__ / __ne__ / __gt__ / __ge__ methods set, known as rich comparisons, was added in Python 2.1 to give more fine-grained control on comparisons. If you don't need such a granularity, just implement the __cmp__ method and you'll have all comparison operators working as expected. 2/ wrt/ self in functions signatures: How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
karthikbalaguru wrote: [EMAIL PROTECTED] hello]# Analyzer hello_input ^^ This is often a bad idea. Anyhow, that has nothing to do with Python. Loading debug info: hello_input Traceback (most recent call last): File /usr/local/SDK/host/bin/Analyzer, line 694, in ? app.dbg.readObjectInfo(elf) File /usr/local/SDK/host/bin/debugprocessor.py, line 427, in readObjectInfo self.privateProcessorDwarfTree.readProcessorDwarfTree(filename) File /usr/local/SDK/bin/debugprocessor.py, line 314, in readDwarfTree if DW_OP_reg in value: TypeError: 'in string' requires character as left operand Is this related with the version conflicts ? Which version conflict? Sorry, but my crystal ball is getting a new polish today, so I can't see the actual code that causes the error. I suggest that you reduce your code to the smallest possible piece of code that still shows the error and post it here, otherwise nobody will be able to help you. Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
On Jul 24, 2:20 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: karthikbalaguru wrote: I am new to python . I am face few problems related with python and iam trying to resolve it. The below is the error that i get when i invoke my application by giving the necessary input file. [EMAIL PROTECTED] hello]# Analyzer hello_input Loading debug info: hello_input Traceback (most recent call last): File /usr/local/SDK/host/bin/Analyzer, line 694, in ? app.dbg.readObjectInfo(elf) File /usr/local/SDK/host/bin/debugprocessor.py, line 427, in readObjectInfo self.privateProcessorDwarfTree.readProcessorDwarfTree(filename) File /usr/local/SDK/bin/debugprocessor.py, line 314, in readDwarfTree if DW_OP_reg in value: TypeError: 'in string' requires character as left operand Is this related with the version conflicts ? Should i need to configure any environment variables or change some source code. You should run the code on a Python version that supports the features your code is using. Support for arbitrary strings on the left side of the in operator was added in Python 2.3, which was released in 2003. Thx for that info. I understand. The requirements state that it needs Python 2.2, But i wonder how that program has been implemented using Python 2.3 features. Anyhow, this has to be resolved and i need your help. Kindly let me know a trick to make to resolve the 'in' operator related problem by using Python 2.2. Thx in advans, Karthik Balaguru -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Hallöchen! Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
karthikbalaguru wrote: The requirements state that it needs Python 2.2, But i wonder how that program has been implemented using Python 2.3 features. Anyhow, this has to be resolved and i need your help. No, you need the help of the original author. He/she might have forgotten to update the requirements page, or you may have mis- read the information. Only the author knows if this program might have a chance of working on 2.2. What program is this? Can you point us to the site where you got it? Kindly let me know a trick to make to resolve the 'in' operator related problem by using Python 2.2. Instead of backporting the software, why not just update to Python 2.3 or newer and be done with it? Why insist on using a Python version that's nearly seven years old, when the program you're trying to run obviously wasn't written for it? (Note that you can have multiple versions of Python installed on the same machine. Maybe you already have -- have you tried running the program with python2.3 or python2.4 or python2.5 instead of just python?) /F -- http://mail.python.org/mailman/listinfo/python-list
Confounded by Python objects
Hello group, take a look at the code snippet below. What I want to do is initialize two separate Channel objects and put some data in them. However, although two different objects are in fact created (as can be seen from the different names they spit out with the diag() method), the data in the sample member is the same although I stick different values in. Thanks, robert (Sorry for Google Groups, but I don't have NNTP at work) Here's the code: #!/usr/bin/python class Channel: name = '' sample = [] def __init__(self, name): self.name = name def append(self, time, value): self.sample.append((time, value)) self.diag() def diag(self): print (self.name, self.sample) chA = Channel('A') chB = Channel('B') chA.append(1, 1.1) chB.append(2, 2.1) chA.append(3, 1.2) chB.append(4, 2.2) print 'Result:' chA.diag() chB.diag() and here's the output: ('A', [(1, 1.1001)]) ('B', [(1, 1.1001), (2, 2.1001)]) ('A', [(1, 1.1001), (2, 2.1001), (3, 1.2)]) ('B', [(1, 1.1001), (2, 2.1001), (3, 1.2), (4, 2.2002)]) Result: ('A', [(1, 1.1001), (2, 2.1001), (3, 1.2), (4, 2.2002)]) ('B', [(1, 1.1001), (2, 2.1001), (3, 1.2), (4, 2.2002)]) What I'd like to see, however, is 2 tuples per Channel object, like this: ('A', [(1, 1.1001)]) ('B', [(2, 2.1001)]) ('A', [(1, 1.1001), (3, 1.2)]) ('B', [(2, 2.1001), (4, 2.2002)]) Result: ('A', [(1, 1.1001), (3, 1.2)]) ('B', [(2, 2.1001), (4, 2.2002)]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
On Jul 24, 7:33 pm, karthikbalaguru [EMAIL PROTECTED] wrote: Kindly let me know a trick to make to resolve the 'in' operator related problem by using Python 2.2. You seem to be making life -very- difficult for yourself. Your distro is running Python 2.4, you've gone out of your way to get Py2.2 installed. Why are you so convinced that you -need- Python 2.2 over 2.4? Everyone problem you've posted here seems due to that assumption... Generally, Python is pretty good about backwards compatibility. Code written for 2.2 should run fine under 2.4. As you're discovering, the opposite isn't true. __future__ isn't a cure-all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
Thx for that info. I understand. The requirements state that it needs Python 2.2, But i wonder how that program has been implemented using Python 2.3 features. Anyhow, this has to be resolved and i need your help. Kindly let me know a trick to make to resolve the 'in' operator related problem by using Python 2.2. You obviously don't understand and it appears that it's time to resort to somewhat more explicit clue-batting: YOU ARE UNDER A WRONG IMPRESSION THAT YOUR SOFTWARE REQUIRES PYTHON 2.2. YOU HAVE BEEN TOLD THAT NUMEROUS TIMES. SO PLEASE - STOP USING PYTHON 2.2 FOR IT. WHOEVER TOLD YOU THAT IT IS NEEDED WAS WRONG** Now did that get through? Given your record here, I think I have to repeat... STOP USING PYTHON 2.2. NOW! Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: instance comparison
The only methods I do have in class is __init__ and __str__. How ever inst1 and inst2 is coming from a dictionary where I stored them with a unique id. inst1 = stored[id] inst2 = stored[id] Is this makes a difference? I will rip down the piece of code giving me problem and post. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function editing with Vim throws IndentError
In message [EMAIL PROTECTED], Matimus wrote: That isn't the standard. With that setup tabs will show up as 4 spaces, and still confuse you. Why should that be confusing? The most common tab-stop setting is 4 columns. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confounded by Python objects
[EMAIL PROTECTED] wrote: take a look at the code snippet below. What I want to do is initialize two separate Channel objects and put some data in them. However, although two different objects are in fact created (as can be seen from the different names they spit out with the diag() method), the data in the sample member is the same although I stick different values in. that's because you only have one sample object -- the one owned by the class object. since you're modifying that object in place (via the append method), your changes will be shared by all instances. python never copies attributes when it creates an instance; if you want a fresh object, you have to create it yourself. class Channel: tip: if you're not 100% sure why you would want to put an attribute on the class level, don't do it. instead, just create all attributes inside the __init__ method: def __init__(self, name): self.name = name self.sample = [] # create fresh container for instance def append(self, time, value): self.sample.append((time, value)) self.diag() def diag(self): print (self.name, self.sample) hope this helps! /F -- http://mail.python.org/mailman/listinfo/python-list
Re: scanf in python
In message [EMAIL PROTECTED], AMD wrote: Actually it is quite common, it is used for processing of files not for reading parameters. You can use it whenever you need to read a simple csv file or fixed format file which contains many lines with several fields per line. I do that all the time, in Python and C++, but I've never felt the need for a scanf-type function. For reading delimited fields in Python, you can use .split string method. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 7:40 pm, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] Yeah, forgot what I said, Torsten's reply is much better :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. It's sufficiently close to fool those accustomed to OO ways of doing things, but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confounded by Python objects
On Jul 24, 7:45 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: class Channel: name = '' sample = [] def __init__(self, name): self.name = name def append(self, time, value): self.sample.append((time, value)) self.diag() def diag(self): print (self.name, self.sample) Okay, the problem is you're appending to a _class_ attribute, not to an instance attribute. If you change your class definition to this, it should work: class Channel: def __init__(self, name): self.name = name self.sample = [] That will provide each instance with its own version of the sample attribute. The 'self.name = name' in the __init__ for your original code binds a new attribute to the instance, whereas 'self.sample.append(...' in the class's append was appending to the class attribute instead. Hope this helps. - alex23 -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml, comparing nodes
off the top of my head (untested): def equal(a, b): ... if a.tag != b.tag or a.attrib != b.attrib: ... return False ... if a.text != b.text or a.tail != b.tail: ... return False ... if len(a) != len(b): ... return False ... if any(not equal(a, b) for a, b in zip(a, b)): ... return False ... return True this should work for arbitrary ET implementations (lxmk, xml.etree, ET, etc). tweak as necessary. /F Thanks for help. Thats inspiring, tho not exactly what I need, coz ignoring document order is requirement (ignoring changes in order of different siblings of the same type, etc). I plan to try something like that: def xmlCmp(xmlStr1, xmlStr2): et1 = etree.XML(xmlStr1) et2 = etree.XML(xmlStr2) queue = [] tmpq = deque([et1]) tmpq2 = deque([et2]) while tmpq: el = tmpq.popleft() tmpq.extend(el) queue.append(el.tag) while queue: el = queue.pop() foundEl = findMatchingElem(el, et2) if foundEl: et1.remove(el) tmpq2.remove(foundEl) else: return False if len(tmpq2) == 0: return True else: return False def findMatchingElem(el, eTree): for elem in eTree: if elemCmp(el, elem): return elem return None def elemCmp(el1, el2): pass # yet to be implemented ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Confounded by Python objects
In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: class Channel: name = '' sample = [] These are class variables, not instance variables. Take them out, and ... def __init__(self, name): self.name = name ... add this line to the above function self.sample = [] -- http://mail.python.org/mailman/listinfo/python-list
Re: Broken examples
In message [EMAIL PROTECTED], norseman wrote: The OOo examples do not work. I have done OOo scripting in Python. What exactly does not work? -- http://mail.python.org/mailman/listinfo/python-list
Re: instance comparison
King wrote: The only methods I do have in class is __init__ and __str__. How ever inst1 and inst2 is coming from a dictionary where I stored them with a unique id. inst1 = stored[id] inst2 = stored[id] Is this makes a difference? unlikely (well, if that's the literal code, both variables will point to the same variable, but I guess that's not what you meant). I will rip down the piece of code giving me problem and post. please do. and don't be surprised if you find the problem while doing so ;-) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Confounded by Python objects
On Jul 24, 11:59 am, Fredrik Lundh [EMAIL PROTECTED] wrote: tip: if you're not 100% sure why you would want to put an attribute on the class level, don't do it. The reason I did it was sort of C++ish (that's where I come from): I somehow wanted a list of attributes on the class level. More for readibility than anything elase, really. hope this helps! Yup, did the trick. Thanks! robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
OK, it seems my original reply to Bruno got lost in the Aether (apologies therefore if a paraphrased quantum duplicate of this message is eventually forthcoming.) Torsten has adequately responded to his second point, so I need only replicated what I said for the first. Please get your facts, the behaviour *is* actually fully documented: I have the facts. I know full well the behaviour is documented - it was pointed out at the time of the original discussion. Documenting a confusing, unintuitive design decision (whether its in a programming language, an end user GUI app or anything in between) doesn't justify it. To attack a strawman: foolanguage uses the bar IO library; printing to stdout takes about 10 mins on the average machine. But thats ok, because look, its documented right here. FWIW, the __lt__ / __le__ / __eq__ / __ne__ / __gt__ / __ge__ methods set, known as rich comparisons, was added in Python 2.1 to give more fine-grained control on comparisons. If you don't need such a granularity, just implement the __cmp__ method and you'll have all comparison operators working as expected. First, the most serious justification for rich comparisons I remember seeing was that scipy needed them. I never saw a good reason scipy couldnt use methods like the rest of us mortals, nor why it was justifiable introducing a wart into the entire language for the sake of mildly conveniencing an (admittedly important and widely used) library. Second, fine, have silly C++-operator-overloading-style rich comparisons that confuse people reading your code if you must. Why does it have to be the default behaviour? Its people wanting __ne__ do do something other than not __eq__ who should have to be explicit about it. Third, __cmp__ is no good as a fix. Most classes that wan't equality comparison (== and !=) don't want ordered based comparison (= etc.) thrown in as well. I shouldn't implement __cmp__ unless I want my class to implement every order comparison operator. Fourth, I'm trying to examine the wider implications of the Explicit Implict mantra here, not resurrect an old campaign to change != behaviour that I think is probably a lost cause (if it happens as a side effect though, that'd be kinda cool.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
This is just plain wrong for at least C# and C++. C# wants you to explicitly overload !=, if you have overloaded ==, While this is as inconvenient as Python at least it doesn't catch you unawares. C# 1 (or maybe 0.5), Python 0. C++ complains about != not being defined for class A. See above. C++ 1, Python 0. So in showing my clearly hyperbolic comment was technically incorrect (something I could have told you myself), you have merely shown that two languages I find vastly inferior to Python overall are actually better than it in this case. Fortunately, Python isn't designed according to your ideas, and won't change, so consider your posting a waste of time. If feeling like bringing such old issues up again next time, spend your time learning another programming language, as you would obviously not get happy with Python anyway ... OK, if that's your response, that's sad. Of course, I try to learn new languages all the time. Python is still IMO the best. If the attitude in the community in response to feedback/criticism has gone from maybe you've got a point to your a lunatic, we'll never change, well, only Python will suffer in the long term. -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
FoxPro is data-oriented, which means that at any time you have any number of data sets open in the workspace and browse them immediately by running one line of code in the command window. It's a really important feature in terms of efficiency; I don't want to have to move back and forth between SPSS and an IDE when I'm figuring out what code to write, that takes six keystrokes for what FoxPro can do in one. Again, here's what the BROWSE command presents: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=vfptoolkit_figure02.tif Does VIM have the capability to keep data open? -- Do any of these IDEs have this browse capability?? On Jul 24, 4:10 am, Aspersieman [EMAIL PROTECTED] wrote: Anthony wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily Python's IDLE has only half of the first of these features. I did a lot of searching and found the PyDev extensions for Eclipse's Python IDE, and found that they've got Intellisense. I'm still missing b and c, and am getting extremely frustrated programming so slowly.. So two questions: Is there any package, gui, IDE, anything that will do FoxPro-style code completion? If it works in Eclipse, even better.. I can't find a good screenshot, but here's a better description: You type BROW and it pops up a window that says BROWSE ..at this point if you hit enter it completes the word.. and How can I view open SPSS data in one of the Python GUIs? Again, Eclipse would be the preference. Here's an example of how I'd like to browse the data: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=... I don't want to have to switch back and forth between Python and SPSS while I'm programming; I just want to stay in one of them.. What can I do? I feel extremely inefficient when I don't have these three features.. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list You might want to try vim. It has a steep learning curve, but definitely increases productivity _alot_. Here is a tutorial on setting up vim with : 1) Code completion (intellisense) - including tooltips (!!!) 2) Jump between your python code and the python class libraries. 3) Syntax checking 4) A handy source browser 5) Debugging (using pdb) 6) [All the other vim goodies - already included] Above instructions available herehttp://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ I have been using the above setup for a while and find it superior to _any_ IDE I've ever worked with. I'm not sure what you mean by 'Data-Orientation' but I'm sure there's a suitable alternative/replacement for it in vim. Regards Nicolaas -- The three things to remember about Llamas: 1) They are harmless 2) They are deadly 3) They are made of lava, and thus nice to cuddle. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 8:01 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. It's sufficiently close to fool those accustomed to OO ways of doing things, but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. You could still explicitly request non-implicit self on a method by method basis. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan [EMAIL PROTECTED]: # Blog code, not tested class A(): def __eq__(self, obj): return True a = A() b = [] assert a == b assert not (a != b) The second assertion fails. Why? Because coding __eq__, the most obvious way to make a class have equality based comparisons, buys you nothing from the != operator. != isn't (by default) a synonym for the negation of == (unlike in, say, every other language ever); This is just plain wrong for at least C# and C++. C# wants you to explicitly overload !=, if you have overloaded ==, C++ complains about != not being defined for class A. If you had derived A from a another class in C++, the compiler would happily use the operator from the base class instead of doing silly aliasing of != to ! == ... The sad thing is there are plenty of smart Python programmers who will justify all kinds of idiocy in the name of their holy crusade against the implict. If there was one change I could make to Python, it would be to get that damn line out of the Zen. Fortunately, Python isn't designed according to your ideas, and won't change, so consider your posting a waste of time. If feeling like bringing such old issues up again next time, spend your time learning another programming language, as you would obviously not get happy with Python anyway ... -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On 24 Jul., 11:40, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. And $self2, $self3, ... to the object methods of nested classes and $cls2, $cls3, ... to the classmethods of those classes...? And when we are at it, here is a nice little exercise for the proponents of compiler magic. Write a decorator that takes and returns a method and prints the object the method is bound to. It's very easy to do it when the object is passed explicitely: def print_self(func): def call(self, *args, **kwd): print self return func(self, *args, **kwd) return call Conceptual clarity isn't always an entirely bad thing to have. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Hallöchen! Kay Schluehr writes: On 24 Jul., 11:40, Torsten Bronger [EMAIL PROTECTED] wrote: Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. And $self2, $self3, ... to the object methods of nested classes and $cls2, $cls3, ... to the classmethods of those classes...? One could surely find ways to realise this. However, the design goal should be: Make the frequent case simple, and the rare case possible. (Actually, I'm -0 on this anyway because I forget self very seldomly, and you would still have .self all over the place.) Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Working with ctypes and char** data type
I'm a bit of a python newbie and I need to wrap a C library. I can initialise the library using CDLL('mcclient.so') and I can call functions correctly inside the library but I need to invoke one function which has this function definition: char ** CAPAPI McSearch(HMCLINK Handle, short nSearchType, short nNoSelect, char **pSelect, short nNoWhere, char **pWhere, char **pData, int iTimeout); For **pSelect I want to pass in an array of char points, which in C would be declared as char *pData[] = { ADDR, POSTCODE }; Can someone tell me how use pointers + char pointers together in python with ctypes please? Thank you Phill -- http://mail.python.org/mailman/listinfo/python-list
Re: Autocompletion and Interactive Tables in a Python IDE
On Jul 24, 4:10 am, Aspersieman [EMAIL PROTECTED] wrote: Anthony wrote: Hi, I'm a FoxPro programmer, but I want to learn python before it's too late. I do a lot of statistical programming, so I import SPSS into python. In my opinion, the best features of Visual FoxPro 9.0 were: a) Intellisense (tells you what classes/methods are available and what variables go into a function) b) Code Completion (guesses your code after four letters) c) Data-Orientation; multiple data sessions can be open, data can be viewed easily Python's IDLE has only half of the first of these features. I did a lot of searching and found the PyDev extensions for Eclipse's Python IDE, and found that they've got Intellisense. I'm still missing b and c, and am getting extremely frustrated programming so slowly.. So two questions: Is there any package, gui, IDE, anything that will do FoxPro-style code completion? If it works in Eclipse, even better.. I can't find a good screenshot, but here's a better description: You type BROW and it pops up a window that says BROWSE ..at this point if you hit enter it completes the word.. and How can I view open SPSS data in one of the Python GUIs? Again, Eclipse would be the preference. Here's an example of how I'd like to browse the data: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=... I don't want to have to switch back and forth between Python and SPSS while I'm programming; I just want to stay in one of them.. What can I do? I feel extremely inefficient when I don't have these three features.. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list You might want to try vim. It has a steep learning curve, but definitely increases productivity _alot_. Here is a tutorial on setting up vim with : 1) Code completion (intellisense) - including tooltips (!!!) 2) Jump between your python code and the python class libraries. 3) Syntax checking 4) A handy source browser 5) Debugging (using pdb) 6) [All the other vim goodies - already included] Above instructions available herehttp://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ I have been using the above setup for a while and find it superior to _any_ IDE I've ever worked with. I'm not sure what you mean by 'Data-Orientation' but I'm sure there's a suitable alternative/replacement for it in vim. Regards Nicolaas -- Anthony wrote: FoxPro is data-oriented, which means that at any time you have any number of data sets open in the workspace and browse them immediately by running one line of code in the command window. It's a really important feature in terms of efficiency; I don't want to have to move back and forth between SPSS and an IDE when I'm figuring out what code to write, that takes six keystrokes for what FoxPro can do in one. Again, here's what the BROWSE command presents: http://www.vfpconversion.com/ArticleImage.aspx?QuickID=0209071Image=vfptoolkit_figure02.tif Does VIM have the capability to keep data open? -- Do any of these IDEs have this browse capability?? I see what you mean by 'Data Oriented', however I'm not aware of such a 'data set' persistence functionality in vim. You can set up a similar (to FoxPro) environment using DBExt [1] plugin in vim and by using its (vims') built-in session functionality. To set up dbext for FoxPro in vim you might need to use ODBC but it should be quite straight forward provided you read the help. I work on SQL Server (using python and vim) and frequently have many queries result sets open that I'm busy with. When I have to go, all I do is save my session in vim. When I return the next day, I open the session, and it there I have all the queries (not the data sets they return (however you can save that too)) and scripts etc, I was working on. To execute a query (even one embedded in some python code) I merely select the lines the query is on and type the key-mapping (I set up) to execute the query (3 key strokes) and I can view the result set in a split window below the current one. The aforementioned vim setup for python [2] and the DBExt plugin for vim give me all the functionality I need to develop python and/or database applications/scripts in one editor (IDE?). Also, there are so many other useful plugins [3] for vim I have no need of any other IDE (I've replaced Visual Studio .Net with vim as my IDE for Asp.Net applications). I'm sure that vim can meet all the required features you wanted initially. [1] http://www.vim.org/scripts/script.php?script_id=356 [2] here it is again : http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ [3] http://www.vim.org/scripts/script.php?script_id=1318 and http://www.vim.org/scripts/script.php?script_id=910 and http://vim.sourceforge.net/scripts/script.php?script_id=69 and http://www.vim.org/scripts/script.php?script_id=1658
Re: Requires a character ... !!
On Jul 24, 7:23 pm, Ulrich Eckhardt [EMAIL PROTECTED] wrote: karthikbalaguru wrote: [EMAIL PROTECTED] hello]# Analyzer hello_input ^^ This is often a bad idea. Anyhow, that has nothing to do with Python. Loading debug info: hello_input Traceback (most recent call last): File /usr/local/SDK/host/bin/Analyzer, line 694, in ? app.dbg.readObjectInfo(elf) File /usr/local/SDK/host/bin/debugprocessor.py, line 427, in readObjectInfo self.privateProcessorDwarfTree.readProcessorDwarfTree(filename) File /usr/local/SDK/bin/debugprocessor.py, line 314, in readDwarfTree if DW_OP_reg in value: TypeError: 'in string' requires character as left operand Is this related with the version conflicts ? Which version conflict? Sorry, but my crystal ball is getting a new polish today, so I can't see the actual code that causes the error. I suggest that you reduce your code to the smallest possible piece of code that still shows the error and post it here, otherwise nobody will be able to help you. You don't need a crystal ball; you just need to have been reading this group/list for the last day or so --- the OP is trying to use Python 2.2 on some *.py that are obviously written for a later version, refuses to contemplate upgrading, and starts a new thread every time he gets a syntax error. -- http://mail.python.org/mailman/listinfo/python-list
how to cut and paste in the windows of python(command line)
Dear all: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work. But they do work in IDLE. please teach me about the python(command line). -- http://mail.python.org/mailman/listinfo/python-list
Re: how to cut and paste in the windows of python(command line)
fang wrote: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work. But they do work in IDLE. that has absolutely nothing to do with Python, and everything to do with what console or terminal program you're using. if you're using windows, you'll find edit commands, including copy and paste, commands in the window menu (click on the icon in the upper left corner). Python also supports the standard doskey commands (text+F8 to search in history, UP/DOWN to recall commands, ESC to clear, etc). if you want better console support, consider installing the ipython shell: http://ipython.scipy.org/moin/ /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how to cut and paste in the windows of python(command line)
On Jul 24, 8:17 am, fang [EMAIL PROTECTED] wrote: Dear all: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work. But they do work in IDLE. please teach me about the python(command line). What Operating System are you using? If you are using Windows, you could try cutting and pasting from the menu (I am assuming you are using a normal terminal windows). André -- http://mail.python.org/mailman/listinfo/python-list
Re: Requires a character ... !!
John Machin wrote: You don't need a crystal ball; you just need to have been reading this group/list for the last day or so --- the OP is trying to use Python 2.2 on some *.py that are obviously written for a later version, refuses to contemplate upgrading, and starts a new thread every time he gets a syntax error. The traceback indicates that this is some software for working with debug data (http://dwarfstd.org/), but neither Google nor Kodos finds anything similar to the code you see in the tracebacks, so it's probably some proprietary stuff. And for some reason, the OP seems to be a bit unwilling to ask the supplier for help... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how to cut and paste in the windows of python(command line)
-On [20080724 13:50], Fredrik Lundh ([EMAIL PROTECTED]) wrote: if you want better console support, consider installing the ipython shell: Unless you work with non-ASCII. Ipython mangles non-ASCII unfortunately. [Full UTF-8 environment] In [1]: a = u'愛' In [2]: a Out[2]: u'\xe6\x84\x9b' Normal python shell: a = u'愛' a u'\u611b' I wonder if it can be easily fixed with a getpreferredencoding() or by using an .encode(sys.stdout.encoding or getpreferredencoding() or 'ascii', 'replace') triplet. -- Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai イェルーン ラウフロック ヴァン デル ウェルヴェン http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B One who knows that enough is enough will always have enough... -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion Performance Question
B wrote: # pass in window handle and parent node def gwl(node, hwnd): if hwnd: yield node, hwnd for nd, wnd in Wnd.gwl(node.children[-1], GetWindow(hwnd, GW_CHILD)): yield nd, wnd for nd, wnd in Wnd.gwl(node, GetWindow(hwnd, GW_HWNDNEXT)): yield nd, wnd [...] Now it works, but it runs quite slow (compared to the c++ app). I changed gwl from strait recursion to use a generator and that helped, but it still takes 0.5-1.0 seconds to populate the tree. Actually the generator could well be the problem here, because of time spent on yield propagation: gwl has worst-case quadratic performance, the worst case being if the tree is unbalanced and deep, because every yielded value must pass through a chain of propagation for-loops. Straight recursion should be faster; I don't know what you did to make it slow, but try something along these lines: def gwl_helper(node, hwnd, collect): if hwnd: collect((node,hwnd)) gwl_helper(node.children[-1], GetWindow(hwnd, GW_CHILD), collect) gwl_helper(node, GetWindow(hwnd, GW_HWNDNEXT), collect) def gwl(node, hwnd): result = [] gwl_helper(node, hwnd, result.append) return result - Anders -- http://mail.python.org/mailman/listinfo/python-list
Re: how to cut and paste in the windows of python(command line)
Dear: Thank you very much! I can do it! It's very nice! -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 24, 8:21 pm, Jordan [EMAIL PROTECTED] wrote: If the attitude in the community in response to feedback/criticism has gone from maybe you've got a point to your a lunatic, we'll never change, well, only Python will suffer in the long term. Personally, I think it has more to do with statements like there are plenty of smart Python programmers who will justify all kinds of idiocy in the name of their holy crusade than with your position. You don't begin a discussion by discrediting anyone who might disagree with you as some kind of religious bigot while simultaneously holding that you are the only sane voice speaking. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan [EMAIL PROTECTED]: Fortunately, Python isn't designed according to your ideas, and won't change, so consider your posting a waste of time. If feeling like bringing such old issues up again next time, spend your time learning another programming language, as you would obviously not get happy with Python anyway ... OK, if that's your response, that's sad. Of course, I try to learn new languages all the time. Python is still IMO the best. If the attitude in the community in response to feedback/criticism has gone from maybe you've got a point to your a lunatic, we'll never change, well, only Python will suffer in the long term. I don't really mind, what you think about my response. Python will suffer from it as little as it will suffer from your complaints: These things will not change, whatever any of us says about them. So this discussion unlikely to produce any new insight, especially because this as been discussed over and over again in the past, without any effect on Python. Let's just drop this, and if you want to complain next time, just complain about something, that is really worth being complained about, like for instance old and outdated modules in the standard library, or real showstoppers in Python (e.g. the GIL). -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: instance comparison
King a écrit : The only methods I do have in class is __init__ and __str__. Is your class subclassing another one ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt
Fredrik Lundh wrote: ജഗന്നാഥ് wrote: I am a Perl programmer new to Python. I have a small doubt. I suspect you mean question, not doubt. It's not quite the same thing. It seems to be an Indian/Asian thing. By now, I tuned myself to read doubt as question/problem... Diez -- http://mail.python.org/mailman/listinfo/python-list
New to Python, familiar with Perl - Seeking info sources
After many years happily coding Perl, I'm looking to expand my horizons. [no flames please, I'm pretty aware of Perl's strengths and weaknesses and I'm just here to learn more, not to enter religious debates]. I've gone through some of the online tutorials and I'll be browsing the reference before starting the code a lot phase. My question is: What are the best sources to learn best practices or get the answers to questions? Are there any good sources to tell me what Perl habits are good/bad in the Python paradigm? What about common packages that will change my life? (I do a lot of web work, but also a lot of DB reporting) I'm also working as a Java developer primarily, so I'm glad to see that Jython has been resurrected, but I'm focusing on vanilla Python for the moment. As examples: PerlMonks has been my info source. The Perl Best Practices and Higher Order Perl books have been my tutors into better coding practices. CPAN has my life easy, giving me access to the DBI, Class::DBI (and its successors), HTML::FillInForm, Data::FormValidator, CGI::Application, and Text::CSV::Simple modules that are staples of my coding. The (occasionally complete) Perl Advent calendars have proven to be a good source to learn about helpful modules that I might not otherwise stumble across. (I've encountered Django, but I'm getting my fill of frameworks from Java for the moment, so I'm looking for lightweight pieces at the moment) My (admittedly brief) searches here and on google didn't lead me to any particular spots of concentrated Python info, and most of the Perl/ Python stuff is either a smug attack by one camp on the other or a rant about the behavior of an obscure feature between the two. Any recommendations? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Python / PAMIE
Can someone help with a PAMIE issue? I'm new to Python / PAMIE and they seem like great tools but to be honest I'm finding that no responses to questions can be found (Experts Exchange, etc.) I'm hoping this will be the place. I tried to duplicate the authors ie.writeScript function shown at http://showmedo.com/videos/video?name=pythonMarchettiPamie3fromSeriesID=25 I get Attribute not found. I found one reference to where the command was written as ie.scriptWrite but that does not work either. I've emailed the author, Experts Exchange and other sites with ZERO responses. Can someone PLEASE assist? THNX -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Personally, I think it has more to do with statements like there are plenty of smart Python programmers who will justify all kinds of idiocy in the name of their holy crusade than with your position. You don't begin a discussion by discrediting anyone who might disagree with you as some kind of religious bigot while simultaneously holding that you are the only sane voice speaking. I didn't set out to discredit anyone who might disagree with me; in fact I didn't in anyway try to pre-empt any person who might disagree with my thesis. I merely stated an observation - I have in the past seen seemingly intelligent people take silly stands in the name of Explicit is greater than Implicit (not just on comp.lang.python, and not just concerning != or self). I wish in retrospect I'd had the time, patience and focus to edit the initial post to make it more measured and less inflammatory, because its clear the tone detracts from the argument I'm making, which I feel still stands. So if you wish, ignore the specifics of the frustration that inspired me and consider only the thrust of what I'm saying: Explicit is better than Implict considered harmful. Discuss. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan [EMAIL PROTECTED] writes: I just think Explicit is better than Implicit is taken seriously by a large segment the Python community as a guiding principle Indeed it is. However, it has to compete with all the other principles in the Zen of Python, which have equal status. and overall its influence does more harm than good. Thanks for your opinion. I disagree strongly: I think its influence is nicely balanced by the other important principles that are also followed. -- \ “The way to build large Python applications is to componentize | `\ and loosely-couple the hell out of everything.” —Aahz | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan [EMAIL PROTECTED] writes: If the attitude in the community in response to feedback/criticism has gone from maybe you've got a point to your a lunatic, we'll never change, well, only Python will suffer in the long term. You're not a lunatic. We, and Python itself, change quite readily. Neither of those mean your ideas in this instance have merit. -- \ “Pinky, are you pondering what I'm pondering?” “Well, I think | `\ so, Brain, but do I really need two tongues?” —_Pinky and The | _o__) Brain_ | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
FW: [Jython-users] Jython Licensing Question
All, Can anyone answer my question about the licensing for SocketServer.py? I would appreciate it. Kent -Original Message- From: Tobias Ivarsson [mailto:[EMAIL PROTECTED] Sent: Thursday, July 24, 2008 2:13 AM To: Pinegar, Kent T Subject: Re: [Jython-users] Jython Licensing Question No I don't, I spent a few minutes yesterday when researching in what revision it got in to try and find where a list of contributors who have signed the contributors agreement could be found, but without success. I think you should try asking on python-list (python-list@python.org), the e-mail list for discussion about Python in general. /Tobias On Wed, Jul 23, 2008 at 9:25 PM, Pinegar, Kent T [EMAIL PROTECTED] wrote: Tobias, Thanks. Do you know where I can get information on CPython? Specifically, licensing information. Kent From: Tobias Ivarsson [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2008 10:10 AM To: Pinegar, Kent T Cc: [EMAIL PROTECTED] Subject: Re: [Jython-users] Jython Licensing Question SocketServer.py is imported from CPython to where this copyright notice was committed in revision 18872, Jan 19 2001. IANAL so I don't know what is required to be able to redistribute this with Jython. But I guess that if it has been part of CPython since version 2.0 it should be fine for us as well... In fact this file (with that copyright notice) was included in the previous version of Jython as well. /Tobias On Wed, Jul 23, 2008 at 4:27 PM, Pinegar, Kent T [EMAIL PROTECTED] wrote: The file SocketServer.py in the latest version of Jython, contains a copyright by Luke Kenneth Casson Leighton. There is not, however, any license agreement to cover this copyright in the Jython download. Does anyone know if this was an oversight, or existing licenses covers it? Kent Pinegar - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Jython-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jython-users -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
I don't really mind, what you think about my response. Python will suffer from it as little as it will suffer from your complaints: These things will not change, whatever any of us says about them. So this discussion unlikely to produce any new insight, especially because this as been discussed over and over again in the past, without any effect on Python. You're right, of course. Because Python is in so many ways what I'm looking for in a language, I transform it in my mind to my own, personal ideal, close to the real existing language but with what I consider to be the imperfections removed. I'm not suggesting getting rid of explicit self, even in Python 4000. Not because of the advantages it gives, which are some but don't outweigh the net loss in my ledger. It just wouldn't be Pythonic. I know its not a Pythonic thing to want. Thats my problem - because I have a largely Pythonic approach in some areas, it upsets me when there's a mismatch. So lets say I'm -1 for introducing it into a language and +0 for keeping it in Python now that its entrenched. If a lot of users keep bringing up something like this, well my attitude used to be the same as yours - learn to love Python for what it is. Maybe Let's just drop this, and if you want to complain next time, just complain about something, that is really worth being complained about, like for instance old and outdated modules in the standard library, or real showstoppers in Python (e.g. the GIL). Its worth complaining about because I'm not just someone who has stumbled across Python after years of Java and PHP, and hasn't really grokked it, and has jumped on the net at once to start a flamewar. I'm someone who loves Python, uses it in preference to other languages, and have now returned to it after a bit of a break and its finally hit me over the head like a tonne of bricks Hey, I can see exactly what all those internet trolls were talking about. This *is* a really annoying and silly state of affairs. I was trying not to change explicit self, or even != (which has a much better case.) I was trying to ask the community to reconsider a premise that the language is built around. Explicit is actually kinda annoying a lot of the time, viz., java. This is about social and philosophical adjustments, not technical ones. In reality? I'll just keep writing Python (hopefully enough so that explicit self become burned into muscle memory), and use other languages when necessary (no more C than I have to, looking forward to dabbling in Erlang soon, and one day overcoming the parentheses phobia enough to really tackle Lisp properly). When I'm old enough and wise enough, and have the time, energy and inclination, maybe I'll sit down and put a proper effort into designing and implementing a new language that bests suits my own particular style and needs. Just maybe it'll be good enough that smart people will rally to defend its design principles from people attacking them on the internet :-) -- http://mail.python.org/mailman/listinfo/python-list
Wrapping std::set in boost::python
Has anybody wrapped std::set using boost::python? I'm trying to find the best way to do this. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
ctypes and reading value under pointer passed as param of a callback
Hi, I'm using C dll with py module and wanna read value (buffer of bytes) returned in py callback as parameter passed to dll function. -- def mycallback(data, size): # how to read data buffer here ? return 0 cbfunc = CFUNCTYPE(c_int, POINTER(c_uint8), c_int) mydll = cdll.somedll mdll.foo(cbfunct) --- Question: How to get bytes from the buffer passed to mycallback ??? Let's assume that the buffer consist of 4 bytes 4 bytes 8 bytes. I tried unpack(ii8s, data[0]) and nothing. I tried different ctypes passed to callback and nothing. Any sugestions ? Thanks, Waldek -- http://mail.python.org/mailman/listinfo/python-list
pci card adjusting
Hi all, I need to adjust the dimming property of my video card. There is currently a written application called nvclock but it is not supporting my card right now. So i need to implement the requiered register jobs on the card. This is already done to a degree in C. But i don't want to dive in to the C code right now. I prefer Python so may i implement such a feature by Python? Is there any library that i can use inside Python to get or set some register values of my pci card. Some memory stuff might be necessarry, i dont know yet how to implement the dim feature for my card. But till i observe the code, pmc smartdim offset, smartdim mask and shift amount is used for such a thing. These are vendor spesific values and lets imagine i have these values now. What is the next movement or any suggestions about this issue? -- Oğuz Yarımtepe www.loopbacking.info -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan a écrit : OK, it seems my original reply to Bruno got lost in the Aether (apologies therefore if a paraphrased quantum duplicate of this message is eventually forthcoming.) Torsten has adequately responded to his second point, Not MHO, by far. so I need only replicated what I said for the first. Please get your facts, the behaviour *is* actually fully documented: I have the facts. I know full well the behaviour is documented Then why do you write, let me quote: (snip) coding __eq__ (snip) buys you nothing from the != operator. != isn't (by default) a synonym for the negation of == (unlike in, say, every other language ever); not only will Python let you make them mean different things, without documenting this fact - it actively encourages you to do so. - it was pointed out at the time of the original discussion. Documenting a confusing, unintuitive design decision (whether its in a programming language, an end user GUI app or anything in between) doesn't justify it. I was not commenting on the actual design choice, just stating that it is actually documented. To attack a strawman: foolanguage uses the bar IO library; printing to stdout takes about 10 mins on the average machine. But thats ok, because look, its documented right here. And you're talking about strawman ??? Come on, you obviously can tell the difference between a one-line statement and your above strawman argument, don't you ? Please understand that I'm not arguing about this particular design choice (and FWIW, I'd mostly agree on the point that having a != b different from not (a == b) is actually a wart). I'm just correcting your statement about the behaviour of __eq__ / __ne__ not being documented, which is obviously false. (snip) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Torsten Bronger a écrit : Hallöchen! Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. What's defined within classes are plain functions. It's actually the lookup mechanism that wraps them into methods (and manage to insert the current instance as first argument). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / PAMIE
frankrentef wrote: Can someone help with a PAMIE issue? I'm new to Python / PAMIE and they seem like great tools but to be honest I'm finding that no responses to questions can be found (Experts Exchange, etc.) I'm hoping this will be the place. I tried to duplicate the authors ie.writeScript function shown at http://showmedo.com/videos/video?name=pythonMarchettiPamie3fromSeriesID=25 I'd rather you posted the code you've tried. I'm not too keen on viewing a video just to get hold of a piece of code, and in any case that would only show me what the author's done. We need to see what you've done, and what the traceback was. Would you mind posting some code, please? Thanks TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Please understand that I'm not arguing about this particular design choice (and FWIW, I'd mostly agree on the point that having a != b different from not (a == b) is actually a wart). I'm just correcting your statement about the behaviour of __eq__ / __ne__ not being documented, which is obviously false. (snip) What was the reasoning behind having both __eq__ / __ne__ anyway? To fit in with the equality comparisons? I do agree this one seems like a wart, but not a serious one. I'd say it would make more sense for the interpreter to provide a warning on classes that define one and not that other, at least if set to a certain level, similar to -3 for depreciated. (Or does this exist? I think a wart catching level that outputs potential warts and issues would be a useful addition!) -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and reading value under pointer passed as param of a callback
waldek schrieb: Hi, I'm using C dll with py module and wanna read value (buffer of bytes) returned in py callback as parameter passed to dll function. The callback receives a pointer instance. You can dereference the pointer to read individual bytes in this way: print data[0], data[5], data[42] or use slicing to read a bunch of bytes: print data[0:42] So, you probably want something like this: -- def mycallback(data, size): # how to read data buffer here ? print data[:size] return 0 cbfunc = CFUNCTYPE(c_int, POINTER(c_uint8), c_int) mydll = cdll.somedll mdll.foo(cbfunct) --- Question: How to get bytes from the buffer passed to mycallback ??? Let's assume that the buffer consist of 4 bytes 4 bytes 8 bytes. I tried unpack(ii8s, data[0]) and nothing. I tried different ctypes passed to callback and nothing. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with ctypes and char** data type
Philluminati schrieb: I'm a bit of a python newbie and I need to wrap a C library. I can initialise the library using CDLL('mcclient.so') and I can call functions correctly inside the library but I need to invoke one function which has this function definition: char ** CAPAPI McSearch(HMCLINK Handle, short nSearchType, short nNoSelect, char **pSelect, short nNoWhere, char **pWhere, char **pData, int iTimeout); For **pSelect I want to pass in an array of char points, which in C would be declared as char *pData[] = { ADDR, POSTCODE }; Can someone tell me how use pointers + char pointers together in python with ctypes please? # create an array that holds two pointers to 'char *', and fill it with data: pData = (c_char_p * 2)() pData[0] = ADDR pData[1] = POSTCODE # Another way: pData = (c_char_p * 2)(ADDR, POSTCODE) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Then why do you write, let me quote: (snip) coding __eq__ (snip) buys you nothing from the != operator. != isn't (by default) a synonym for the negation of == (unlike in, say, every other language ever); not only will Python let you make them mean different things, without documenting this fact - it actively encourages you to do so. My words aren't as clear as they should be. I mean that Python lets *you* do something without documenting, or rather stating to use a better term, that your intention is the non-obvious one. I'm not saying that Python itself lacks documentation for its own behaviour; I'm saying it should force you to make your intentions clear and visible to someone reading your code when you want to do something non- obvious. I was not commenting on the actual design choice, just stating that it is actually documented. Yes, it is. I apologise for the poor construction of my statement which led to this confusion. And you're talking about strawman ??? Come on, you obviously can tell the difference between a one-line statement and your above strawman argument, don't you ? I'm talking about strawmen because I was deliberately choosing to invoke one with rhetorical flourish for the purposes of making my point forcefully. I wanted people to be clear that I knew perfectly well what I was doing and that they needn't call me out on it. Please understand that I'm not arguing about this particular design choice (and FWIW, I'd mostly agree on the point that having a != b different from not (a == b) is actually a wart). I'm just correcting your statement about the behaviour of __eq__ / __ne__ not being documented, which is obviously false. Good, at least we've come to a point in this discussion where I can firmly agree with somebody. -- http://mail.python.org/mailman/listinfo/python-list
Re: New to Python, familiar with Perl - Seeking info sources
On Jul 24, 3:53 pm, Brett Ritter [EMAIL PROTECTED] wrote: After many years happily coding Perl, I'm looking to expand my horizons. [no flames please, I'm pretty aware of Perl's strengths and weaknesses and I'm just here to learn more, not to enter religious debates]. I've gone through some of the online tutorials and I'll be browsing the reference before starting the code a lot phase. My question is: What are the best sources to learn best practices or get the answers to questions? Are there any good sources to tell me what Perl habits are good/bad in the Python paradigm? What about common packages that will change my life? (I do a lot of web work, but also a lot of DB reporting) I'm also working as a Java developer primarily, so I'm glad to see that Jython has been resurrected, but I'm focusing on vanilla Python for the moment. As examples: PerlMonks has been my info source. The Perl Best Practices and Higher Order Perl books have been my tutors into better coding practices. CPAN has my life easy, giving me access to the DBI, Class::DBI (and its successors), HTML::FillInForm, Data::FormValidator, CGI::Application, and Text::CSV::Simple modules that are staples of my coding. The (occasionally complete) Perl Advent calendars have proven to be a good source to learn about helpful modules that I might not otherwise stumble across. (I've encountered Django, but I'm getting my fill of frameworks from Java for the moment, so I'm looking for lightweight pieces at the moment) My (admittedly brief) searches here and on google didn't lead me to any particular spots of concentrated Python info, and most of the Perl/ Python stuff is either a smug attack by one camp on the other or a rant about the behavior of an obscure feature between the two. Any recommendations? Thanks in advance. Best start is a quick read of DiveIntoPython that provides a nice account of how to work with Python, and relates to coming from a programming background. I also keep this List on my bookmarks, as well as the python library (http://docs.python.org//lib/). The ActiveState Python Cookbook (http://aspn.activestate.com/ASPN/ Python/Cookbook/) generally has a lot of useful code snippets worth using. Zen of Python (http://www.python.org/dev/peps/pep-0020/) shows the idea of Python and (http://www.python.org/dev/peps/pep-0008/) is the Style Guidelines for Python code. I haven't worked with the web and Python much yet so maybe someone else can help you there. Welcome :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / PAMIE
frankrentef wrote: Can someone help with a PAMIE issue? I'm new to Python / PAMIE and they seem like great tools but to be honest I'm finding that no responses to questions can be found (Experts Exchange, etc.) I'm hoping this will be the place. I tried to duplicate the authors ie.writeScript function shown at http://showmedo.com/videos/video?name=pythonMarchettiPamie3fromSeriesID=25 I'd rather you posted the code you've tried. I'm not too keen on viewing a video just to get hold of a piece of code, and in any case that would only show me what the author's done. We need to see what you've done, and what the traceback was. Would you mind posting some code, please? Thanks TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Torsten Bronger a écrit : Hallöchen! Kay Schluehr writes: On 24 Jul., 11:40, Torsten Bronger [EMAIL PROTECTED] wrote: Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. And $self2, $self3, ... to the object methods of nested classes and $cls2, $cls3, ... to the classmethods of those classes...? One could surely find ways to realise this. However, the design goal should be: Make the frequent case simple, and the rare case possible. Given the (more and more prominent) use of decorators, metaclasses and other meta-programming techniques in Python, I'm not sure the cases where you really need access to Python's object model inners are that rare. Not in my code at least. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
My words aren't as clear as they should be. I mean that Python lets *you* do something without documenting, or rather stating to use a better term, that your intention is the non-obvious one. I'm not saying that Python itself lacks documentation for its own behaviour; I'm saying it should force you to make your intentions clear and visible to someone reading your code when you want to do something non- obvious. I take it you are relating to the need for less comments within the code as the idea is the Python code itself is readable? Or are you saying that when someone does a clever trick it should be documented better? I'm a little confused as what you mean by no-documenting? I always add doc-strings to modules I will be using heavily as well as a README with them. But that isn't different from programming in other languages and using comments. (Do you mean something like JavaDoc?) -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Jordan [EMAIL PROTECTED] writes: Explicit is actually kinda annoying a lot of the time Yes. It is also very helpful for those who will later try to understand, interface with, debug, modify, or otherwise work with the code (including, in a great many cases, the original author of that code). The great boost that EIBTI grants to maintainability trumps, in my view, the annoyance felt by some at the time of writing the code. -- \ “An eye for an eye would make the whole world blind.” —Mahatma | `\Gandhi | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: repr(string)
In article [EMAIL PROTECTED], Fredrik Lundh [EMAIL PROTECTED] wrote: David C. Ullrich wrote: I've been saving data in a file with one line per field. Now some of the fields may become multi-line strings... I was about to start escaping and unescaping linefeeds by hand, when I realized that repr() and eval() should do. Hence the question: If s is a string, is repr(s) guaranteed not to contain line breaks? yes. just keep in mind that using eval() on untrusted data isn't a very good idea. Right. This data comes from me, gets put into a file and then read by me. Someone _could_ corrupt that file, but someone who could do that could more easily just throw the machine out the window... /F -- David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / PAMIE
On Jul 24, 10:07 am, Tim Golden [EMAIL PROTECTED] wrote: frankrentef wrote: Can someone help with a PAMIE issue? I'm new to Python / PAMIE and they seem like great tools but to be honest I'm finding that no responses to questions can be found (Experts Exchange, etc.) I'm hoping this will be the place. I tried to duplicate the authors ie.writeScript function shown at http://showmedo.com/videos/video?name=pythonMarchettiPamie3fromSerie... I'd rather you posted the code you've tried. I'm not too keen on viewing a video just to get hold of a piece of code, and in any case that would only show me what the author's done. We need to see what you've done, and what the traceback was. Would you mind posting some code, please? Thanks TJG THNX for your response. Based on the authors code it's very simple. from cPAMIE import PAMIE ie=PAMIE () #ie.navigate (google.com) #ie.linkClick #ie.textBoxSet #ie.writeScript ie.navigate ('https://login.yahoo.com/config/mail?.intl=us') #ie.scriptWrite () ie.scriptWrite() Below is the error I get... File C:\Python24\lib\site-packages\cPAMIE.py, line 1837, in scriptWrite nameProp = getattr(x,nameProp) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 500, in __getattr__ raise AttributeError, %s.%s % (self._username_, attr) AttributeError: unknown.nameProp -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Lawrence D'Oliveiro a écrit : In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. Oh yes ? What's missing exactly ? You have objects that have an id, state and behaviour, and you have a message-passing mechanism. You meant Python is not truly a mainstream class-based language, I think. It's sufficiently close to fool those accustomed to OO ways of doing things, s/OO/class-based/ but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. It's not even a question of OO/non-OO. An implicit self would take away some things that makes Python's *object* model so powerful. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
You're not a lunatic. We, and Python itself, change quite readily. Neither of those mean your ideas in this instance have merit. You're right, these premises don't lead to this conclusion. Neither do they lead to its negation, of course. As it happens, you're wrong on both counts. I do in fact suffer from a mental illness and have spent a week in a psych ward, so am a lunatic by some reasonable definitions. Python readily changes in some regards, but not in others. Of course, a great many things of worth have this as one of their essential qualities. Pithy replies are fun. Thanks for your opinion. I disagree strongly: I think its influence is nicely balanced by the other important principles that are also followed. This isn't just being clever, there's substance here. A clearly stated opposing position, with a decent if somewhat short justification. I think you're right insofar as you go - that if someone really sits down, and thinks clearly about all the Pythonic principles, as a whole, and in detail, then the net result in the shaping their thinking will be positive more often than not. Perhaps we're just looking at an instance of a wider problem - smart people boil good ideas down into short slogans, which are nice and memorable and somewhat helpful, but can lead to bad consequences when lots of others start overusing or misunderstanding them. -- http://mail.python.org/mailman/listinfo/python-list
need help with introducing more traffic
Hiya, I found this code snippet(reference http://www.goldb.org) and wish to do more with it than just send out a Http Get request.I would like to introduce more traffic -say by downloading files,crawling through all the links,logging in etc etc,and wish to see how the web server reacts.I'm trying to stress the server to its limitsappreciate if anyone could provide me code/ideas to inject into this. the website -http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ selected as example has many downloads.i tried from urllib import urlretrieve urlretrieve('http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32/ruby-1.6.4-i586-mswin32.zip','ruby-1.6.4-i586-mswin32.zip'),but didnt work. [QUOTE]import time import os import sys, urllib, re import httplib #from urllib import urlretrieve import urllib2 from threading import Thread class LoadManager: def __init__(self): self.thread_refs = [] self.msg = ('localhost') # default def stop(self): for thread in self.thread_refs: thread.stop() def start(self, threads=1, interval=0, rampup=1): for i in range(threads): spacing = (i * (float(rampup) / float(threads))) time.sleep(spacing) agent = LoadAgent(interval, self.msg) agent.setDaemon(True) agent.start() # print 'started thread # ' + str(i + 1) self.thread_refs.append(agent) class LoadAgent(Thread): def __init__(self, interval, msg): Thread.__init__(self) self.running = True self.interval = interval self.msg = msg def stop(self): self.running = False def run(self): while self.running: start_time = time.time() if self.send(self.msg): end_time = time.time() raw_latency = end_time - start_time expire_time = (self.interval - raw_latency) latency = ('%.3f' % raw_latency) print latency else: raw_latency = 0 expire_time = (self.interval - raw_latency) if expire_time 0: time.sleep(expire_time) def send(self, msg): try: req = urllib2.Request(msg) response = urllib2.urlopen(req) the_page = response.read() return True except: print 'failed request' return False def main(): # sample usage manager = LoadManager() manager.msg = ('http://ftp.ruby-lang.org/pub/ruby/binaries/mswin32') manager.start(threads=5, interval=2, rampup=2) if __name__ == '__main__': main()[/QUOTE] -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Just wondered whether the OP's Subject was a deliberate play on flog a dead horse or merely an ironic one :) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Inserting cookies into a web session
In [EMAIL PROTECTED] =?ISO-8859-1?Q?Michael_Str=F6der?= [EMAIL PROTECTED] writes: John Gordon wrote: I'm developing a web application that needs a semi-persistent way to store information. I've looked at some options such as writing entries to a database table or creating small textfiles, but I'm not thrilled with anything I've come up with so far. What's the problem? The problem is databases and textfiles are too heavyweight. I only need the information for the duration of a session; I don't want to have to worry about cleaning up the database or textfile afterwards. To explain my requirements a bit more, I'm writing a web-based contact manager application. The basic contact unit is a person, and I'm currently working on the page layout for displaying information relating to a person. The top section of the page is always the same: it shows your personal information. Name, userid, title, etc. But the bottom section of the page can change; it shows one of several different kinds of information. It can either display your home and office address, or it can show all the ways you can be contacted (phone, email, pager, etc), or it can show the times during which you wish to be contacted. (I didn't choose this layout; it was all done and approved before I joined the project. I just have to implement it.) My problem is if the user goes to the top portion of the page and changes some of the information there, for example he wants to change his title, that information is self-contained in a form and knows nothing about the choice the user made of what to show at the bottom of the page. Of course, I could add the choice as a hidden form element at the top of the page. But that seems kludgy -- that form *shouldn't* have to know. And the page layout isn't as simple as I've described here; there are actually lots of these little self-contained forms that are unrelated to the information at the bottom of the page, and I'd rather not have to add a hidden element to all of them. Using a cookie seems like an ideal solution. When the session starts, I can set the choice to the default setting of address, and if the user ever clicks on show me my contact methods or show me my times, I just set the cookie to that choice. I don't have to worry about passing the choice around in each of the dozen or so forms that are on the page. Before using cookies keep in mind that the cookies returned by the browser are not trustworthy! You have to validate the values each time. I'm not sure it's worth the trouble in my case. I won't be depending on the cookie for sensitive information; I'm just using it as a stored setting for which kind of information to display on the page. http://docs.python.org/lib/module-Cookie.html That looks great! Ciao, Michael. Thanks Michael. :-) -- John Gordon A is for Amy, who fell down the stairs [EMAIL PROTECTED] B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: repr(string)
David C. Ullrich wrote: In article [EMAIL PROTECTED], Fredrik Lundh [EMAIL PROTECTED] wrote: David C. Ullrich wrote: I've been saving data in a file with one line per field. Now some of the fields may become multi-line strings... I was about to start escaping and unescaping linefeeds by hand, when I realized that repr() and eval() should do. Hence the question: If s is a string, is repr(s) guaranteed not to contain line breaks? yes. just keep in mind that using eval() on untrusted data isn't a very good idea. Right. This data comes from me, gets put into a file and then read by me. Someone _could_ corrupt that file, but someone who could do that could more easily just throw the machine out the window... You could also use a csv file with a single row. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: repr(string)
Peter Otten wrote: You could also use a csv file with a single row. Err, I meant column, but a row would also work. Your choice. Peter -- http://mail.python.org/mailman/listinfo/python-list
Encoding for Devanagari Script.
Hello All, I wanted to know what encoding should I use to open the files with Devanagari characters. I was thinking of UTF-8 but was not sure, any leads on this? Anyone used it earlier? Thanks in Advance. Regards, Atul. -- http://mail.python.org/mailman/listinfo/python-list
Re: repr(string)
David C. Ullrich skrev: just keep in mind that using eval() on untrusted data isn't a very good idea. Right. This data comes from me, gets put into a file and then read by me. Someone _could_ corrupt that file, but someone who could do that could more easily just throw the machine out the window... and then your boss finds your program useful, and it's installed on a shared server, and then the guys at the office in Eggkleiva wants a copy, and then people start shipping save files via mail to keep things synchronized, and then someone sets up a web service... ;-) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Hallöchen! Bruno Desthuilliers writes: Torsten Bronger a écrit : Kay Schluehr writes: On 24 Jul., 11:40, Torsten Bronger [EMAIL PROTECTED] wrote: [...] Just like this. However, the compiler could add self to non-decorated methods which are defined within class. And $self2, $self3, ... to the object methods of nested classes and $cls2, $cls3, ... to the classmethods of those classes...? One could surely find ways to realise this. However, the design goal should be: Make the frequent case simple, and the rare case possible. Given the (more and more prominent) use of decorators, metaclasses and other meta-programming techniques in Python, I'm not sure the cases where you really need access to Python's object model inners are that rare. Not in my code at least. What does not rare mean for you? Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Hallöchen! Bruno Desthuilliers writes: Torsten Bronger a écrit : Bruno Desthuilliers writes: [...] How would you handle this case with an implicit 'self' : class Foo(object): pass def bar(self): print self Foo.bar = bar Just like this. However, the compiler could add self to non-decorated methods which are defined within class. What's defined within classes are plain functions. It's actually the lookup mechanism that wraps them into methods (and manage to insert the current instance as first argument). And why does this make the implicit insertion of self difficult? I could easily write a preprocessor which does it after all. Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python / PAMIE
frankrentef wrote: THNX for your response. Based on the authors code it's very simple. from cPAMIE import PAMIE ie=PAMIE () #ie.navigate (google.com) #ie.linkClick #ie.textBoxSet #ie.writeScript ie.navigate ('https://login.yahoo.com/config/mail?.intl=us') #ie.scriptWrite () ie.scriptWrite() Below is the error I get... File C:\Python24\lib\site-packages\cPAMIE.py, line 1837, in scriptWrite nameProp = getattr(x,nameProp) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 500, in __getattr__ raise AttributeError, %s.%s % (self._username_, attr) AttributeError: unknown.nameProp I'm afraid I'm no IE expert (read: never use it if I can avoid it) but I suspect here a combination of slightly flaky code in the Python module plus, maybe, a change in the IE dom object model. If you change lines 1832-1836 of cPAMIE.py to be as follows: patch for j in range(doc.length): x = doc[j] etype = getattr(x,type, ) name = getattr(x,name, ) nameProp = getattr(x,nameProp, ) /patch then at least some kind of output is produced. But I'm not entirely sure what this function is trying to achieve so I don't guarantee it's doing the right thing yet. TJG -- http://mail.python.org/mailman/listinfo/python-list