omniORBpy 3.4 released
I am pleased to announce that omniORB 4.1.4 and omniORBpy 3.4 are now available. omniORB is a robust, high performance CORBA implementation for C++. omniORBpy is a version for Python. They are freely available under the terms of the GNU LGPL (and GPL for stand-alone tools). These are mainly bug fix releases, with a number of minor new features. SourceForge's file upload system is currently broken, so you can download the releases from this directory on the web site: http://omniorb.sourceforge.net/releases/ There are source archives and a number of Windows builds for different compilers / Python versions. Other Windows builds may arrive later. Enjoy! Duncan. -- -- Duncan Grisby -- -- dun...@grisby.org -- -- http://www.grisby.org -- -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
plotting graph from another file
hello.. i want to plot a distribution graph for following data: *elements: number of occurance: a2 b4 c1 d9 e3* ( this a simple version) the data is in a file , say abc.txt how can i call/import the text file and draw an appropriate distribution graph in python ? can it be done using matplotlib ? if yes , please give me the code for plotting the importing the text file and plotting the graph. thanx jhinak -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very similar job as far as we can tell. My guess is that it was probably for optimization reasons long ago. I've never heard a *good* reason why Python needs both. The good reason is the immutability, which lets you use a tuple as a dict key. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
On Tue, 21 Jul 2009 00:39:24 +0200, Niels L. Ellegaard wrote: Phillip B Oldham phillip.old...@gmail.com writes: We often find we need to do manipulations like the above without changing the order of the original list, and languages like JS allow this. We can't work out how to do this in python though, other than duplicating the list, sorting, reversing, then discarding. I think Phillip is confused if he thinks that other languages can sort a list without modifying or duplicating the original. If you don't duplicate the list, how can you sort it without modifying the original? The only difference is whether the language makes the duplicate for you, or expects you to do it yourself. If you just want a one-liner, and you don't care about speed you can do the following (but I don't think this is considered best practice) x = [2,1,3] print list(sorted(x)) The call to list is redundant, as sorted() already creates a list. But that's the wrong solution to the problem. The OP wants the largest (or smallest) item, which he expects to get by sorting, then grabbing the first element: sorted(alist)[0] That requires sorting the entire list, only to throw away everything except the first item. A better solution is to use min() and max(), neither of which sort the list, so they are much faster. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: plotting graph from another file
On Tue, Jul 21, 2009 at 11:28 PM, jhinak senjhinak@gmail.com wrote: hello.. i want to plot a distribution graph for following data: elements: number of occurance: a 2 b 4 c 1 d 9 e 3 ( this a simple version) the data is in a file , say abc.txt how can i call/import the text file and draw an appropriate distribution graph in python ? can it be done using matplotlib ? if yes , please give me the code for plotting the importing the text file and plotting the graph. Given matplot's versatility, I would presume with high likelihood that matplot could make such a chart. However, the purpose of this mailinglist is *not* to do people's job/work/homework for them for free. I would suggest you first *attempt* coding a solution yourself. If you run into trouble, read http://catb.org/~esr/faqs/smart-questions.html Then ask a more specific question on the mailinglist. Best of luck. Regards, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
On Tue, 21 Jul 2009 06:49:59 -0700, Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very similar job as far as we can tell. My guess is that it was probably for optimization reasons long ago. I've never heard a *good* reason why Python needs both. Suppose you could do this: key = [1, 2] adict = {key: 'x', [1, 1]: 'y'} This would work as expected: adict[ [1, 2] ] = returns 'x' adict[ [1, 1] ] = returns 'y' But what happens if you mutate the key? key[1] = 0 adict[ [1, 2] ] = raises KeyError Okay, that's bad. What's even worse is this: key[1] = 1 adict[ [1, 1] ] = should it return 'x' or 'y'? The solution is to disallow mutable objects like lists from being used as keys in dicts, and to allow immutable list-like tuples instead. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
greg: Posting benchmark times for Pyrex or Cython is pretty meaningless without showing the exact code that was used, since times can vary enormously depending on how much you C-ify things. Was this link, shown by William, not enough? http://hg.flibuste.net/libre/games/cheval/file/46797c3a5136/chevalx.pyx#l1 Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: clean way prepend an element to a numpy array
bdb112 wrote: I saw this interest syntax on this site x[:0]=0 I guess that is cute, but could be confusing(and doesn't work) It does if you use an array of the appropriate type on the right hand side: a[:0] = array('i', [0]) -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: Mutable Strings - Any libraries that offer this?
Thanks all for your advice. I'm not actually going to use the mutable string right at the moment, but I thought I might in the future and I was just curious if it existed. I suppose a list of characters is close enough for most purposes. On Jul 22, 10:28 am, greg g...@cosc.canterbury.ac.nz wrote: Ben Finney wrote: My point was rather meant to imply that subclassing the built-in (immutable)stringtypes was the best way to usefully get all their functionality However, it would be difficult to do that without changing all C code that deals with strings, including that in extension modules. That's because the existingstringtype stores the characters in thestringobject itself. Amutablevariant would have to contain a pointer to a resizable memory block, and therefore couldn't be used as a drop-in replacement by existing C code that expects astring. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: win32api install problem
Gerry gerard.bl...@gmail.com wrote: I'm running Python 2.6 under XP. I've installed Windows 32 extensions for Python 2.6 version 1.4 (pywin32-214.win32-py2.6.exe). But If I try to import win32api, I get: File C:\python_projects\euler\driveletters.py, line 1, in module import win32api ImportError: DLL load failed: The specified module could not be found. \Python26\Lib\site-packages has: 03/23/2009 08:35 AMDIR win32 07/20/2009 09:08 AMDIR win32com 02/18/2009 01:21 PMDIR win32comext Can anyone offer a suggestion? It is very unusual that those three directories should have different creation dates. Normally, all three would have the same date and time, from whenever you ran the installer. I would suggest that you go into Add and Remove Programs, uninstall pywin32, and run the installer again. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Running a Python Service under the LocalService or NetworkService Account
On Jul 21, 8:05 pm, Martin P. Hellwig martin.hell...@dcuktec.org wrote: David Adamo Jr. wrote: On Jul 21, 10:40 am, Martin P. Hellwig martin.hell...@dcuktec.org wrote: sightseer wrote: knip Error Installing Service: Access is Denied. (5) knip Are you trying to do this on windows vista? -- MPHhttp://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' Yeah, I was trying to do it on Vista. Someone has just helped me out. I had to deactivate User Account Control on Windows Vista...and now everything is rosy. Thanks guys. No need to deactivate it, just right click on the command shell program and say run as administrator, than you can install the service via the command line. -- MPHhttp://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' Thanks MPH -- http://mail.python.org/mailman/listinfo/python-list
Re: trouble with minidom
On Jul 21, 2009, at 8:08 PM, Ronn Ross wrote: Hello I'm trying to read an xml file using minidome. The xml looks like: rootNode project namemyProj/name path/here//path /project /rootNode My code looks like so: from xml.dom.minidom import parse dom = parse(myfile.xml) for node in dom.getElementsByTagName(project'): print('name: %s, path: %s \n') % (node.childNodes[0].nodeValue, node.childNodes[1]) Unfortunately, it returns 'nodeValue as none. I'm trying to read the value out of the node fir example name: myProj. I haven't found much help in the documentation. Can someone point me in the right direction? Two issues: In your example XML file, the first child node of the project Element is the Text node containing the whitespace between the project and name tags. node.childNodes[0] will select that whitespace node. The nodeValue of an Element is null (None). In order to get the text contents of an element, you must get the nodeValue of the Text child node of the Element. Like Gabriel, I would recommend using an XML library with a more concise API than the W3C DOM (I like lxml.objectify). But if you stick with xml.dom, use the specification as a reference: http://www.w3.org/TR/REC-DOM-Level-1/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow Libraries (DB vs Code)
Diez B. Roggisch schrieb: Thomas Guettler wrote: Hi, I need to write some simple workflows with web interface. For the web stuff I will use django, but I am not sure how to do the workflow part. Did you consider using OpenERP? It comes with a web-frontend (TG1.0.8-based), but also offers a XMLRPC-server to connect to, so using it from within django shouldn't be any difficult. Workflow-definitions are stored in the DB, and can be generated visually, not sure if they have to though. Thank you for this hint. OpenERP seems well done. But the licence is GPL and the dependency is too big. But I will have a look at how they did it. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular exprssion for IRC messages
On 22 July, 06:43, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Fri, 17 Jul 2009 13:59:47 -0300, nohics nohics noh...@gmail.com escribió: When an IRC client receive a messages, this message in in a special format defined here: Message format in pseudo BNFhttp://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1( I want to transforme the message format defined in the irc protocole in the last link, to a regular expression to get the nickname, the username, the host, the commad, it's arguments if exist, and the message after : You may want to use the pyparsing module instead of a monstruous and unmantainable regular expression: http://pyparsing.wikispaces.com/ -- Gabriel Genellina Alternatively, if IIRC, the twisted framework has an IRC client, which automatically parses server messages. -- http://mail.python.org/mailman/listinfo/python-list
Ideas for problem with chat server application!
I developed a chat application with an attendant chat server. Everything is working fine. The issue now is the fact that whenever the chat server goes down (for instance, the server system shuts down as a result of power failure or some other problem), by the time the server system come back on, the chat server would have to be restarted manually. I believe (and I know) it is more appropriate for the chat server application to restart itself when the computer comes back on (and of course regardless of who is logged in and of course, even before anyone logs in). I have a batch file that executes the chat server. My attempt was to create a windows service that start automatically and runs this batch file using a Network Service account on the server system. Although, I'm having a hard time with this (temporarily), I would love to ask if there are any alternatives to using a windows service. Suggestions are highly appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Detect target name in descriptor __set__ method
On 22 July, 06:02, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: I have a class attribute 'foo' which is a data descriptor. I create an instance of such class. When I say instance.foo = value, the descriptor __set__ method is called. Is there any way to obtain the name being assigned to? ('foo' in this example). That is, I want to know the target name for the assignment that triggered the __set__ method call. class descriptor(object): def __get__(self, instance, owner): print 'descriptor.__get__ self=%r instance=%r owner=%r' % ( self, instance, owner) return self def __set__(self, instance, value): # I want to know the *name* this value is being assigned to print 'descriptor.__set__ self=%r instance=%r value=%r' % ( self, instance, value) def __delete__(self, instance): print 'descriptor.__delete__ self=%r instance=%r' % ( self, instance) class X(object): foo = descriptor() x = X() x.foo = value I can obtain the name descriptor() was assigned to at the time the X class was defined, using a custom metaclass: class Meta(type): def __new__(meta, name, bases, dict): for key,value in dict.iteritems(): if isinstance(value, descriptor): value.name = key return type.__new__(meta, name, bases, dict) class Y(object): __metaclass__ = Meta foo = descriptor() y = Y() print y.foo.name # prints 'foo' This is good enough for me (assuming no one modifies the class after defining it, no two names refer to the same descriptor, no two classes share the same descriptor instance...). But I would like to use a more direct/robust approach, if available. Any ideas? -- Gabriel Genellina class Test: def __setattr__(self, what, value): print what, value t = Test() t.foo = 'x' foo x Is that what you're after? Jon. -- http://mail.python.org/mailman/listinfo/python-list
Suggestions for Python MapReduce?
I understand that there are a number of MapReduce frameworks/tools that play nicely with Python (Disco, Dumbo/Hadoop), however these have large dependencies (Erlang/Java). Are there any MapReduce frameworks/ tools which are either pure-Python, or play nicely with Python but don't require the Java/Erlang runtime environments? -- http://mail.python.org/mailman/listinfo/python-list
binary literal
hello clp. i can insert a hex value for a character literal in a string: stuff = \x45 print stuff E can i do something like the above, but using a *binary* number? (e.g. 00101101 instead of 45) ? bye -- http://mail.python.org/mailman/listinfo/python-list
Re: binary literal
2009/7/22 superpollo u...@example.net hello clp. i can insert a hex value for a character literal in a string: stuff = \x45 print stuff E can i do something like the above, but using a *binary* number? (e.g. 00101101 instead of 45) ? (Python 3) bin(45) '0b101101' int(_, 2) 45 -- Pablo Martí http://www.linkedin.com/in/pmarti || http://www.warp.es python -c print '706d6172746940776172702e6573'.decode('hex') -- http://mail.python.org/mailman/listinfo/python-list
Re: Python
Hi, Check the below links.. http://www.tutorialspoint.com/python/ http://www.java2s.com/Tutorial/Python/CatalogPython.htm Hope that helps. Cheers -theajo On Wed, Jul 22, 2009 at 5:42 AM, Prateek prateekkakir...@gmail.com wrote: Chk dis out ... http://www.swaroopch.com/notes/Python It's gr8 guide for beginners Cheers!!! Prateek -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast reading and unpacking of binary data (struct module)
Daniel Platz mail.to.daniel.platz at googlemail.com writes: Hi, I have a Python newbie question about reading data from a binary file. I have an huge binary file from an external program. Please translate huge into Mb. Also, how much free real memory do you have? I want to read and process the data in this file in a reasonable time. It turns out that the reading of the data itself and the processing do not need most of the time. However, when using the read(bytes) method Python returns a string representing the binary information in hex. In hex is not part of the string's nature. If you look at it through hexadecimal/decimal/octal/binary spectacles, you'll see respectively hex/decimal/octal/binary. This string I have to cast/translate into a number (in my case a signed short). For this I am using the method struct.unpack from the struct module. This unpacking part of the program takes by far the most time. Is there a way to speed this up or to do it the unpacking more cleverly than with the struct module? Are you reading the file (a) two bytes at a time (b) several Kb at a time (c) whole file? Are you unpacking it ... [same options as above but the two answers may differ]? What are you planning to do with this large list/array? The array option that Gabriel mentioned should be fastest to load, and take up least memory, but working with the elements will require making int objects out of the shorts (and the reverse if you are updating the array). Is numpy (http://numpy.scipy.org/) a possibility? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: binary literal
superpollo wrote: i can insert a hex value for a character literal in a string: stuff = \x45 print stuff E can i do something like the above, but using a *binary* number? (e.g. 00101101 instead of 45) ? There are binary number literals since 2.6 and there is the chr() function. print chr(0b1000101) E Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Mechanize not recognized by py2exe
OrcaSoul wrote: ...it's too late to name my first born after you, but I did have a cat named Gabriel - she was a great cat! Remember Gabriel in English uses a hard A, as in the horn player, not Gabrielle. I know because when I first read his posts I made the same trick in my head, and hence imagined a woman. I suspect it would come to irk one almost enough to become a Gabe. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Documentation Problems
Hi Can anyone tell me where to go to suggest changes to the Python documentation? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fast reading and unpacking of binary data (struct module)
Daniel Platz wrote: Hi, I have a Python newbie question about reading data from a binary file. I have an huge binary file from an external program. I want to read and process the data in this file in a reasonable time. It turns out that the reading of the data itself and the processing do not need most of the time. However, when using the read(bytes) method Python returns a string representing the binary information in hex. This string I have to cast/translate into a number (in my case a signed short). For this I am using the method struct.unpack from the struct module. This unpacking part of the program takes by far the most time. Is there a way to speed this up or to do it the unpacking more cleverly than with the struct module? Thanks in advance. With kind regards, Daniel Consider mmap Consider numpy Consider numpy+mmap -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation Problems
Mark du Preez wrote: Hi Can anyone tell me where to go to suggest changes to the Python documentation? Drop an entry in the tracker: http://bugs.python.org Patches are always welcome, or at least suggested wording rather than vague I don't think it should say that -- although that's better than nothing! TJG -- http://mail.python.org/mailman/listinfo/python-list
GTK+ ques
I need to develop a GUI preferably in GTK using c or PYGTK.I have little idea about Python. Following are requiremnts of the application: should be GUI Sould be real time Should interface serial port should display moving maps,like google earth It is basically for Ground control station of a UAV. How would Python+Pygtk combo work? is python slower than c/c++ ,if then by how much? any suggestions for the applcation? -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation Problems
Mark du Preez wrote: Hi Can anyone tell me where to go to suggest changes to the Python documentation? Thanks. http://docs.python.org/ has a bugs-section that leads to http://docs.python.org/bugs.html You can file doc-bugs in the tracker, and check if they are already fixed in the dev-docs. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
I updated the script (python, c and java) with your unrolled version + somes litle thinks. I also tried with python3.1, unladen Q2, ironpython1.1.1 Unfortunately it doesn't work more with shedskin, i'll see on the shedskin group... c 1.85s gcj 2.15s java 2.8s python2.5 + psyco 3.1s unladen-2009Q2 145s (2m45) python2.5 254s (4m14s) python3.1 300s (5m) ironpython1.1.1 680s (11m20) -- William Dodé - http://flibuste.net Informaticien Indépendant -- http://mail.python.org/mailman/listinfo/python-list
Python ctypes on win64
Hi, Does anybody know if python includes a win64 version of ctypes? According to the documentation it should be included - at least there's no special remarks for win64, and I haven't found any recent notes saying that it shouldn't work on win64. Yet it looks like both the installer from Python.org and from ActiveState.com have disabled it. regards /ulfw -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: But that's the wrong solution to the problem. The OP wants the largest (or smallest) item, which he expects to get by sorting, then grabbing the first element: sorted(alist)[0] That requires sorting the entire list, only to throw away everything except the first item. A better solution is to use min() and max(), neither of which sort the list, so they are much faster. And if they want the n smallest or largest items (where n is significantly less than the length of the list[*]) they might consider using heapq.nsmallest() and heapq.nlargest() I find it interesting that the heapq functions tell you in the documentation that they aren't suitable for use where n==1 or where n is near the total size of the sequence whereas random.sample() chooses what it thinks is the best algorithm based on the input. At the very least I would have thought the heapq functions could check for n==1 and call min/max when it is. [*] Some quick playing with timeit seems to indicate that with a list of 200 integers nsmallest is fastest (by a very small margin) when n==2 and n==3 but is beaten by sorted[:n] when n==4, so I guess you need a reasonably long list to make it worth not sorting it: with list of 20,000 integers it isn't worth sorting unless you want more than about 700 items. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: List insertion cost
Lucas P Melo wrote: Hello, I would like to know how much it costs to insert an element into a list using this operation: a[2:2] = [ 1 ] i. e, what is the complexity of the operation above (given that len(a) = n)? O(n) I'd say. You need to copy nearly the whole list, and sometimes re-allocate it's storage (they are internally stored as arrays of object references) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: doted filenames in import statements
Piet van Oostrum wrote: [snip] JP file = /home/dsp/4.6.0.0/test.py JP test = __import__(file) JP = no module name blalalal found. JP Any suggestion ? I tried multiple escape technics without any success. Rightly so. I think the best would be to add the directory to sys.path sys.path.add('/home/dsp/4.6.0.0') and then __import__('test', ... ) I see. My problem is that a have to import 2 different files having de same name. In the same name space I have 2 objects from 2 different software branches, let's say 4.6.0 and 4.6.1. The first object shall import 4.6.0/orb.py and the second one 4.6.1/orb.py. If I add 4.6.1 to sys.path, the import statement will look like: self._orb = __import__('orb') The problem is, python wil assume orb is already imported and will assign the module from the 4.6.0 branch to my 4.6.1 object. Do I have to mess up with sys.modules keys to make python import the correct file ? Is there a standard/proper way to do that ? JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Changing the private variables content
Temat: Re: Changing the private variables content Od: Gary Herron gher...@islandtraining.com Data: Tue, 21 Jul 2009 14:14:44 -0700 Do: Ryniek90 rynie...@gmail.com Do: Ryniek90 rynie...@gmail.com Kopia: python-list@python.org Ryniek90 wrote: Hi. I'm writing some class, and decided to use inside private method and some private variables. While with method i haven't got any problem's with variables i have. Maybe some example. A class with private method and private variable: class Secret(object): # def __init__(self): self._number = 1 # def _secret(self): print self._number def showit(self): print Secret number is:\n self._secret() sec = Secret() sec.showit() Secret number is: 1 sec._number 1 sec._number = 2 sec._number 2 sec._number += 3 sec._number 5 As You can see, i made class with private method and private variable inside __init__ constructor. I've changed also the variable value, but outside class. I've got problem with changing some variable value _inside__my_ class, which i'm writing. Not sure this is what you are asking, but a method (which is how I interpret _inside__my_ class) changes the value by normal assignment like this: class Secret(object): ... def SetNumber(self,value): self._number = value Is that what you were asking? Gary Herron I've searched over google, some tuts with topics about operations on private variables, but didn't found anything - only how to make them, but no how to assign new objects/override them with new content (and other advanced and helpful options). If someone could help me, it would be great. Thanks. Thanks for hint, but looks like i can't do what i want. Maybe i show You my class: class ModPrint(object): u This will be the doc. def __init__(self): #Assign the Python installation directory - sys.exec_prefix - to variable self._default_search_path=sys.exec_prefix self._chosen_module = '' self._user_search_path = '' self._this_module = '' def _SetVar(self, attr, val): self.attr = val def _search_for_module(self, *args): Private method which walks through default Python installation directories, and search for prefered module. #walking thru all directories available in path '_user_search_path' for root, dirs, files in os.walk(self._user_search_path): for f in files: #if found file 'f' is THAT module, #full path to THAT file is assigned to variable if f == (%s.py % self._chosen_module): self._SetVar(self._this_module, os.path.join(root, f)) def print_module(self, _chosen_module='', _user_search_path='', _default_search_path=sys.exec_prefix,): Reads module chosen by user, and returns full content of this module, as it is. #if custom search path hasn't been assigned, #default path is being assigned as custom path if self._user_search_path == '': self._user_search_path = self._default_search_path #using private method '_search_for_module' with 'self.' preffix #to search for prefered module self._search_for_module(_chosen_module, _user_search_path) #opening prefered module with read-only binary mode #and assigning it to 'module_open' variable module_open = open(self._this_module, 'rb') #reading this file and assigning it to variable module_text = module_open.read() #closing read file; the read content is still available #it's stored in variable 'module_text' module_open.close() #returning the read content return module_text When i use this class in Python IDLE, i've got this error: mod = ModPrint() import socket mod.print_module('socket') Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' As You can see, i can't assign the new value os.path.join(root, f) to the 'self._this_module variable'. So for sure i've made some mistake in method: def _SetVar(self, attr, val): self.attr = val When i've changed private variables to normal, stored in class (in __init__ method), it was the same situation - i couldn't change this variable value. mod = ModPrint() mod.print_module('os') Traceback (most recent call last): File pyshell#72, line 1, in module mod.print_module('os') File pyshell#64, line 48, in print_module module_open = open(self.this_module, 'rb') IOError: [Errno 2] No such file or directory: '' Thanks i someone could
Re: Re: Changing the private variables content
On Wed, Jul 22, 2009 at 10:29 PM, Ryniek90 rynie...@gmail.com wrote: Thanks for hint, but looks like i can't do what i want. That's because def _SetVar(self, attr, val): self.attr = val doesn't work as you might think. However, I tried to replace it with: val('self.' + attr + '=\'' + val + '\'') and it gives me a syntax error! File test.py, line 7, in _setVar eval('self.' + attr + '=\'' + val + '\'') File string, line 1 self.var='Mrra' ^ SyntaxError: invalid syntax So, uh, I'm wondering if this is a bug. And also the solution to his problem. Good luck. Any ideas appreciated. Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Changing the private variables content
val('self.' + attr + '=\'' + val + '\'') Obviously that was eval, not val. Also it doesn't work without the escaped single quotes, either. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
please send any program that doesn't work with shedskin (it still is experimental after all) to me, or create an issue at shedskin.googlecode.com, and I will have a look at the problem. thanks, mark. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
On 22-07-2009, srepmub wrote: please send any program that doesn't work with shedskin (it still is experimental after all) to me, or create an issue at shedskin.googlecode.com, and I will have a look at the problem. I did it, on the discussion group http://groups.google.com/group/shedskin-discuss/browse_thread/thread/c1f47a7c21897b44 -- William Dodé - http://flibuste.net Informaticien Indépendant -- http://mail.python.org/mailman/listinfo/python-list
Finding all cycles within an undirected graph
Hey everyone, I am interested to find out all the cycles within an undirected graph. I don't have a particular implementation of nodes and vertices yet, so would someone kindly point out a good graph library for this ( I looked at pygraph and python-graph, but not really satisfied ), in addition to good algorithm for solving this issue. -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Changing the private variables content
Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Jul 22)
QOTW: If programming is symbol manipulation, then you should remember that the user interface is also symbol manipulation, and it is a MUCH harder problem than databases, sorting, searching, and all the other problems you learn about in academia. The user interface has to communicate over a rich but noisy channel using multiple under-specified protocols to a couple of pounds of meat which processes information using buggy heuristics evolved over millions of years to find the ripe fruit, avoid being eaten, and have sex. If you think getting XML was hard, that's *nothing* compared to user interfaces. The fact that even bad UIs work at all is a credit to the heuristics, bugs and all, in the meat. - Steven D'Aprano http://groups.google.com/group/comp.lang.python/msg/8c65eacbd76e79cf Invoke the same method over every object in a collection: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8fd293a9b39c8733/ There is no 'xor' boolean operator, why? What should be its outcome? http://groups.google.com/group/comp.lang.python/browse_thread/thread/16eec722310e75e8/ A thread-safe method to create unique identifiers (not necesarily increasing integers): http://groups.google.com/group/comp.lang.python/browse_thread/thread/dfe22a6446c057df/ Tim Chase tells us three ways to turn standard output into unbuffered mode: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a65f71444bd4bb53/ How to receive data of unknown length using sockets: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9e4a9f8b6e83320/ Override a method, but keeping the inherited docstring: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1e4075ba10dcbdd9/ Limiting the execution time of a code fragment: http://groups.google.com/group/comp.lang.python/browse_thread/thread/734054de170e2904/ Sharing a big object between processes using the multiprocessing module: http://groups.google.com/group/comp.lang.python/browse_thread/thread/833d4988b7af6353/ Why aren't OrderedDicts [3.1] comparable using , , =, =? http://groups.google.com/group/comp.lang.python/browse_thread/thread/c3c6f4fe7b6d487d/ So many ways to call a function - why is that? Beginners get confused: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3fd57f5ee4850530/ The reasons to choose your favorite programming language (Python, I presume!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/5d87008e328efcf9/ Tuples, lists, their differences and motivation: http://groups.google.com/group/comp.lang.python/browse_thread/thread/cb0cf56c52321ccc/ Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiasts: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report
Re: Multiple versions of python
CCW wrote: On 21 July, 15:19, Dave Angel da...@dejaviewphoto.com wrote: ChrisW wrote: Hi, I have installed 2 versions of python on my Windows XP computer - I originally had 3.0.1, but then found that the MySQL module only supported 2.*, so I've now installed that. I have found that if I change the Windows Environment Variable path, then I can change the version of python called when I type 'python' into a command line. However, I'd like to be able to choose which version I use. I know that if I change C:\Python26\python.exe to C:\Python26\python2.exe and C:\Python30\python.exe to C: \Python26\python3.exe, then typing 'python2' or 'python3' will invoke the correct interpreter. However, is it safe just to rename the executable files? Is there a more elegant way to achieve the same task? Thanks, Chris The elegant way is to have a batch directory on your PATH ( I use m:\t\bat ) and put your *.bat files there. I do NOT put any python installations on the PATH. For example, I have a batch file called: m:\t\bat\python26.bat c:\progfiles\python26\python.exe %* The %* syntax means pass all arguments through to the program. Once it all works, you can add an @ in front of the c: in order to suppress echoing the command. At that point, it'll look and work the same way as what you did, but without modifying anything in the install directory.(You may want python26.bat, pythonw26.bat, python31.bat and pythonw31.bat) The other thing you may want to do in a batch file is to change the file associations so that you can run the .py file directly, without typing python or pythonw in front of it. The relevant Windows commands are: assoc and ftype And on a related note, you may want to edit the PATHEXT environment variable, to add .PY and .PYW Thanks for this - this way made a bit more sense to me. I've now got C:\commands with the 4 .bat files in, and C:\commands in my path. It all seems to work :) I think I've missed the point of the @ though - it doesn't seem to make any difference.. I'm also a bit confused with the associations - since I've got python 2.6 and 3.1, surely the command I type (python26 or python31) is the only way to force a script to be run using a specific interpreter at runtime without having to change the .bat file every time I want to run a script using 3.1 instead of 2.6? The @ symbol was used in older versions of CMD and COMMAND to suppress echoing of the command line. I think if you're using XP or later, it doesn't matter. As for file associations, I don't know just what you already know about. When you typedata.docat a command line, the system looks for the data file, then if it's found, it looks up the program associated with that extension. On my machine, that's a particular version of Word for Windows. Similarly, if I typedigest.py and I'm in the directory containing that file, the system looks up my associations, and runs Python 2.6 on that file. If I wanted it to run Python 3.1 on that file, I'd have to change the associations, temporarily. So, first approximation, it's a way to avoid having to type PYTHON each time I want to run a script, as long as I don't need any other arguments on the (implied) command line. Further, the system will then look for digest.py everywhere on the PATH, so I don't even have to be in the same directory. And that means I can be in the data directory that digest.py is going to work on. Effectively, it raises digest.py to feeling like an executable, for most purposes. In fact, I put all my scripts in a directory, along with other simple executables. I use m:\t\bin for that purpose. These associations (to .py and .pyw) are established by the installer program for Python. But when you had multiple installs, you could choose whether the second one installed overrides the first. My point is that if you need to change them back and forth, you could use assoc and ftype to do it. On my system: M:\LabOrdersassoc .py .py=Python.File M:\LabOrdersftype Python.File Python.File=C:\PROGFI~1\ACTIVE~1\python.exe %1 %* M:\LabOrders So my .py files are associated with the 2.6.2 version of ActivePython installation. Note the similarity of the ftype to your python26.bat file? One more little trick is that I could just type digestinstead ofdigest.py, if I have added the .py and .pyw extensions to my PATHEXT environment variable.So my PATHEXT looks like: PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PY;.PYW Note that the association changes made by assoc and ftype are global. They apply to all cmd.exe windows, even those already running, and they survive a reboot. But when you set environment variables like PATHEXT, you can choose to do it in a single window (with SET), or globally (using control-panel). If I found myself switching often, I'd make separate ftype entries for each
Re: Changing the private variables content
Ryniek90 wrote: Temat: Re: Changing the private variables content Od: Gary Herron gher...@islandtraining.com Data: Tue, 21 Jul 2009 14:14:44 -0700 Do: Ryniek90 rynie...@gmail.com Do: Ryniek90 rynie...@gmail.com Kopia: python-list@python.org Ryniek90 wrote: Hi. I'm writing some class, and decided to use inside private method and some private variables. While with method i haven't got any problem's with variables i have. Maybe some example. A class with private method and private variable: class Secret(object): # def __init__(self): self._number = 1 # def _secret(self): print self._number def showit(self): print Secret number is:\n self._secret() sec = Secret() sec.showit() Secret number is: 1 sec._number 1 sec._number = 2 sec._number 2 sec._number += 3 sec._number 5 As You can see, i made class with private method and private variable inside __init__ constructor. I've changed also the variable value, but outside class. I've got problem with changing some variable value _inside__my_ class, which i'm writing. Not sure this is what you are asking, but a method (which is how I interpret _inside__my_ class) changes the value by normal assignment like this: class Secret(object): ... def SetNumber(self,value): self._number = value Is that what you were asking? Gary Herron I've searched over google, some tuts with topics about operations on private variables, but didn't found anything - only how to make them, but no how to assign new objects/override them with new content (and other advanced and helpful options). If someone could help me, it would be great. Thanks. Thanks for hint, but looks like i can't do what i want. Maybe i show You my class: class ModPrint(object): u This will be the doc. def __init__(self): #Assign the Python installation directory - sys.exec_prefix - to variable self._default_search_path=sys.exec_prefix self._chosen_module = '' self._user_search_path = '' self._this_module = '' def _SetVar(self, attr, val): self.attr = valdef _search_for_module(self, *args): Private method which walks through default Python installation directories, and search for prefered module. #walking thru all directories available in path '_user_search_path' for root, dirs, files in os.walk(self._user_search_path): for f in files: #if found file 'f' is THAT module, #full path to THAT file is assigned to variable if f == (%s.py % self._chosen_module): self._SetVar(self._this_module, os.path.join(root, f)) def print_module(self, _chosen_module='', _user_search_path='', _default_search_path=sys.exec_prefix,): Reads module chosen by user, and returns full content of this module, as it is. #if custom search path hasn't been assigned, #default path is being assigned as custom path if self._user_search_path == '': self._user_search_path = self._default_search_path #using private method '_search_for_module' with 'self.' preffix #to search for prefered module self._search_for_module(_chosen_module, _user_search_path) #opening prefered module with read-only binary mode #and assigning it to 'module_open' variable module_open = open(self._this_module, 'rb') #reading this file and assigning it to variable module_text = module_open.read() #closing read file; the read content is still available #it's stored in variable 'module_text' module_open.close() #returning the read content return module_text When i use this class in Python IDLE, i've got this error: mod = ModPrint() import socket mod.print_module('socket') Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' As You can see, i can't assign the new value os.path.join(root, f) to the 'self._this_module variable'. So for sure i've made some mistake in method: def _SetVar(self, attr, val): self.attr = val When i've changed private variables to normal, stored in class (in __init__ method), it was the same situation - i couldn't change this variable value. mod = ModPrint() mod.print_module('os') Traceback (most recent call last): File pyshell#72, line 1, in module mod.print_module('os') File pyshell#64, line 48, in print_module module_open = open(self.this_module, 'rb') IOError: [Errno 2] No such file or directory: '' Thanks i someone could
Re: invoke method on many instances
On Fri, 17 Jul 2009 05:19:50 +, Alan G Isaac wrote: def apply2(itr, methodname, *args, **kwargs): f = operator.methodcaller(methodname, *args, **kwargs) for item in itr: f(item) On 7/17/2009 3:45 AM Steven D'Aprano apparently wrote: for obj in objects: getattr(obj, methodname)(*args, **kwargs) En Sat, 18 Jul 2009 12:31:46 -0300, Alan G Isaac: Are there any obvious considerations in choosing between those two? On 7/20/2009 3:29 AM Gabriel Genellina apparently wrote: The operator.methodcaller version is faster in my tests for large collections, but slightly slower when you have very few elements. So it seems. Is this easily explained? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
What is the point of the _SetVar method? So you can set any variable in that class, I guess? -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for Python MapReduce?
On Jul 22, 5:27 am, Phillip B Oldham phillip.old...@gmail.com wrote: I understand that there are a number of MapReduce frameworks/tools that play nicely with Python (Disco, Dumbo/Hadoop), however these have large dependencies (Erlang/Java). Are there any MapReduce frameworks/ tools which are either pure-Python, or play nicely with Python but don't require the Java/Erlang runtime environments? I can't answer your question, but I would like to better understand the problem you are trying to solve. The Apache Hadoop/MapReduce java application isn't really that large by modern standards, although it is generally run with large heap sizes for performance (-Xmx1024m or larger for the mapred.child.java.opts parameter). MapReduce is designed to do extremely fast parallel data set processing on terabytes of data over hundreds of physical nodes; what advantage would a pure Python approach have here? -- http://mail.python.org/mailman/listinfo/python-list
Getting cookie expires value
Hi there, My web application uses a cookie to set/get a session id. This is working fine. However, I'm unable to work out how to get the cookie expires value. Below is test code that replicates the problem. It creates a simple web page and shows a cookie value if it's found, or creates a new one (correctly setting the expires value) and indicates that it was created: #!/usr/bin/env python import Cookie,os def printHeader(): print Content-type: text/html\n print htmltitleCookie test/title print body cookies=Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE')) if cookies.has_key('test'): #If cookie was found: printHeader() print Found cookie:br/br/ #Get cookie: c = cookies.get('test') #Print its value: print divValue: %s/div % c.value #Iterate through its items and print name/value: for k,v in c.items(): print div%s=%s/div % (k,v) else: #Define cookie: cookies['test'] = 1234 cookies['test']['expires'] = 3600 #Save cookie: print cookies['test'] #Now print HTML: printHeader() print Cookie created. print /body/html This is what I get if the cookie exists: Found cookie: Value: 1234 comment= domain= secure= expires= max-age= version= path= As you can see, the cookie attributes are valueless. Can anyone help? Am I missing something fundamental? Cheers, Brendon -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
On Wed, 22 Jul 2009 14:29:20 +0200, Ryniek90 wrote: When i use this class in Python IDLE, i've got this error: ... Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' As You can see, i can't assign the new value os.path.join(root, f) to the 'self._this_module variable'. In the __init__ method, you successfully set the `_this_module` attribute: self._this_module = '' That works, so it proves that you *can* set a private attribute. Later on, you call the `_SetVar` method, which does this: def _SetVar(self, attr, val): self.attr = val In English, this method does this: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute named exactly attr. What you actually want is: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute with the name stored in the variable attr. Can you see the difference? What you actually want is: def _SetVar(self, attr, val): setattr(self, attr, val) Your code is terribly complicated. This will probably do what you want. (Warning -- I haven't tested it, so there may be a few errors.) class ModPrint(object): u This will be the doc. def __init__(self, default_search_path=''): self.default_search_path = '' def find_module(self, modulename, search_path=''): if search_path == '': # Try the default search path instead. search_path = self.default_search_path if search_path == '': # still blank. # Try the Python search path instead. search_path = sys.exec_prefix for root, dirs, files in os.walk(search_path): for f in files: if f == %s.py % modulename: return os.path.join(root, f) def get_module_text(self, modulename, search_path=''): filename = self.find_module(modulename, search_path) module_open = open(filename, 'rb') module_text = module_open.read() module_open.close() return module_text I changed the name of print_module_text because it doesn't actually print anything. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding all cycles within an undirected graph
disappearedng wrote: Hey everyone, I am interested to find out all the cycles within an undirected graph. I don't have a particular implementation of nodes and vertices yet, so would someone kindly point out a good graph library for this ( I looked at pygraph and python-graph, but not really satisfied ), in addition to good algorithm for solving this issue. this one has been updated recently http://code.google.com/p/python-graph/ also this page has many links http://wiki.python.org/moin/PythonGraphApi -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
How to document Python code properly for Pydoc
Hi, Do you know where I can find the rules for documenting Python code, so that automatic document generation with Pydoc makes the most of the comments inserted in the code? I know about documenting class and method through triple quote just under the class definition. But how do you comment a specific field or variable, or how do you document function arguments so that they are extracted like in javadoc? Thanks very much -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple versions of python
CCW wrote: On 21 July, 15:19, Dave Angel da...@dejaviewphoto.com wrote: The other thing you may want to do in a batch file is to change the file associations so that you can run the .py file directly, without typing python or pythonw in front of it. The relevant Windows commands are: assoc and ftype And on a related note, you may want to edit the PATHEXT environment variable, to add .PY and .PYW Thanks for this - this way made a bit more sense to me. I've now got C:\commands with the 4 .bat files in, and C:\commands in my path. It all seems to work :) I think I've missed the point of the @ though - it doesn't seem to make any difference.. I'm also a bit confused with the associations - since I've got python 2.6 and 3.1, surely the command I type (python26 or python31) is the only way to force a script to be run using a specific interpreter at runtime without having to change the .bat file every time I want to run a script using 3.1 instead of 2.6? OK, for me currently: C:\ assoc .py .py=Python.File C:\ assoc .pyw .pyw=Python.NoConFile C:\ ftype Python.File Python.File=C:\Python31\python.exe %1 %* C:\ ftype Python.NoConFile Python.NoConFile=C:\Python31\pythonw.exe %1 %* C:\ ftype Python.File Python.File=C:\Python31\python.exe %1 %* Now imagine instead that you've added: C:\ ftype Python31.File=C:\Python31\python.exe %1 %* C:\ ftype Python31.NoConFile=C:\Python31\pythonw.exe %1 %* C:\ ftype Python26.File=C:\Python26\python.exe %1 %* C:\ ftype Python26.NoConFile=C:\Python26\pythonw.exe %1 %* Then you can do the following: C:\ assoc .py=Python26.File C:\ fumble.py C:\ assoc .py=Python31.File C:\ fumble.py That is the basic idea, but at the moment, I don't see a simple demo working for me. SO, if you want to pursue this, you can probably get it to work. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Detect target name in descriptor __set__ method
On Wed, 22 Jul 2009 06:02:55 +0100, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: class X(object): foo = descriptor() x = X() x.foo = value Isn't this going to create a brand new instance attribute x.foo that has nothing to do with the descriptor anyway? -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com mailto:cont...@xavierho.com Website: http://xavierho.com/ To bad, that didn't worked in my class. Still the same error: mod.print_module('socket') Traceback (most recent call last): File pyshell#121, line 1, in module mod.print_module('socket') File pyshell#118, line 51, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' :-/ What is the point of the _SetVar method? Instead of: self._SetVar(self._this_module, os.path.join(root, f)) just do: self._this_module = os.path.join(root, f) (unless I'm misunderstanding what you're trying to do!) Of course i;ve tried, but still get the same error: mod.print_module('socket') Traceback (most recent call last): File pyshell#121, line 1, in module mod.print_module('socket') File pyshell#118, line 51, in print_module module_open = open(self.this_module, 'rb') IOError: [Errno 2] No such file or directory: '' It looks like private variable have specific naure, that prevent from traditional editing them. Still searching for some tuts about private methods and variables. -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue combining gzip and subprocess
Piet van Oostrum wrote: ... f = gzip.open(filename, 'w') proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE) while True: line = proc.stdout.readline() if not line: break f.write(line) f.close() Or even: proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE) with gzip.open(filename, 'w') as dest: for line in iter(proc.stdout, ''): f.write(line) --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: plotting graph from another file
On 2009-07-22, jhinak sen jhinak@gmail.com wrote: i want to plot a distribution graph for following data: [...] can it be done using matplotlib ? if yes , please give me the code for plotting the importing the text file and plotting the graph. As soon as you're done cleaning my house, washing my car, and running a few errands. -- Grant Edwards grante Yow! Of course, you at UNDERSTAND about the PLAIDS visi.comin the SPIN CYCLE -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding all cycles within an undirected graph (disappearedng)
Actually, I have realized that using the bit vector XOR method by http://www.me.utexas.edu/~bard/IP/Handouts/cycles.pdf gives some possibility of doing so. However this method is still experimental and doesn't really have a definitive end to the algorithm (the base number of vectors can change). Any ideas anyone? On Wed, Jul 22, 2009 at 9:12 PM, python-list-requ...@python.org wrote: Send Python-list mailing list submissions to python-l...@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-requ...@python.org You can reach the person managing the list at python-list-ow...@python.org When replying, please edit your Subject line so it is more specific than Re: Contents of Python-list digest... Today's Topics: 1. Finding all cycles within an undirected graph (disappearedng) 2. Re: Re: Changing the private variables content (Xavier Ho) 3. Python-URL! - weekly Python news and links (Jul 22) (Gabriel Genellina) 4. Re: Multiple versions of python (Dave Angel) 5. Re: Changing the private variables content (MRAB) -- Forwarded message -- From: disappearedng disappeare...@gmail.com To: python-l...@python.org Date: Wed, 22 Jul 2009 21:04:18 +0800 Subject: Finding all cycles within an undirected graph Hey everyone, I am interested to find out all the cycles within an undirected graph. I don't have a particular implementation of nodes and vertices yet, so would someone kindly point out a good graph library for this ( I looked at pygraph and python-graph, but not really satisfied ), in addition to good algorithm for solving this issue. -- Forwarded message -- From: Xavier Ho cont...@xavierho.com To: python-l...@python.org Date: Wed, 22 Jul 2009 23:06:22 +1000 Subject: Re: Re: Changing the private variables content Got it: exec('self.' + attr + '=\'' + val + '\'') That worked. I think it'll do what you want now ;) Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavierho.com Website: http://xavierho.com/ -- Forwarded message -- From: Gabriel Genellina python-...@phaseit.net To: python-l...@python.org Date: Wed, 22 Jul 2009 12:48:25 + (UTC) Subject: Python-URL! - weekly Python news and links (Jul 22) QOTW: If programming is symbol manipulation, then you should remember that the user interface is also symbol manipulation, and it is a MUCH harder problem than databases, sorting, searching, and all the other problems you learn about in academia. The user interface has to communicate over a rich but noisy channel using multiple under-specified protocols to a couple of pounds of meat which processes information using buggy heuristics evolved over millions of years to find the ripe fruit, avoid being eaten, and have sex. If you think getting XML was hard, that's *nothing* compared to user interfaces. The fact that even bad UIs work at all is a credit to the heuristics, bugs and all, in the meat. - Steven D'Aprano http://groups.google.com/group/comp.lang.python/msg/8c65eacbd76e79cf Invoke the same method over every object in a collection: http://groups.google.com/group/comp.lang.python/browse_thread/thread/8fd293a9b39c8733/ There is no 'xor' boolean operator, why? What should be its outcome? http://groups.google.com/group/comp.lang.python/browse_thread/thread/16eec722310e75e8/ A thread-safe method to create unique identifiers (not necesarily increasing integers): http://groups.google.com/group/comp.lang.python/browse_thread/thread/dfe22a6446c057df/ Tim Chase tells us three ways to turn standard output into unbuffered mode: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a65f71444bd4bb53/ How to receive data of unknown length using sockets: http://groups.google.com/group/comp.lang.python/browse_thread/thread/9e4a9f8b6e83320/ Override a method, but keeping the inherited docstring: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1e4075ba10dcbdd9/ Limiting the execution time of a code fragment: http://groups.google.com/group/comp.lang.python/browse_thread/thread/734054de170e2904/ Sharing a big object between processes using the multiprocessing module: http://groups.google.com/group/comp.lang.python/browse_thread/thread/833d4988b7af6353/ Why aren't OrderedDicts [3.1] comparable using , , =, =? http://groups.google.com/group/comp.lang.python/browse_thread/thread/c3c6f4fe7b6d487d/ So many ways to call a function - why is that? Beginners get confused: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3fd57f5ee4850530/ The reasons to choose
Re: Ideas for problem with chat server application!
David Adamo Jr. wrote: I developed a chat application with an attendant chat server. Everything is working fine. The issue now is the fact that whenever the chat server goes down (for instance, the server system shuts down as a result of power failure or some other problem), by the time the server system come back on, the chat server would have to be restarted manually. I believe (and I know) it is more appropriate for the chat server application to restart itself when the computer comes back on (and of course regardless of who is logged in and of course, even before anyone logs in). I have a batch file that executes the chat server. My attempt was to create a windows service that start automatically and runs this batch file using a Network Service account on the server system. Although, I'm having a hard time with this (temporarily), I would love to ask if there are any alternatives to using a windows service. Suggestions are highly appreciated. As a starting place, take a look at the Windows Scheduler. One of the options is to schedule something at boot. That happens before anybody logs on to the system. I don't know whether you can specify what user account will be used, but you can certainly launch a python program from there. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
On Jul 22, 2:36 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: On Tuesday 21 July 2009 15:49:59 Inky 788 wrote: On Jul 20, 12:27 pm, Phillip B Oldham phillip.old...@gmail.com wrote: [snip] We understand that lists are mutable and tuples are not, but we're a little lost as to why the two were kept separate from the start. They both perform a very similar job as far as we can tell. My guess is that it was probably for optimization reasons long ago. I've never heard a *good* reason why Python needs both. The good reason is the immutability, which lets you use a tuple as a dict key. Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not sophisticated enough, but I've never wanted to use a list/ tuple as a dict key. This sounds like obscure usage, and a bit contrived as a reason for having *both* lists and tuples. -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation Problems
On Jul 22, 7:15 am, Tim Golden m...@timgolden.me.uk wrote: Mark du Preez wrote: Hi Can anyone tell me where to go to suggest changes to the Python documentation? Drop an entry in the tracker: http://bugs.python.org Patches are always welcome, Could you please provide brief instructions on exactly how to go about creating a suitable patch file? I mean, starting from the beginning (as in, check out code from {here} using {this command}, cd to {this} directory, edit the file in place, run {this} command to create a patch file). Or perhaps this procedure is already outlined elsewhere? -- http://mail.python.org/mailman/listinfo/python-list
Not understanding this documentation
http://bugs.python.org/issue5358 I simply installed 3.0 on my ubuntubox brought my project from a windows machine and made necessary changes to what I had used from os and os.path. I have an error at the end of this line: for k in range(I): and the error: SyntaxError: invalid character in identifier I've already declared I way above as the lenth of an array (I = len (IA)) There shouldn't be a problem there aren't any issues with other declarations identical to this. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
On Jul 22, 7:38 am, William Dode w...@flibuste.net wrote: I updated the script (python, c and java) with your unrolled version + somes litle thinks. I also tried with python3.1, unladen Q2, ironpython1.1.1 Unfortunately it doesn't work more with shedskin, i'll see on the shedskin group... c 1.85s gcj 2.15s java 2.8s python2.5 + psyco 3.1s unladen-2009Q2 145s (2m45) python2.5 254s (4m14s) python3.1 300s (5m) ironpython1.1.1 680s (11m20) Cool; it would be interesting to see the numbers for Jython and Boo as well if it's not too much effort. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Help understanding the decisions *behind* python?
Quoting Inky 788 inky...@gmail.com: The good reason is the immutability, which lets you use a tuple as a dict key. Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm just not sophisticated enough, but I've never wanted to use a list/ tuple as a dict key. This sounds like obscure usage, and a bit contrived as a reason for having *both* lists and tuples. I don't seem to understand your definition of obscure and contrived. It seems that you got late to this thread, and you missed the examples. I'd suggest you to go back on this thread and look at them. heights = {} heights[1,2] = 5 heights[1,3] = 7 heights[3,5] = 1 addresses[lastname, firstname] = my_home_address census[location, age] = census.get((location, age), 0) + 1 All those are using tuples as dict keys. Regards, -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Not understanding this documentation
On Wed, 22 Jul 2009 15:46:09 +0100, F.O.P. f.orndorffplunk...@gmail.com wrote: http://bugs.python.org/issue5358 I simply installed 3.0 on my ubuntubox brought my project from a windows machine and made necessary changes to what I had used from os and os.path. I have an error at the end of this line: for k in range(I): and the error: SyntaxError: invalid character in identifier I've already declared I way above as the lenth of an array (I = len (IA)) There shouldn't be a problem there aren't any issues with other declarations identical to this. Could you show us slightly more of your code and the rest of the error message, please? I have a suspicion that the error actually lies in the necessary changes you made. -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for Python MapReduce?
On Jul 22, 2:23 pm, Casey Webster casey...@gmail.com wrote: I can't answer your question, but I would like to better understand the problem you are trying to solve. The Apache Hadoop/MapReduce java application isn't really that large by modern standards, although it is generally run with large heap sizes for performance (-Xmx1024m or larger for the mapred.child.java.opts parameter). MapReduce is designed to do extremely fast parallel data set processing on terabytes of data over hundreds of physical nodes; what advantage would a pure Python approach have here? We're always taught that it is a good idea to reduce the number of dependencies for a project. So you could use Disco, or Dumbo, or even Skynet. But then you've introduced another system you have to manage. Each new system will have a learning curve, which is lessened if the system is written in an environment/language you already work with/ understand. And since a large cost with environments like erlang and java is in understanding them any issues that are out of the ordinary can be killer; changing the heap size as you mentioned above for Java could be one of these issues that a non-java dev trying to use Hadoop might come across. With the advent of cloud computing and the new semi-structured/ document databases that are coming to the fore sometimes you need to use MapReduce on smaller/fewer systems to the same effect. Also, you may need only to ensure that a job is done in a timely fashion without taking up too many resources, rather than lightening-fast. Dumbo/disco in these situations may be considered overkill. Implementations like BashReduce http://blog.last.fm/2009/04/06/ mapreduce-bash-script are perfect for such scenarios. I'm simply wondering if there's another simpler/smaller implementation of MapReduce that plays nicely with Python but doesn't require the setup/ knowledge overhead of more robust implementations such as hadoop and disco... maybe similar to Ruby's Skynet. -- http://mail.python.org/mailman/listinfo/python-list
Re: binary literal
superpollo wrote: div class=moz-text-flowed style=font-family: -moz-fixedhello clp. i can insert a hex value for a character literal in a string: stuff = \x45 print stuff E can i do something like the above, but using a *binary* number? (e.g. 00101101 instead of 45) ? bye /div There's no way to get a binary value directly into a literal, but you can convert one into a string value, as follows: x = 0b00101101 print x print chr(x) output is: 45 - Note that this is decimal 45, which is different than the hex 45 you used in your first example. For doing multiple characters, I can't see anything better than: lis = [0b00101101, 0b01000101, 0b0111] print lis s= .join(chr(x) for x in lis) print s DaveA -- http://mail.python.org/mailman/listinfo/python-list
challenging problem for changing to a dedicated non-privileged user within a script.
hello all, This is a real challenge and I don't know if a solution even exists for this or not. I am writing an application which I run as my usual user on ubuntu. the usernake is let's say kk and it has sudo permission (meaning the user is in the sudoers list ). now when i do python myscript.py, the script has to change to another non-privileged user for some tasks. let's say for example switch to the postgres user which is dedicated for postgres and has no other privileges. I have tryed doing os.setuid(112) where 112 could be the uid of the user I want the script to swith over. but I got opperation not permitted. I tryed using subprocess but that did not help me either. I tryed sudo su into the Popen command but it throws me into the terminal (shell) with postgres as the user. But that's now my desired result. what I exactly want is that the script now continues to execute under postgres user till the end. I don't know how to achieve this iffect. Infact I will need this during a serious deployment because i would have my application run as a demon as a dedicated user. I am finding some code for deamonising a python application but don't know how to tell the script to change user. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
Ryniek90 wrote: snip It looks like private variable have specific naure, that prevent from traditional editing them. Still searching for some tuts about private methods and variables. There's no tutorial on private variables for good reason: Private variables have no special characteristics. The compiler and runtime library don't treat them specially (except for the highly controversial from xx import *). It's strictly a programming convention. You've got some other bugs in your code, which I can't help you with because your code comes across formatted so strangely that it cannot compile here. Some things you might do to make it easier to get help: 1) make sure you're not mixing tabs and spaces in your source code 2) post using text messages, so they don't get reformatted. 3) copy/paste the code and error messages into your message, don't retype. 4) whenever you've made more than trivial changes to the code, repost it all, since it's very difficult to tell which suggestions you've followed, and which ones you haven't gotten yet, or maybe dismissed because they didn't work. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for Python MapReduce?
Phillip, We've had great success writing simple, project specific algorithms to split content into chunks appropriate for ETL type, Python based processing in a hosted cloud environment like Amazon EC2 or the recently launched Rackspace Cloud Servers. Since we're purchasing our cloud hosting time in 1 hour blocks, we divide our data into much larger chunks than what a traditional map-reduce technique might use. For many of our projects, the data transfer time to and from the cloud takes the majority of clock time. Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing the private variables content
Steven D'Aprano wrote: On Wed, 22 Jul 2009 14:29:20 +0200, Ryniek90 wrote: When i use this class in Python IDLE, i've got this error: ... Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' As You can see, i can't assign the new value os.path.join(root, f) to the 'self._this_module variable'. In the __init__ method, you successfully set the `_this_module` attribute: self._this_module = '' That works, so it proves that you *can* set a private attribute. Later on, you call the `_SetVar` method, which does this: def _SetVar(self, attr, val): self.attr = val In English, this method does this: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute named exactly attr. What you actually want is: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute with the name stored in the variable attr. Can you see the difference? What you actually want is: def _SetVar(self, attr, val): setattr(self, attr, val) Your code is terribly complicated. This will probably do what you want. (Warning -- I haven't tested it, so there may be a few errors.) class ModPrint(object): u This will be the doc. def __init__(self, default_search_path=''): self.default_search_path = '' def find_module(self, modulename, search_path=''): if search_path == '': # Try the default search path instead. search_path = self.default_search_path if search_path == '': # still blank. # Try the Python search path instead. search_path = sys.exec_prefix for root, dirs, files in os.walk(search_path): for f in files: if f == %s.py % modulename: return os.path.join(root, f) def get_module_text(self, modulename, search_path=''): filename = self.find_module(modulename, search_path) module_open = open(filename, 'rb') module_text = module_open.read() module_open.close() return module_text I changed the name of print_module_text because it doesn't actually print anything. Moreover, if I'm not wrong there is absolutely no difference in the way python is handling private and public attributes, for python, both are the same kind of attributes. This is purely conventional (some doc processing tool will take into account the private prefix). So there is absolutely no restriction in writing self._myVar = 0 in any of the instance methods. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 70, Issue 282
When i use this class in Python IDLE, i've got this error: ... Traceback (most recent call last): File pyshell#60, line 1, in module mod.print_module('socket') File pyshell#57, line 48, in print_module module_open = open(self._this_module, 'rb') IOError: [Errno 2] No such file or directory: '' As You can see, i can't assign the new value os.path.join(root, f) to the 'self._this_module variable'. In the __init__ method, you successfully set the `_this_module` attribute: self._this_module = '' That works, so it proves that you *can* set a private attribute. Later on, you call the `_SetVar` method, which does this: def _SetVar(self, attr, val): self.attr = val In English, this method does this: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute named exactly attr. What you actually want is: (1) Take two arguments, and store them in variables called attr and val. (2) Assign the value stored in val to an attribute with the name stored in the variable attr. Can you see the difference? What you actually want is: def _SetVar(self, attr, val): setattr(self, attr, val) Your code is terribly complicated. This will probably do what you want. (Warning -- I haven't tested it, so there may be a few errors.) class ModPrint(object): u This will be the doc. def __init__(self, default_search_path=''): self.default_search_path = '' def find_module(self, modulename, search_path=''): if search_path == '': # Try the default search path instead. search_path = self.default_search_path if search_path == '': # still blank. # Try the Python search path instead. search_path = sys.exec_prefix for root, dirs, files in os.walk(search_path): for f in files: if f == %s.py % modulename: return os.path.join(root, f) def get_module_text(self, modulename, search_path=''): filename = self.find_module(modulename, search_path) module_open = open(filename, 'rb') module_text = module_open.read() module_open.close() return module_text I changed the name of print_module_text because it doesn't actually print anything. Thanks for ready class - it works great, but that code: What you actually want is: def _SetVar(self, attr, val): setattr(self, attr, val) Didn't worked, so i wil reuse your class, and modify it later. Now i see that working on private objects complex. -- http://mail.python.org/mailman/listinfo/python-list
Copy/paste through LAN
Hello, I've a client/server application which uses Pyro to communicate each other. Now i try to implement copy/paste through LAN between server controlled filesystem to my local windows machine (I could list files in client's window). How can i pass the url information through Pyro ? Thank you in advance. Jun -- http://mail.python.org/mailman/listinfo/python-list
Re: binary literal
superpollo wrote: hello clp. i can insert a hex value for a character literal in a string: stuff = \x45 print stuff E can i do something like the above, but using a *binary* number? (e.g. 00101101 instead of 45) ? Language Ref 2.4. Literals -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation Problems
Diez B. Roggisch wrote: Mark du Preez wrote: Hi Can anyone tell me where to go to suggest changes to the Python documentation? Thanks. http://docs.python.org/ has a bugs-section that leads to http://docs.python.org/bugs.html You can file doc-bugs in the tracker, and check if they are already fixed in the dev-docs. Actually, check first at http://docs.python.org/dev/py3k/ for 3.2a http://docs.python.org/dev/ for 2.7a These are updated often, perhaps nightly. Then file if you still think a change is needed. For small changes, a specific suggested rewording is sufficient. Change 'tihs' to 'this'. Between 'Sentence 1' and 'sentence 2', I suggest adding 'sentence 3'. The doc maintainers are happy to do the rst formatting themselves. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
In article urr9m.6558$ze1.5...@news-server.bigpond.net.au, Neil Hodgson nyamatongwe+thun...@gmail.com wrote: milanj: and all of them use native threads (python still use green threads ?) Python uses native threads. But then it adds the global interpreter lock, which completely undermines the utility of native threads. So yes, it uses native threads, but it does not actually realize the benefits of that use. rg -- http://mail.python.org/mailman/listinfo/python-list
Re: Not understanding this documentation
On Jul 23, 12:46 am, F.O.P. f.orndorffplunk...@gmail.com wrote: http://bugs.python.org/issue5358 I simply installed 3.0 on my ubuntubox brought my project from a windows machine and made necessary changes to what I had used from os and os.path. I have an error at the end of this line: for k in range(I): and the error: SyntaxError: invalid character in identifier I've already declared I way above as the lenth of an array (I = len (IA)) There shouldn't be a problem there aren't any issues with other declarations identical to this. You are have used the --ftniv and --strict options and hence it's objecting to the lower-case k. -- http://mail.python.org/mailman/listinfo/python-list
Re: doted filenames in import statements
Jean-Michel Pichavant wrote: Piet van Oostrum wrote: [snip] JP file = /home/dsp/4.6.0.0/test.py JP test = __import__(file) JP = no module name blalalal found. JP Any suggestion ? I tried multiple escape technics without any success. Rightly so. I think the best would be to add the directory to sys.path sys.path.add('/home/dsp/4.6.0.0') and then __import__('test', ... ) I see. My problem is that a have to import 2 different files having de same name. In the same name space I have 2 objects from 2 different software branches, let's say 4.6.0 and 4.6.1. The first object shall import 4.6.0/orb.py and the second one 4.6.1/orb.py. If I add 4.6.1 to sys.path, the import statement will look like: self._orb = __import__('orb') The problem is, python wil assume orb is already imported and will assign the module from the 4.6.0 branch to my 4.6.1 object. Do I have to mess up with sys.modules keys to make python import the correct file ? Is there a standard/proper way to do that ? If you make the directory names into proper identifiers like v460 and v461 and add __init__.py to each to make them packages and have both on search path, then import v460.orb #or import v460.orb as orb460 import v461.orb #or import v460.orb as orb461 will get you both. One way or another, they have to get different names within Python. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
On 22-07-2009, George Sakkis wrote: On Jul 22, 7:38 am, William Dode w...@flibuste.net wrote: I updated the script (python, c and java) with your unrolled version + somes litle thinks. I also tried with python3.1, unladen Q2, ironpython1.1.1 Unfortunately it doesn't work more with shedskin, i'll see on the shedskin group... c 1.85s gcj 2.15s java 2.8s python2.5 + psyco 3.1s unladen-2009Q2 145s (2m45) python2.5 254s (4m14s) python3.1 300s (5m) ironpython1.1.1 680s (11m20) Cool; it would be interesting to see the numbers for Jython and Boo as well if it's not too much effort. I just tried with jython, but oddly it's faster without array. Thanks to Mark, i could compile to shedskin again. And add somes little improvements... c 1.65s gcj 1.9s java 2.4s python2.5 + psyco 2.9s shedskin 3.4s unladen-2009Q2 125s (2m05) Jython 2.2.1 on java1.6.0_12 176s (without array, like shedskin) Jython 2.2.1 on java1.6.0_12 334s (with array) python2.5 215s (3m35s) python3.1 246s (4m06s) ironpython1.1.1 512 (8m32s) -- William Dodé - http://flibuste.net Informaticien Indépendant -- http://mail.python.org/mailman/listinfo/python-list
Re: Not understanding this documentation
On Jul 22, 9:07 am, Rhodri James rho...@wildebst.demon.co.uk wrote: On Wed, 22 Jul 2009 15:46:09 +0100, F.O.P. f.orndorffplunk...@gmail.com wrote: http://bugs.python.org/issue5358 I simply installed 3.0 on my ubuntubox brought my project from a windows machine and made necessary changes to what I had used from os and os.path. I have an error at the end of this line: for k in range(I): and the error: SyntaxError: invalid character in identifier I've already declared I way above as the lenth of an array (I = len (IA)) There shouldn't be a problem there aren't any issues with other declarations identical to this. Could you show us slightly more of your code and the rest of the error message, please? I have a suspicion that the error actually lies in the necessary changes you made. -- Rhodri James *-* Wildebeest Herder to the Masses I spoke to a friend about it and he found that I had put in a unicode semicolon rather than ASCII. I feel silly for asking a question like this but there's really no harm done in asking. Thank you for the quick response Rhodri! Much appreciated! Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding all cycles within an undirected graph
disappearedng wrote: Hey everyone, I am interested to find out all the cycles within an undirected graph. I think you have to qualify that as 'minimal cycles' to have a well-defined problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: Not understanding this documentation
F.O.P. wrote: Your subject line should have been about SyntaxError message http://bugs.python.org/issue5358 Why reference this? Unless you added zero-width joiners in the move, this is irrelevant noise. I simply installed 3.0 on my ubuntubox Upgrade to 3.1 as soon as you can. Works better. brought my project from a windows machine and made necessary changes to what I had used from os and os.path. I have an error at the end of this line: for k in range(I): and the error: SyntaxError: invalid character in identifier I've already declared I way above as the lenth of an array (I = len (IA)) There shouldn't be a problem there aren't any issues with other declarations identical to this. I otherwise concur with R. James as there is no syntax error posted. To make sure there is nothing invisible in that line, do print(repr(for k in range(I):)) # should be no escaped chars and print(len(for k in range(I):)) # should be 18, I believe tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for Python MapReduce?
Phillip B Oldham phillip.old...@gmail.com writes: Implementations like BashReduce http://blog.last.fm/2009/04/06/ mapreduce-bash-script are perfect for such scenarios. I'm simply wondering if there's another simpler/smaller implementation of MapReduce that plays nicely with Python but doesn't require the setup/ knowledge overhead of more robust implementations such as hadoop and disco... maybe similar to Ruby's Skynet. I usually just spew ssh tasks across whatever computing nodes I can get my hands on. It's less organized than something like mapreduce, but I tend to run one-off tasks that I have to keep an eye on anyway. I've done stuff like that across up to 100 or so machines and I think it wouldn't be really worse if the number were a few times higher. I don't think it would scale to really large (10,000's of nodes) clusters. -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 22, 9:36 am, Ron Garret rnospa...@flownet.com wrote: In article urr9m.6558$ze1.5...@news-server.bigpond.net.au, Neil Hodgson nyamatongwe+thun...@gmail.com wrote: milanj: and all of them use native threads (python still use green threads ?) Python uses native threads. But then it adds the global interpreter lock, which completely undermines the utility of native threads. So yes, it uses native threads, but it does not actually realize the benefits of that use. Wrong. It only partially undermines the utility of native threads, not completely. Native threading allows some threads to run while others are blocked in a system call (as well as in a few other minor cases), which can't be done with green threads. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation Problems
Inky 788 wrote: On Jul 22, 7:15 am, Tim Golden m...@timgolden.me.uk wrote: Mark du Preez wrote: Hi Can anyone tell me where to go to suggest changes to the Python documentation? Drop an entry in the tracker: http://bugs.python.org Patches are always welcome, Could you please provide brief instructions on exactly how to go about creating a suitable patch file? I mean, starting from the beginning (as in, check out code from {here} using {this command}, cd to {this} directory, edit the file in place, run {this} command to create a patch file). Or perhaps this procedure is already outlined elsewhere? It's the typical svn-based development, svn checkout from the repository (see list of svn urls here: http://www.python.org/dev/faq/#how-do-i-get-a-checkout-of-the-repository-read-only-and-read-write), modify the files, then svn diff (or diff -u) And last but not least, check out the dev-faq: http://www.python.org/dev/faq/ -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
Carl Banks pavlovevide...@gmail.com writes: Wrong. It only partially undermines the utility of native threads, not completely. Native threading allows some threads to run while others are blocked in a system call (as well as in a few other minor cases), which can't be done with green threads. Why is that such an advantage? Green threads work fine if you just organize the i/o system to never block. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyserial and pyQt
On Jul 21, 7:24 pm, David Boddie da...@boddie.org.uk wrote: On Tuesday 21 July 2009 21:37, Seth wrote: I have used pyserial in the past but this is my first experience with pyQt. I am using the Python xy package for windows current but might move to linux. I have a small device that is outputting a basic text string. I want to be able to read this string(from the comm port) and update a text box and eventually a graph in pyQt. I can't find any documentation or tutorials on how to do this. If anyone can point me in the right direction or give me some tips I would be grateful. It seems that someone has already asked a similar question on Stack Overflow, though perhaps you should start with a simpler solution and look at more advanced ones later: http://stackoverflow.com/questions/771988/pyqt4-and-pyserial One starting point is this list of tutorials on the PyQt and PyKDE Wiki: http://www.diotavelli.net/PyQtWiki/Tutorials Later, when you want to draw graphs, you might find PyQwt useful: http://pyqwt.sourceforge.net/ You may already be aware that there's also a mailing list for PyQt and PyKDE: http://www.riverbankcomputing.com/pipermail/pyqt/ Another way to get answers to questions is to join the #pyqt IRC channel at freenode.net: irc://irc.freenode.net/ David Thanks for the response. I have gone through a lot of the tutorials. All of them(that I saw) seem to just deal will event-based applications ie calculator, image viewer, etc. How do I run pyserial in the background and pass the information to PyQT and refresh the screen? Is there a way to have pyserial run in another thread and pass the information to the UI? Thanks, Seth -- http://mail.python.org/mailman/listinfo/python-list
Re: How to document Python code properly for Pydoc
jorma kala wrote: Hi, Do you know where I can find the rules for documenting Python code, so that automatic document generation with Pydoc makes the most of the comments inserted in the code? I know about documenting class and method through triple quote just under the class definition. But how do you comment a specific field or variable, or how do you document function arguments so that they are extracted like in javadoc? Thanks very much pydoc is a simple tool, and doesn't do much. You write in freeform, although generally you'll do something like this: def myfunc(a, b): ''' short description of myfunc longer description of myfunc, if necessary, and typically includes description of the arguments and the behaviors. Also includes the description of the return value. ''' pass pydoc doesn't recognize any special markups. If you want to get more from the docstring, you need other documentation generator such as epydoc, Doxygen, or Sphinx. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for Python MapReduce?
On Jul 22, 5:55 pm, Paul Rubin http://phr...@nospam.invalid wrote: Phillip B Oldham phillip.old...@gmail.com writes: I usually just spew ssh tasks across whatever computing nodes I can get my hands on. It's less organized than something like mapreduce, but I tend to run one-off tasks that I have to keep an eye on anyway. I'm thinking of repeated tasks; things you run regularly, but don't need to be blisteringly fast. I'll more than likely use Disco, but if I were to find something more light-weight I'd take a serious look. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
On 22-07-2009, William Dode wrote: c 1.65s gcj 1.9s java 2.4s python2.5 + psyco 2.9s shedskin 3.4s with -bw i have 2.6s unladen-2009Q2 125s (2m05) Jython 2.2.1 on java1.6.0_12 176s (without array, like shedskin) Jython 2.2.1 on java1.6.0_12 334s (with array) python2.5 215s (3m35s) python3.1 246s (4m06s) ironpython1.1.1 512 (8m32s) somebody can test with ironpython on windows ? Anyway, it's very impressive. I wonder if unladen will be so close in the futur. -- William Dodé - http://flibuste.net Informaticien Indépendant -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 22, 10:20 am, Paul Rubin http://phr...@nospam.invalid wrote: Carl Banks pavlovevide...@gmail.com writes: Wrong. It only partially undermines the utility of native threads, not completely. Native threading allows some threads to run while others are blocked in a system call (as well as in a few other minor cases), which can't be done with green threads. Why is that such an advantage? Green threads work fine if you just organize the i/o system to never block. Because then I don't have to organize the I/O system never to block. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order
i never heard of the logging module, but this function seemed simple enough. i assume this link is what you refering to: http://docs.python.org/library/logging.html thanks for the helpful info. i think Piet van Oostrum has resolved my issue. good eyes! -- http://mail.python.org/mailman/listinfo/python-list
Re: list of 'magic methods' or builtin class methods... want to exclude those from dir output
On Jul 22, 12:15 pm, DG dang...@gmail.com wrote: There is probably a better way to do this (please enlighten me, if you know), but what I want to do is get a list of a class' attributes minus whatever the 'builtin' methods are. I would also like to do this for instances of classes as well. I don't want to use __dict__ because I want to get all of the attributes that have been added throughout the inheritance tree, just not the builtin ones. I was wondering if there is a function to return a list of these, so I could perform a 'dir' on the object (class or instance) and filter out the builtin attributes. I know I could create my own list something like ['__class__', '__delattr__', ..., '__weakref__'] and use that. I would see this being fragile to Python version differences as new ones are added or taken away. A more flexible way is to have the list be filled out dynamically by creating a 'junk' class that inherits only from object and storing it's dir() output into the filter list. This is probably what I'll do unless someone knows of a builtin function that will give me a (version-safe) list. Thanks! Haha, replying to my own post. Here is the implementation of my idea of dynamically creating the filter lists from a 'junk' object. As of now it appears that the dir output of a class is the same as the dir output of an instance, but if that ever changes, this should future proof it. This is only a 4-liner, so it is probably good enough for what I want to do, but I would rather use a builtin/standard way if there is one. class A(object): pass class_filter_methods = dir(A) instance_filter_methods = dir(A()) -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On 2009-07-22, Ron Garret rnospa...@flownet.com wrote: In article urr9m.6558$ze1.5...@news-server.bigpond.net.au, Neil Hodgson nyamatongwe+thun...@gmail.com wrote: milanj: and all of them use native threads (python still use green threads ?) Python uses native threads. But then it adds the global interpreter lock, which completely undermines the utility of native threads. So yes, it uses native threads, but it does not actually realize the benefits of that use. Not all of the time. For library/extension calls that release the GIL, it does. -- Grant Edwards grante Yow! I was making donuts at and now I'm on a bus! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 22, 12:04 pm, Paul Rubin http://phr...@nospam.invalid wrote: Carl Banks pavlovevide...@gmail.com writes: Why is that such an advantage? Green threads work fine if you just organize the i/o system to never block. Because then I don't have to organize the I/O system never to block. We're talking about what a language implementation does behind the scenes, I thought. No we're not, we are talking about the whether GIL completely or only partially undermines the use of native threads on Python. I don't think your fantasy async-only all-green-thread langauge implementation is possible anyway. How would you wait on a pipe in one thread, a socket in another, a semaphore in a third? (Are there any popular OSes that offer a unified polling interface to all possible synchronizations?) And what do you do about drivers or libraries that make underlying blocking calls? What if you have a busy calculation going on in the background? Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Shed Skin 0.2, an experimental (restricted) Python-to-C++ compiler
On Jul 22, 12:45 pm, William Dode w...@flibuste.net wrote: On 22-07-2009, George Sakkis wrote: On Jul 22, 7:38 am, William Dode w...@flibuste.net wrote: I updated the script (python, c and java) with your unrolled version + somes litle thinks. I also tried with python3.1, unladen Q2, ironpython1.1.1 Unfortunately it doesn't work more with shedskin, i'll see on the shedskin group... c 1.85s gcj 2.15s java 2.8s python2.5 + psyco 3.1s unladen-2009Q2 145s (2m45) python2.5 254s (4m14s) python3.1 300s (5m) ironpython1.1.1 680s (11m20) Cool; it would be interesting to see the numbers for Jython and Boo as well if it's not too much effort. I just tried with jython, but oddly it's faster without array. FYI Jython 2.5 was released last month, you may want to try this instead of 2.2. George -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Wed, 22 Jul 2009 12:35:52 -0700 (PDT), Carl Banks pavlovevide...@gmail.com wrote: On Jul 22, 12:04 pm, Paul Rubin http://phr...@nospam.invalid wrote: Carl Banks pavlovevide...@gmail.com writes: Why is that such an advantage? Green threads work fine if you just organize the i/o system to never block. Because then I don't have to organize the I/O system never to block. We're talking about what a language implementation does behind the scenes, I thought. No we're not, we are talking about the whether GIL completely or only partially undermines the use of native threads on Python. I don't think your fantasy async-only all-green-thread langauge implementation is possible anyway. How would you wait on a pipe in one thread, a socket in another, a semaphore in a third? (Are there any popular OSes that offer a unified polling interface to all possible synchronizations?) Every OS I can think of can support the three examples you gave here. And what do you do about drivers or libraries that make underlying blocking calls? Certainly a point to consider. What if you have a busy calculation going on in the background? What if you do? Are you suggesting this would somehow prevent I/O from being serviced? I'm not sure why, as long as the implementation pays attention to I/O events. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: logging outgoing HTTP POST message and incoming response message
On Jul 22, 1:54 pm, Diez B. Roggisch de...@nospam.web.de wrote: You can use proxy-tools such as tcpmon or sniff traffic using wireshark. Diez Thanks, but I am trying to enable some debug mode to log all outgoing and incoming messages for certain period of time, and running another proxy-tool is not very ideal. It would be great to log it in some log file. -- http://mail.python.org/mailman/listinfo/python-list
Re: time.strftime('%m-%d-%Y %H:%m:%S') to log is out of order
davidj411 davidj...@gmail.com (d) wrote: d i never heard of the logging module, but this function seemed simple d enough. d i assume this link is what you refering to: d http://docs.python.org/library/logging.html d thanks for the helpful info. i think Piet van Oostrum has resolved d my issue. good eyes! Without glasses I wouldn't have noticed it :=) -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue combining gzip and subprocess
Scott David Daniels scott.dani...@acm.org (SDD) schreef: SDD Piet van Oostrum wrote: ... f = gzip.open(filename, 'w') proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE) while True: line = proc.stdout.readline() if not line: break f.write(line) f.close() SDD Or even: SDD proc = subprocess.Popen(['ls','-la'], stdout=subprocess.PIPE) SDD with gzip.open(filename, 'w') as dest: SDD for line in iter(proc.stdout, ''): SDD f.write(line) If it would work. 1) with gzip... is not supported in Python 3.1 2) for line in iter(proc.stdout), i.e. no second argument. 3) dest == f should be the same identifier. Lesson: if you post code either: - test it and copy verbatim from your test, or - write a disclaimer -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: If Scheme is so good why MIT drops it?
On Jul 22, 1:53 pm, Jean-Paul Calderone exar...@divmod.com wrote: On Wed, 22 Jul 2009 12:35:52 -0700 (PDT), Carl Banks pavlovevide...@gmail.com wrote: On Jul 22, 12:04 pm, Paul Rubin http://phr...@nospam.invalid wrote: Carl Banks pavlovevide...@gmail.com writes: Why is that such an advantage? Green threads work fine if you just organize the i/o system to never block. Because then I don't have to organize the I/O system never to block. We're talking about what a language implementation does behind the scenes, I thought. No we're not, we are talking about the whether GIL completely or only partially undermines the use of native threads on Python. I don't think your fantasy async-only all-green-thread langauge implementation is possible anyway. How would you wait on a pipe in one thread, a socket in another, a semaphore in a third? (Are there any popular OSes that offer a unified polling interface to all possible synchronizations?) Every OS I can think of can support the three examples you gave here. I guess you would know, but polling on all of these at once has got use more obscure calls than I'm familiar with. On Linux I can use select to wait for pipes and sockets, but not SysV semaphores AFAIK. On Windows it's well known that select only works for sockets. So do all these OSes have some kind of __mega_unifying_poll system call that works for anything that might possibly block, that you can exploit from a user process? And what do you do about drivers or libraries that make underlying blocking calls? Certainly a point to consider. What if you have a busy calculation going on in the background? What if you do? Are you suggesting this would somehow prevent I/O from being serviced? I'm not sure why, as long as the implementation pays attention to I/O events. Using native theads with blocking allows one to run a background calculation without burdening it to yield often enough to provide sufficient response times for other operations (which may or may not be convenient to do). Even if it's possible to accomplish arbitrary background processing without native threading (and it is not, because the background calculations could be performed by a library you don't control whose author didn't bother yielding at any point), you cannot reasonably claim native threads have no advantage in this case. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: challenging problem for changing to a dedicated non-privileged user within a script.
Krishnakant hackin...@gmail.com (K) wrote: K hello all, K This is a real challenge and I don't know if a solution even exists for K this or not. K I am writing an application which I run as my usual user on ubuntu. K the usernake is let's say kk and it has sudo permission (meaning the K user is in the sudoers list ). K now when i do python myscript.py, the script has to change to another K non-privileged user for some tasks. K let's say for example switch to the postgres user which is dedicated for K postgres and has no other privileges. K I have tryed doing os.setuid(112) where 112 could be the uid of the user K I want the script to swith over. K but I got opperation not permitted. Being a sudoer is not a privilege to issue the os.setuid system call. It is only a permission to use the sudo command. K I tryed using subprocess but that did not help me either. I tryed sudo K su into the Popen command but it throws me into the terminal (shell) K with postgres as the user. You could execute the command: sudo -u postgres required_command with subprocess. You have another problem then: your password must be supplied unless the NOPASSWD flag is set in the sudoers file. K But that's now my desired result. K what I exactly want is that the script now continues to execute under K postgres user till the end. I don't think that's possible if you start as the user kk. K I don't know how to achieve this iffect. K Infact I will need this during a serious deployment because i would have K my application run as a demon as a dedicated user. K I am finding some code for deamonising a python application but don't K know how to tell the script to change user. K happy hacking. K Krishnakant. -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list