ANN: PyAMF 0.2
We released PyAMF 0.2, a lightweight library that allows Flash and Python applications to communicate via Adobe's ActionScript Message Format. AMF3 and RemoteObject are supported in all the implemented Remoting gateways, currently supported for Django, Twisted, Web2Py and WSGI. This release comes with the following changes: - Encoding/decoding performance has been increased 2x for AMF0 and upto 10x(!) for AMF3 (Ticket:198) - Logging is now possible in all the supported gateways (Ticket:173) - Python 2.3 support (Ticket:33) - Python 2.6 support (Ticket:222) - Made PyAMF distributable as zip-based Python Egg (Ticket:193) - Encoders/Decoders now check for __getstate__/__setstate__ respectively (Ticket:209) - A new preprocessor function that runs after authentication, but before invoking the service method (Ticket:196) - authenticator can now be decorated with expose_request (Ticket:195) - Removed amfinfo console_script (Ticket:226) - Gateway import hack has now been removed - permanently (Ticket:224) Check out the download page [1], installation instructions [2] and examples [3]. Questions? First stop is the mailing list [4], but we also hang out on [5]. Cheers, - the PyAMF team [1] http://pyamf.org/wiki/Download [2] http://pyamf.org/wiki/Install [3] http://pyamf.org/wiki/Examples [4] http://pyamf.org/wiki/MailingList [5] irc://freenode.net/pyamf -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: EuroSciPy 2008 Conference - Leipzig, Germany
Greetings, We're pleased to announce the EuroSciPy 2008 Conference to be held in Leipzig, Germany on July 26-27, 2008. http://www.scipy.org/EuroSciPy2008 We are very excited to create a venue for the European community of users of the Python programming language in science. This conference will bring the presentations and collaboration that we've enjoyed at Caltech each year closer to home for many users of SciPy, NumPy and Python generally--with a similar focus and schedule. Call for Participation: -- If you are a scientist using Python for your computational work, we'd love to have you formally present your results, methods or experiences. To apply to present a talk at this year's EuroSciPy, please submit an abstract of your talk as a PDF, MS Word or plain text file to [EMAIL PROTECTED] The deadline for abstract submission is April 30, 2008. Papers and/or presentation slides are acceptable and are due by June 15, 2008. Presentations will be allotted 30 minutes. Registration: Registration will open April 1, 2008. The registration fee will be 100.00€ for early registrants and will increase to 150.00€ for late registration. Registration will include breakfast, snacks and lunch for Saturday and Sunday. Volunteers Welcome: -- If you're interested in volunteering to help organize things, please email us at [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[ANN] PyGtkImageView 1.1.0 -- Image viewer widget for PyGTK
I'm pleased to finally announce PyGtkImageView 1.1.0! Description --- GtkImageView is a simple image viewer widget for GTK+. Similar to the image viewer panes in gThumb or Eye of Gnome. It makes writing image viewing and editing applications easy. Among its features are: * Mouse and keyboard zooming. * Scrolling and dragging. * Adjustable interpolation. * Fullscreen mode. * GIF animation support. * Ability to make selections. * Extensible using a tool system. PyGtkImageView is the Python bindings for GtkImageView. PyGtkImageView Download --- Subversion: svn co http://publicsvn.bjourne.webfactional.com/pygtkimageview Tarball: http://trac.bjourne.webfactional.com/attachment/wiki/WikiStart/pygtkimageview-1.1.0.tar.gz API doc: http://trac.bjourne.webfactional.com/chrome/common/pygtkimageview-docs/ PDF: http://trac.bjourne.webfactional.com/attachment/wiki/WikiStart/pygtkimageview-1.1.0-api.pdf Project website: http://trac.bjourne.webfactional.com Examples Here is the canonical example for using the widget:: import gtk import gtk.gdk import gtkimageview view = gtkimageview.ImageView() scroll = gtkimageview.ImageScrollWin(view) # Where box is a gtk.Box already part of your layout. box.pack_start(scroll) pixbuf = gtk.gdk.pixbuf_new_from_file(someimage.png) view.set_pixbuf(pixbuf) -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
VIFF 0.4
I'm very happy to announce the release of VIFF version 0.4: Tar/GZ: http://viff.dk/release/viff-0.4.tar.gz Tar/BZ2: http://viff.dk/release/viff-0.4.tar.bz2 Zip: http://viff.dk/release/viff-0.4.zip Exe: http://viff.dk/release/viff-0.4.win32.exe The changes since version 0.3 are: Implemented a reliable Bracha broadcast which is secure against active adversaries. Shamir sharings, pseudo-random as well as standard, can now be asymmetric which means that only a subset of the parties provide input. The open protocol is now also asymmetric, in the sense that only a subset of the parties receive the opened result. The behavior of field elements in Boolean expressions has been fixed. This means that GF256(0) and GF256(1) now returns GF256(0) instead of GF256(1). Added a modern implementation of the classic Yao millionaires example from 1982 which started this field of research. About VIFF: Virtual Ideal Functionality Framework is a framework for creating efficient and secure multi-party computations (SMPC). Players, who do not trust each other, participate in a joint computation based on their private inputs. The computation is done using a cryptographic protocol which allows them to obtain a correct answer without revealing their inputs. Operations supported include addition, multiplication, and comparison, all with Shamir secret shared outputs. -- Martin Geisler VIFF (Virtual Ideal Functionality Framework) brings easy and efficient SMPC (Secure Multi-Party Computation) to Python. See: http://viff.dk/. pgpQpalPlFsJH.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: no more comparisons
Terry Reedy [EMAIL PROTECTED] writes: | I don't see what's so inefficient about it necessarily. The key function is called once per list item, for n calls total. The comparision function is called once per comparision. There are at least n-1 such calls and typically something on the order of n * lg2(n) calls. Right. Depending on the application, calling the comparison function lg(n) times may be faster than calling the key function once. Example: you want to sort a list of strings case-independently, each string containing a few pages worth of text. There are 1 strings, each maybe 1 chars long. Then (untested): x.sort(xs, key=lower) makes a copy of each of the 1 strings, makes 1 tuples, sorts, then releases the temporary strings and tuples. At least 100 megabytes of memory allocated and 100 million chars copied, even though any give pair of strings will usually differ somewhere in the first few characters and there's no need to look past those. from string import lower from operator import eq from itertools import * def xcmp(a,b): for x,y in izip(a,b)): c = cmp(x.lower() y.lower()) if c: return c return 0 x.sort(xcmp) runs the comparison function about 14000 times, looking at only a few bytes on most of the calls, and using only a small constant amount of auxiliary storage, and is likely to be much faster than all that copying. Hmm, there is a slight problem with xcmp-- it will fail if a is a prefix of b. That's fixable but anyway it still makes its point as written. -- http://mail.python.org/mailman/listinfo/python-list
Dispatch(Excel.Application) failed
Hi, Maybe it 's quite simple, but I can't fix it. Do I make some mistakes in my env setting? My excel version is 2003. any suggestion? Thanks. Traceback (most recent call last): File testexcel.py, line 3, in ? excel = Dispatch(Excel.Application) File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c lsctx) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 98, in _ GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 78, in _ GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II D_IDispatch) pywintypes.com_error: (-2147221005, '\xce\xde\xd0\xa7\xb5\xc4\xc0\xe0\xb1\xf0\xd7\xd6\xb7\xfb\xb4\xae', None, None) -- http://mail.python.org/mailman/listinfo/python-list
copying all data(tags and values) after a particular XML tag
i've an XML file with the following structure a b c . . . . ./c /b /a what i want to do is copy all data(tags and all) between N and N+k appearances of c. I am a python newbie. How do I do it? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: a Roguelike in Python
On Mar 12, 8:25 am, [EMAIL PROTECTED] wrote: Seeing the 7DRL start up recently, i wanted to see what one was made of. Python is the language i'm most familiar with so i searched for some code to look at, but i couldn't find any. Can anyone direct me to the right place? I did some searching on what it would take to write a roguelike in python and it looked like the curses module would work perfectly, but it looks to me like it doesn't work in windows? I tried to import it and it says 'No Module named _curses' Sorry if all this sounds a bit noobish, it's only cause i am. I made a very small basic roguelike, except that in it you control the monsters instead of the hero. It uses curses so no worky in windows. Here: http://silmarill.org/nodes/I,_monster_game.html I later modified this game to control the hero and sometimes to ask you multiple-choice questions from biology and other fields of knowledge, and based on your right/wrong answer it either makes a Hit for your HP or gives you a small reward. If there's interest i can post that updated game too. Both are kind of buggy though.. -ak -- http://mail.python.org/mailman/listinfo/python-list
Re: copying all data(tags and values) after a particular XML tag
On Mar 13, 8:21 am, [EMAIL PROTECTED] wrote: i've an XML file with the following structure a b c . . . . ./c /b /a what i want to do is copy all data(tags and all) between N and N+k appearances of c. I am a python newbie. How do I do it? Thanks. You can take a look at the docs for Beautiful Soup, they might help you. If it's just as simple as you're describing and you could always do something like... test = a b c 1 /c /b b c 2 /c /b /a test = test.replace('c','|||').replace('/c','|||') [i for (j,i) in enumerate(tmp2.split('|')) if j%2] which would yield ['\n1\n', '\n2\n'] which you could then parse as required. -- http://mail.python.org/mailman/listinfo/python-list
Re: no more comparisons
Paul Rubin http://phr.cx@NOSPAM.invalid wrote in message news:[EMAIL PROTECTED] | Terry Reedy [EMAIL PROTECTED] writes: | | I don't see what's so inefficient about it necessarily. | | The key function is called once per list item, for n calls total. The | comparision function is called once per comparision. There are at least | n-1 such calls and typically something on the order of n * lg2(n) calls. | | Right. Depending on the application, calling the comparison function | lg(n) times may be faster than calling the key function once. | | Example: you want to sort a list of strings case-independently, each | string containing a few pages worth of text. There are 1 strings, | each maybe 1 chars long. If the strings are pulled in from a file, or stored off to a file, as I would expect in and real app of this sort, the in-memory data to be sorted could/should be tuples of the lowercased strings and files positions. Then no key param is needed. | Then (untested): | | x.sort(xs, key=lower) | | makes a copy of each of the 1 strings, makes 1 tuples, sorts, | then releases the temporary strings and tuples. At least 100 | megabytes of memory allocated and 100 million chars copied, even | though any give pair of strings will usually differ somewhere in the | first few characters and there's no need to look past those. | | from string import lower | from operator import eq | from itertools import * | | def xcmp(a,b): | for x,y in izip(a,b)): | c = cmp(x.lower() y.lower()) | if c: return c | return 0 | | x.sort(xcmp) | | runs the comparison function about 14000 times, 14 * 1 = 14, not 14000. For each of these, you have a call to izip and multiple calls to .next, cmp, and .lower. That said, this use case of where the potentially needed key is long whereas the actually needed key is much shorter is a better use case than anything I have seen so far. Still, as I figure it, the initial part of each text is lowercased around 28 times, on average. So there can only be a speed saving if the text is more than 28 times the effective actual key. To actually do such a thing, at least more than once, I would be tempted to have the key function take just the first k chars, for k perhaps 50. If the texts average, say, 1500 chars, then the key array would be 1/30 * perhaps 2 (for object overhead) = 1/15 of the original array space. Then run over the 'sorted' array to see if there are any cases where the first 50 chars match and if so, check more to see if a swap needs to be made. Easiest would be to do a simple bubble or insert sort with the full compare. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: mulithreaded server
asit [EMAIL PROTECTED] wrote: In the above program, why there is an unhandeled exception ??? Probably because the code as you posted it has at least a half-dozen mistakes. import socket import sys import thread p=1 PORT=11000 BUFSIZE=1024 def getData(cSocket): global stdoutlock,cSocketlock while True: cSocketlock.acquire() data=cSocket.recv(BUFSIZE) if data=='q': data='client exited' cSocket.close() p=0 cSocketlock.release() stdoutlock.acquire() stdout.write(data) stdoutlock.release() You do not need the global statement there, since you are not changing either stdoutlock or cSocketlock. However, you ARE setting p, so you need a global p. Otherwise, you are simply creating a variable called p that is local to the function, and which disappears when the function returns. Calling a global variable p is a very bad practice, by the way. def sendData(cSocket): global stdoutlock,cSocketlock while True: stdoutlock.acquire() data=raw_input('') cSocketlock.acquire_lock() if data=='q': stdout.write('server exited') stdout.release() p=0 cSocket.close() sSocket.send(data) sSocketlock.release() Same comments. You do not need the global statement you have, but you do need global p if you want to change the global version of p. Further, as Jean-Paul pointed out and you rather rudely ignored, there is no variable called sSocketlock, because you commented it out. Next, stdout.release() will fail. stdout does not have a release function. You meant stdoutlock.release(). Next, you release sSocketlock, but you never acquired it. And if data does not equal q, you repeatedly acquire stdoutlock, but you never release it. Fix these problems, and then see if you can ask for help in a more thorough fashion. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout assign to- bug
import sys class ThreadedOut: def __init__( self, old ): self._old= old def write( self, s ): self._old.write( s ) sys.stdout= ThreadedOut( sys.stdout ) Python 3.0a2 WinXP, on the console. 'a' is undeclared but error message isn't thrown. With 'sys.stdout= Thr...' commented: stdout and stderr needn't be built-in file objects: any object is acceptable as long as it has a write() method that takes a string argument. Adding def flush( self ): self._old.flush() fixed it. Can we get that in the docs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
On Mar 12, 8:48 pm, Carl Banks [EMAIL PROTECTED] wrote: On Mar 12, 2:19 pm, Alex [EMAIL PROTECTED] wrote: Hi all, The subject says pretty much all, i would very appreciate an answer. I tried to search the various forums and groups, but didn't find any specific answer... Python technically has no equivalent: you can't run code at compile time. However, the BEGIN block in Perl seems to have been added to work around some of Perl's nonlinear order of execution. Normally in Python you don't need a BEGIN block: just put the code at the top of you script/module and it will exectute before anything else. Want to tell us what you need it for? Perhaps we can suggest a way of doing it that's appropriate in Python. Carl Banks Hi, First of all thanks all for answering! I have some environment check and setup in the beginning of the code. I would like to move it to the end of the script. But I want it to execute first, so the script will exit if the environment is not configured properly. Thanks, Alex. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class Inheritance
On Thu, 13 Mar 2008 00:06:52 -0500, Andrew Rekdal wrote: Problem is layout_ext and Layout code is dependant on a Class instance 'css'. Then pass that instance to the `Layout` class in the `__init__()` so both, the base class and the subclass use the same `CSS` instance. Ciao, Marc 'BlackJack' -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a file with $SIZE
[EMAIL PROTECTED] wrote: On Mar 12, 2:44 pm, Robert Bossy [EMAIL PROTECTED] wrote: Matt Nordhoff wrote: Robert Bossy wrote: k.i.n.g. wrote: I think I am not clear with my question, I am sorry. Here goes the exact requirement. We use dd command in Linux to create a file with of required size. In similar way, on windows I would like to use python to take the size of the file( 50MB, 1GB ) as input from user and create a uncompressed file of the size given by the user. ex: If user input is 50M, script should create 50Mb of blank or empty file def make_blank_file(path, size): f = open(path, 'w') f.seek(size - 1) f.write('\0') f.close() I'm not sure the f.seek() trick will work on all platforms, so you can: def make_blank_file(path, size): f = open(path, 'w') f.write('\0' * size) f.close() I point out that a 1 GB string is probably not a good idea. def make_blank_file(path, size): chunksize = 10485760 # 10 MB chunk = '\0' * chunksize left = size fh = open(path, 'wb') while left chunksize: fh.write(chunk) left -= chunksize if left 0: fh.write('\0' * left) fh.close() Indeed! Maybe the best choice for chunksize would be the file's buffer size... I won't search the doc how to get the file's buffer size because I'm too cool to use that function and prefer the seek() option since it's lighning fast regardless the size of the file and it takes near to zero memory. Cheers, RB But what platforms does it work on / not work on? Posix. It's been ages since I touched Windows, so I don't know if XP and Vista are posix or not. Though, as Marco Mariani mentioned, this may create a fragmented file. It may or may not be an hindrance depending on what you want to do with it, but the circumstances in which this is a problem are quite rare. RB -- http://mail.python.org/mailman/listinfo/python-list
Re: How to port Python code into C++ code automatically?
On Wed, 12 Mar 2008 20:15:32 -0700, Bo wrote: I want to port a Python project (about 10,000 line python code) to C+ +. Is there any automatically tool to do this kind of things? e.g., SWIG(http://www.swig.org/)? Any comment is welcome! Have a look at the ShedSkin Python-to-C++ compiler: http://shed-skin.blogspot.com/ It has some restrictions, i.e. the code has to be written in a more or less statically typed way. And me too is interested in why you want to port the entire project instead just the time critical parts? ShedSkin might help here too. As Cython_ or Pyrex_ do. Both compile a subset of Python with optional static typing to C extension modules. .. _Cython: http://www.cython.org/ .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: call by reference howto????
On 2008-02-28, Steven D'Aprano [EMAIL PROTECTED] wrote: On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote: Hi! Can somebody of you make me a sample how to define a function based on call by reference ??? Python doesn't do call by reference. Nor does it do call by value. Please pay no attention to anyone who says it does. Whatever python has for a calling convention, it is close enough that naming it call by reference gives people a reasonable idea of what is going on. Instead, read this: http://effbot.org/zone/call-by-object.htm Which IMO isn't very helpfull. The mentioning of e.g. mutable just confuses things since it really isn't the issue. AFAICS people don't have a problem with understanding the calling convention of python. They have a problem understanding the assignment semantics. It is just that these problems of understanding most often surface when an assignment is made to a parameter which makes them think they don't understand the calling convention. The important thing to understand is that an assigment in python is not copying the contends into the variable but is passing a reference/binding the name to a new object. After the variable is assigned to it doesn't refer to the same object with a new contend. It refers to a different object. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Class Inheritance
Andrew Rekdal a écrit : I am trying to bring functions to a class by inheritance... for instance in layout_ext I have.. --- layout_ext.py- class Layout() def...some function that rely on css in Layout.py It shouldn't, definitively. The Layout instance should have a reference on the CSS instance, ie: # layout_ext.py class LayoutExt(object): def __init__(self, css): self.css = css def some_function(self): do_something_with(self.css) # layout.py from layout_ext import LayoutExt from CSS import CSS class Layout(LayoutExt): def __init__(self, css): LayoutExt.__init__(self, css) # etc def... ---EOF-- in the main application file I have... Layout.py--- from layout_ext import Layout from CSS import CSS css = CSS() class Layout(Layout) You will have a problem here - this class statement will shadow the Layout class imported from layout_ext. Remember that in Python, def and class statements are executed at runtime and that they bind names in current namespace - here, the 'class Layout' statement rebinds the name 'Layout' in the Layout module's namespace. def __init__ more code. EOF Problem is layout_ext and Layout code is dependant on a Class instance 'css'. Whenever the CSS instance it parses a file, this means that I would have to parse the file twice?? Why is this? Can I do something like pass an already created instance to the import? Wrong solution, obviously. cf above for the most probably correct one. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: help please, splitter windows like in maya or 3ds max
On Mar 13, 12:47 pm, Andrew Rekdal nospam@comcast.net wrote: This seems to work... split then split each side. then tandem the size. import wx class Layout(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) sizer = wx.BoxSizer(wx.HORIZONTAL) panel = wx.Panel(self,-1) splitter = wx.SplitterWindow(panel) sizer_left = wx.BoxSizer(wx.VERTICAL) panel_left = wx.Panel(splitter,-1) splitter_left = wx.SplitterWindow(panel_left) splitter_left.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.leftChange,id=splitter_left.GetId()) panel_left_upper = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN) panel_left_upper.SetBackgroundColour(WHITE) panel_left_lower = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN) splitter_left.SplitHorizontally(panel_left_upper,panel_left_lower) sizer_left.Add(splitter_left,1,wx.EXPAND) sizer_right = wx.BoxSizer(wx.VERTICAL) panel_right = wx.Panel(splitter,-1) splitter_right =wx.SplitterWindow(panel_right) splitter_right.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.rightChange,id=splitter_right.GetId()) panel_right_upper = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN) panel_right_lower = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN) panel_right_lower.SetBackgroundColour(WHITE) splitter_right.SplitHorizontally(panel_right_upper,panel_right_lower) sizer_right.Add(splitter_right,1,wx.EXPAND) splitter.SplitVertically(panel_left,panel_right) sizer.Add(splitter,1,wx.EXPAND) panel.SetSizer(sizer) panel_left.SetSizer(sizer_left) panel_right.SetSizer(sizer_right) self.splitter_left = splitter_left self.splitter_right = splitter_right def leftChange(self,event): pos = self.splitter_left.GetSashPosition() self.splitter_right.SetSashPosition(pos) event.Skip() def rightChange(self,event): pos = self.splitter_right.GetSashPosition() self.splitter_left.SetSashPosition(pos) event.Skip() app = wx.App(0) k = Layout(None, -1, 'layout.py') k.Show(True) app.MainLoop() -- Andrew - Original Message - From: moonrie [EMAIL PROTECTED] Newsgroups: comp.lang.python Sent: Wednesday, March 12, 2008 10:19 PM Subject: help please, splitter windows like in maya or 3ds max hi, everyone there, I am doing a 3D modeling project. I like to do it with Python( am a newbie), but have no idea with the wxSplitterWindow to create the 4-view windows( top, front, side, perspective), like the mfc CSplitterWnd guy), anyone can give me some help with wxPython? thanks in advance. - moonrie should be these ones, thanks, :P -- http://mail.python.org/mailman/listinfo/python-list
List mutation method gotcha - How well known?
Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above I undertake to summarise answers posted to complete this survey. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: call by reference howto????
Antoon Pardon [EMAIL PROTECTED] writes: On 2008-02-28, Steven D'Aprano [EMAIL PROTECTED] wrote: On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote: Hi! Can somebody of you make me a sample how to define a function based on call by reference ??? Python doesn't do call by reference. Nor does it do call by value. Please pay no attention to anyone who says it does. Whatever python has for a calling convention, it is close enough that naming it call by reference gives people a reasonable idea of what is going on. Quite. The thing is not to get hung up with the label - but to understand what actually happens. -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 13, 8:36 am, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above I undertake to summarise answers posted to complete this survey. - Hendrik None is the likely answer as .append is an inplace change and will return None... -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Hendrik van Rooyen wrote: I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): I thought it were a FAQ, but found only http://effbot.org/pyfaq/why-doesn-t-list-sort-return-the-sorted-list.htm I'm sure you can draw the analogy. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 13, 9:36 am, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above I undertake to summarise answers posted to complete this survey. - Hendrik No output because x is a NoneType... -- http://mail.python.org/mailman/listinfo/python-list
Re: no more comparisons
Paul Rubin http://[EMAIL PROTECTED] wrote: Terry Reedy [EMAIL PROTECTED] writes: | I don't see what's so inefficient about it necessarily. The key function is called once per list item, for n calls total. The comparision function is called once per comparision. There are at least n-1 such calls and typically something on the order of n * lg2(n) calls. Right. Depending on the application, calling the comparison function lg(n) times may be faster than calling the key function once. Example: you want to sort a list of strings case-independently, each string containing a few pages worth of text. There are 1 strings, each maybe 1 chars long. Then (untested): x.sort(xs, key=lower) makes a copy of each of the 1 strings, makes 1 tuples, sorts, then releases the temporary strings and tuples. At least 100 megabytes of memory allocated and 100 million chars copied, even though any give pair of strings will usually differ somewhere in the first few characters and there's no need to look past those. Not tuples actually, there's a special sortwrapper type which is used. This is slightly better as it stops the comparison leaking through to the original values without having to store an index value. As Dan has pointed out, for those rare cases where it actually is better to use cmp than key you can easily create a wrapper. The only change is that you now have to work at using cmp instead of it being the first thing you think of. So here you could use his wrapper and your comparison function together: x.sort(key=cmp_key(xcmp)) I'd agree though that the comparison wrapper should be reasonably well publicised: I'd remembered that there was an easy way to implement cmp in terms of key but not what it was. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with Python 2.5.2 and gcc 4.3
David P. Riedel wrote: I tried building Python 2.5.2 using gcc 4.3.0. The build completes with no problems but when I run 'make test', I get a segfault part way through the test run. here is the last part of the output from make test test_softspace test_sort test_sqlite test_sqlite skipped -- no sqlite available test_startfile test_startfile skipped -- cannot import name startfile test_str make: *** [test] Segmentation fault You don't identify the platform or O/S, though I'd guess some Linux distro on i386 or x86-64... If you have gdb available, a backtrace might give a clue. However, as this is a new major release of gcc I'm automatically going to assume an optimisation issue. To test this I'd suggest doctoring the makefile generated by configure to reduce the optimisation level - I'd suggest trying -O instead of -O3. If that works, try -O2 or -Os. If -O2 or -Os works, I'd be taking the matter up with the gcc team. -- - Andrew I MacIntyre These thoughts are mine alone... E-mail: [EMAIL PROTECTED] (pref) | Snail: PO Box 370 [EMAIL PROTECTED] (alt) |Belconnen ACT 2616 Web:http://www.andymac.org/ |Australia -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Hendrik van Rooyen wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above I undertake to summarise answers posted to complete this survey. None, as python chose deliberately to return None on mutating functions like append, sort and reverse. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Hendrik van Rooyen [EMAIL PROTECTED] writes: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 4) Nothing - no output By Python convention, methods that mutate the object return None, and also stuff that returns None doesn't generate output at the interactive prompt. There is a similar situation with list.sort() which led to the introduction of the sorted() builtin. Lately I try to avoid mutation, e.g. by using a generator or listcomp instead of building up a list with .append() -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Hendrik van Rooyen a écrit : Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above answer 5 - list.append returns None, which when printed gives 'None'. You'll get the same thing with list.sort, list.extend, list.reverse etc... -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Hendrik van Rooyen schreef: So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above Answer 5: the output will be 'None': append() doesn't return the list, it returns None. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Paul Rubin http://[EMAIL PROTECTED] writes: Hendrik van Rooyen [EMAIL PROTECTED] writes: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 4) Nothing - no output Correction, it will print None, there is an explicit print statement that went past me. I'm sleepy. -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Still, I suppose this is a gotcha for a lot of people, just follow the good advice Paul said; By Python convention, methods that mutate the object return None, and also stuff that returns None doesn't generate output at the interactive prompt. And you should survive most. -- http://mail.python.org/mailman/listinfo/python-list
What's Going On?
(Accompanied by Marvin Gaye) def f(list=[0]): ...list[0]+=1 ...return list[0] ... f() 1 f() 2 f() # 'list' is a name bound to a list (mutable) so this makes sense 3 f([5]) 6 f() # What's Going On? 4 Off topic: Motown chief Berry Gordy tells Gaye he won't release the uncommercial song. Gaye tells Gordy he'll never have another Gaye song if he doesn't release it. Gordy backs down. 2.5 million singles plus title track for blockbuster album. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
Alex a écrit : (sni) First of all thanks all for answering! I have some environment check and setup in the beginning of the code. I would like to move it to the end of the script. Why ? (if I may ask...) But I want it to execute first, so the script will exit if the environment is not configured properly. If you want some code to execute first when the script/module is loaded, then keep this code where it belongs : at the beginning of the script. -- http://mail.python.org/mailman/listinfo/python-list
Re: What's Going On?
[EMAIL PROTECTED] wrote: (Accompanied by Marvin Gaye) def f(list=[0]): ...list[0]+=1 ...return list[0] ... f() 1 f() 2 f() # 'list' is a name bound to a list (mutable) so this makes sense 3 f([5]) 6 f() # What's Going On? 4 http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm You heard it through the grapevine ;) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: What's Going On?
[EMAIL PROTECTED] wrote: (Accompanied by Marvin Gaye) def f(list=[0]): ...list[0]+=1 ...return list[0] ... f() 1 f() 2 f() # 'list' is a name bound to a list (mutable) so this makes sense 3 f([5]) 6 f() # What's Going On? 4 That the same default argument is mutated? What did you expect, that it got replaced by you passing another list? That would kind of defy the meaning of default-arguments, replacing them whenever you call a function with actual parameters. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: help please, splitter windows like in maya or 3ds max
Sounds like this might do exactly what you need... http://xoomer.alice.it/infinity77/main/FourWaySplitter.html Cheers, John On Thu, Mar 13, 2008 at 1:45 AM, moonrie [EMAIL PROTECTED] wrote: On Mar 13, 12:47 pm, Andrew Rekdal nospam@comcast.net wrote: This seems to work... split then split each side. then tandem the size. import wx class Layout(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) sizer = wx.BoxSizer(wx.HORIZONTAL) panel = wx.Panel(self,-1) splitter = wx.SplitterWindow(panel) sizer_left = wx.BoxSizer(wx.VERTICAL) panel_left = wx.Panel(splitter,-1) splitter_left = wx.SplitterWindow(panel_left) splitter_left.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.leftChange ,id=splitter_left.GetId()) panel_left_upper = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN) panel_left_upper.SetBackgroundColour(WHITE) panel_left_lower = wx.Panel(splitter_left,style= wx.BORDER_SUNKEN) splitter_left.SplitHorizontally(panel_left_upper,panel_left_lower) sizer_left.Add(splitter_left,1,wx.EXPAND) sizer_right = wx.BoxSizer(wx.VERTICAL) panel_right = wx.Panel(splitter,-1) splitter_right =wx.SplitterWindow(panel_right) splitter_right.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED,self.rightChange ,id=splitter_right.GetId()) panel_right_upper = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN) panel_right_lower = wx.Panel(splitter_right,style= wx.BORDER_SUNKEN) panel_right_lower.SetBackgroundColour(WHITE) splitter_right.SplitHorizontally(panel_right_upper,panel_right_lower) sizer_right.Add(splitter_right,1,wx.EXPAND) splitter.SplitVertically(panel_left,panel_right) sizer.Add(splitter,1,wx.EXPAND) panel.SetSizer(sizer) panel_left.SetSizer(sizer_left) panel_right.SetSizer(sizer_right) self.splitter_left = splitter_left self.splitter_right = splitter_right def leftChange(self,event): pos = self.splitter_left.GetSashPosition() self.splitter_right.SetSashPosition(pos) event.Skip() def rightChange(self,event): pos = self.splitter_right.GetSashPosition() self.splitter_left.SetSashPosition(pos) event.Skip() app = wx.App(0) k = Layout(None, -1, 'layout.py') k.Show(True) app.MainLoop() -- Andrew - Original Message - From: moonrie [EMAIL PROTECTED] Newsgroups: comp.lang.python Sent: Wednesday, March 12, 2008 10:19 PM Subject: help please, splitter windows like in maya or 3ds max hi, everyone there, I am doing a 3D modeling project. I like to do it with Python( am a newbie), but have no idea with the wxSplitterWindow to create the 4-view windows( top, front, side, perspective), like the mfc CSplitterWnd guy), anyone can give me some help with wxPython? thanks in advance. - moonrie should be these ones, thanks, :P -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
How to send a var to stdin of an external software
Hi the list, I need to send a var to stdin of an external soft (cat command for example). How can I do this ? I would like a function like that : theFunction ('cat -', stdin=myVar) I don't need to get any return value. Another related question : Is there's a limitation of var size ? I would have var up to 10 MB. Thanks ! Ben -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen pipeline bug?
This tiny program hangs: #!/usr/bin/env python import subprocess a = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE, stdout = subprocess.PIPE) b = subprocess.Popen('cat /dev/null',shell = True,stdin = a.stdout) a.stdin.close() b.wait() # hangs a.wait() # never reached It shouldn't, should it? Environment: Python 2.5.1 (r251:54863, Jun 20 2007, 12:14:09) [GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2 Marko -- Marko Rauhamaa mailto:[EMAIL PROTECTED] http://pacujo.net/marko/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send a var to stdin of an external software
Benjamin Watine [EMAIL PROTECTED]: How can I do this ? I would like a function like that : theFunction ('cat -', stdin=myVar) Another related question : Is there's a limitation of var size ? I would have var up to 10 MB. import subprocess myVar = '*' * 1000 cat = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE) cat.stdin.write(myVar) cat.stdin.close() cat.wait() Marko -- Marko Rauhamaa mailto:[EMAIL PROTECTED] http://pacujo.net/marko/ -- http://mail.python.org/mailman/listinfo/python-list
Diary of a Stripper.
Hi, my name is Michelle, I'm 27, just left being a secretary to become a stripper, and looking for friends to talk to. I love meeting new people! I also have a blog where I talk about my life... http://missxxy.blogspot.com Talk to you soon! Michelle -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 13, 2:36 am, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above 5. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with Python 2.5.2 and gcc 4.3
Andrew MacIntyre wrote: David P. Riedel wrote: I tried building Python 2.5.2 using gcc 4.3.0. The build completes with no problems but when I run 'make test', I get a segfault part way through the test run. here is the last part of the output from make test test_softspace test_sort test_sqlite test_sqlite skipped -- no sqlite available test_startfile test_startfile skipped -- cannot import name startfile test_str make: *** [test] Segmentation fault You don't identify the platform or O/S, though I'd guess some Linux distro on i386 or x86-64... If you have gdb available, a backtrace might give a clue. However, as this is a new major release of gcc I'm automatically going to assume an optimisation issue. To test this I'd suggest doctoring the makefile generated by configure to reduce the optimisation level - I'd suggest trying -O instead of -O3. If that works, try -O2 or -Os. If -O2 or -Os works, I'd be taking the matter up with the gcc team. You are correct -- Mandriva Linux 2007. I will try varying the optimization level and see what happens. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Dispatch(Excel.Application) failed
On Mar 13, 1:02 am, lialie [EMAIL PROTECTED] wrote: Hi, Maybe it 's quite simple, but I can't fix it. Do I make some mistakes in my env setting? My excel version is 2003. any suggestion? Thanks. Traceback (most recent call last): File testexcel.py, line 3, in ? excel = Dispatch(Excel.Application) File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c lsctx) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 98, in _ GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 78, in _ GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II D_IDispatch) pywintypes.com_error: (-2147221005, '\xce\xde\xd0\xa7\xb5\xc4\xc0\xe0\xb1\xf0\xd7\xd6\xb7\xfb\xb4\xae', None, None) I'm not seeing anything obviously wrong. What version of Windows are you using? Are you logged in as an admin? You also might try the PyWin32 user's mailing list: http://mail.python.org/mailman/listinfo/python-win32 Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Different results when running script from IDLE versus Command Line
On Mar 12, 5:28 pm, Chris [EMAIL PROTECTED] wrote: On Mar 12, 8:10 pm, Casey T [EMAIL PROTECTED] wrote: Hi, I'm new to Python and I'm having some problems with getting different results from my script when I run it from IDLE versus just double- clicking the .py file and having it run through the command line. Basically, my script reads some CSV files, assembles a text files, then uploads that test file to an ftp site. When I run the script from IDLE, everything works fine. But when it runs from the command line, the file that gets uploaded is empty. It seems that it is creating a new file to upload, rather than using the existing file (or at least that's what I think is going on.) Below is my script. I apologize for any ugly code. Thanks for your help. import sys,os,linecache,csv,ftplib,time starttime = time.time() #*** #Summary file assembling #*** currentdir = //folder/ reg_sum = open('reg_sum.txt','w') reg_sum.close for files in os.listdir(currentdir): reg_file = csv.reader(open(currentdir + files)) for row in reg_file: reg_sum = open('reg_sum.txt','a') reg_sum.write(,.join(row) + ',\n') reg_sum.close #*** #Summary file processing #*** coordList = [ [F10,40.0053,-75.0927], [T10,40.0272,-75.1123], [D22,39.9811,-75.0998], [P02,40.0437,-75.0217], [D68,39.9203,-75.1388], [D51,39.9534,-75.1405], [S43,39.9217,-75.2275], [S33,39.9360,-75.2077], [S42A,39.9215,-75.1937], [S05,39.9617,-75.1782], [T14,40.0165,-75.1077]] coordList_index = [F10,T10,D22,P02,D68,D51,S43,S33,S42A,S05,T14] #coordList_index is a list containing in_text = open('reg_sum.txt','r') out_text = open('reg_out.txt','w') out_text.close out_text = open('reg_out.txt','a') for line in in_text: split_line = line.split(',') if (split_line[0]) in coordList_index: i = coordList_index.index(split_line[0]) coords = str(coordList[i][1]) + , + str(coordList[i][2]) last_update = str(split_line[2]) print str(split_line[0]) if split_line[1] == 1: out_text.write(split_line[0] + br,Test1: + last_update + , + coords + ,1 + \n) elif split_line[1] == 0: out_text.write(split_line[0] + br,Test2.brLast updated: + last_update + , + coords + ,0 + \n) else: out_text.write(split_line[0] + br,No data., + coords + \n) in_text.close ###*** ###Uploads file via FTP ###*** s = ftplib.FTP('ftp.blah123.org,'user','pass') f.open('reg_out.txt','r') s.storlines('STOR reg_out.txt', f) f.close() s.quit() print Processed in + str(((time.time() - starttime) / 60) *60) + seconds! #prints elapsed time You never closed your file. file_object.close built-in method close of file object at 0x00BA6CC8 try adding '()' at the end of your close calls. As to why it differs, I can't think offhand why it wouldn't. wow. thank you so much. it was the '()'. I now get consistent results. In all the sample code I saw, I never saw the '()' after close. thanks again - casey -- http://mail.python.org/mailman/listinfo/python-list
Re: Python - CGI - XML - XSD
Sorry, it was really late when i wrote this post. The file is an XSL file. It defines HTML depending on what appears in the XML document. Then the content-type might be the culprit, yes. But testing so would have been faster than waiting for answers here... Diez -- http://mail.python.org/mailman/listinfo/python-list
RE: Socket Performance
[EMAIL PROTECTED] wrote: Sent: Wednesday, March 12, 2008 9:47 PM To: python-list@python.org Subject: Socket Performance Can anyone explain why socket performance (throughput) varies depending on the amount of data send and recv are called with? For example: try creating a local client/server (running on the same computer) where the server sends the client a fixed amount of data. Using method A, recv(8192) and sendall( ) with 8192 bytes worth of data. Do this 100 times. Using method B, recv(1) and sendall( ) with 1 byte worth of data. Do this 819200 times. If you time both methods, method A has much greater throughput than method B. Why is it faster to drink a liter of water a cupful at a time than to drink it out of an eyedropper? - Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with subprocess in threaded enviroment
On Mar 12, 12:58 pm, Ningyu Shi [EMAIL PROTECTED] wrote: I'm trying to write a multi-task downloader to download files from a website using multi-threading. I have one thread to analyze the webpage, get the addresses of the files to be downloaded and put these in a Queue. Then the main thread will start some threads to get the address from the queue and download it. To keep the maximum files downloaded concurrently, I use a semaphore to control this, like at most 5 downloads at same time. You don't need a semaphore for that. Semaphores are low-level and very hard to get right. (Read http://www.greenteapress.com/semaphores/ if you don't believe me.) You don't need any other type of explicit lock either. Just use Queues. Queues are much easier. Make simple threads, each of which typically reads from one queue and writes to one queue. If you want N-way concurrency at one stage, start N instances of that thread. If you need to guarantee non-concurrency at some stage, make that thread a singleton. Avoid sharing mutable data across threads except through Queues. I tried to use urllib.urlretreive in the download() thread, but from time to time, it seems that one download thread may freeze the whole program. Then I gave up and use subprocess to call wget to do the job. My download thread is like this: def download( url ): subprocess.call([wget, -q, url]) with print_lock: print url, 'finished.' semaphore.realease() If the prints are just for debugging, print_lock is overkill. And in practice that print statement is probably atomic in CPython because of the GIL. But let's assume that it really is critical not to mix the output streams, and that the print isn't necessarily atomic. So instead of the lock, use a print_queue and a single PrintThread that just pulls strings off the queue and prints them. But later I found that after the specific wget job finished downloading, that download() thread never reach the print url statement. So I end up with files been downloaded, but the download() thread never ends and don't realease the semaphore then block the whole program. My guess is that at the time wget process ends, that specific download thread is not active and missed the return of the call. The fact that changing libraries didn't fix your problem is a strong indicator that it's your code, not the libraries. You're probably introducing deadlocks with your semaphores. Too much locking is as bad as too little. Here's the skeleton of how I'd write this program: main thread: create queues, create and start other threads, find URLs, put URLs on input_queue class DownloadThread(threading.Thread): def run(self): while True: url = input_queue.get() urllib.urlretrieve(url) print_queue.put(done with %s % url) class PrintThread(threading.Thread): def run(self): while True: st = print_queue.get() print st Then you just have to worry about clean shutdown. A simple way to handle this to initialize a counter to the number of URLs in main, and decrement it in PrintThread. Then have main busy-wait (with a sleep to avoid consuming too much CPU) for it to hit zero, then join all the other threads and exit. (This seems to violate the no-shared-mutable- data rule, but only one thread at a time can mutate it, so it's safe.) Once you've done this manually, consider using the TaskQueue recipe on the Python Cookbook site, to simplify it a bit. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send a var to stdin of an external software
Benjamin Watine [EMAIL PROTECTED] wrote: How can I do this ? I would like a function like that : theFunction ('cat -', stdin=myVar) I don't need to get any return value. http://docs.python.org/lib/node534.html says this is spelt myVar = subprocess.Popen([cat, -], stdout=subprocess.PIPE).communicate()[0] (Probably not obvious how to find this if you've not come across the backtick notation in shell or Perl.) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
wx and pil conversion
A little problem. Can I directly show Pil objects image.open(bla.jpg) in Wx or do I have to transform them. If I have to transofm them How can I do it. Pixel by pixel or is there somethin built in in pil or wx or python. pilj-wx and wx-pil. -- http://mail.python.org/mailman/listinfo/python-list
Re: Get cgi script to begin execution of another script...
sophie_newbie [EMAIL PROTECTED] wrote: Basically I've a CGI script, that when executed by the user, I want to call another script that does a very long running task (10 hours +) and print a message on the screen saying that the user will be emailed on completion of the very long task. The script executing the very long task will then email the user on completion. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 was helpful to me in solving this problem. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
(off-topic) JS/DHTML export to XLS format?
Anyone use/know of anything looks like a spreadsheet, lives in a web-browser and can export to XLS format? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send a var to stdin of an external software
Marko Rauhamaa a écrit : Benjamin Watine [EMAIL PROTECTED]: How can I do this ? I would like a function like that : theFunction ('cat -', stdin=myVar) Another related question : Is there's a limitation of var size ? I would have var up to 10 MB. import subprocess myVar = '*' * 1000 cat = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE) cat.stdin.write(myVar) cat.stdin.close() cat.wait() Marko Thank you Marko, it's exactly what I need. And if somebody need it : to get the stdout in a var (myNewVar), not in the shell : cat = subprocess.Popen('cat', shell = True, stdin = subprocess.PIPE, stdout=subprocess.PIPE) cat.stdin.write(myVar) cat.stdin.close() cat.wait() myNewVar = cat.stdout.read() Is it correct ? Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Thu, Mar 13, 2008 at 8:36 AM, Hendrik van Rooyen [EMAIL PROTECTED] wrote: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above 5 -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Attribute Doesnt Exist ... but.... it does :-s
Hello Guys, I've got an awfully aggravating problem which is causing some substantial hair loss this afternoon J I want to get your ideas on this. I am trying to invoke a particular method in one of my classes, and I'm getting a runtime error which is telling me the attribute does not exist. I'm calling the method from within __init__ yet it still seems to think it doesn't exist. Code: # Define the RemoteDevice class. class remote_device: # I'm the class constructor method. def __init__(self, message_list=): self.set_pending_list(message_list) def set_pending_list(self, pending_list): # Set the message list property. self.pending_list = message_list And the error message which I receive during the instantiation of the class: File: /path/to/my/files/remote_device.py, line 22, in __init__ self.set_pending_list(message_list) AttributeError: remote_device instance has no attribute 'set_pending_list' Does anyone have the slightest idea why this might be happening? I can see that the code DOES have that method in it, I also know that I don't get any compile time errors so that should be fine. I know it mentions line 22 in the error, but I've chopped out a load of non relevant code for the sake of posting here. Perhaps I'm missing something really simple, but it's got my head spinning. Thanks, Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Attribute Doesnt Exist ... but.... it does :-s
On Thu, Mar 13, 2008 at 10:36 AM, Robert Rawlins [EMAIL PROTECTED] wrote: Hello Guys, I've got an awfully aggravating problem which is causing some substantial hair loss this afternoon J I want to get your ideas on this. I am trying to invoke a particular method in one of my classes, and I'm getting a runtime error which is telling me the attribute does not exist. I'm calling the method from within __init__ yet it still seems to think it doesn't exist. Code: # Define the RemoteDevice class. class remote_device: # I'm the class constructor method. def __init__(self, message_list=): self.set_pending_list(message_list) def set_pending_list(self, pending_list): # Set the message list property. self.pending_list = message_list And the error message which I receive during the instantiation of the class: File: /path/to/my/files/remote_device.py, line 22, in __init__ self.set_pending_list(message_list) AttributeError: remote_device instance has no attribute 'set_pending_list' Does anyone have the slightest idea why this might be happening? I can see that the code DOES have that method in it, I also know that I don't get any compile time errors so that should be fine. I know it mentions line 22 in the error, but I've chopped out a load of non relevant code for the sake of posting here. Perhaps I'm missing something really simple, but it's got my head spinning. Create a copy of your source file, confirm that it shows the problem, and start chopping out lines until all that is left is what you pasted here. See if it still shows the problem. If it does, and if you haven't found the problem yet, post again, attaching (not pasting inline) your chopped down file. -- http://mail.python.org/mailman/listinfo/python-list
scons Buffer.cpp
I am trying to install some libs but can not get them build properly. It seems to be looking for Buffer.cpp but can't find it any where . Here is the error message: scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o AssociationRejection.o -c -I/usr/lib -I/usr/lib/boost AssociationRejection.cpp g++ -o Buffer.o -c -I/usr/lib -I/usr/lib/boost Buffer.cpp In file included from Buffer.cpp:1: Buffer.hpp:9:27: error: socket/Base.hpp: No such file or directory Buffer.hpp:10:35: error: socket/SwitchEndian.hpp: No such file or directory Buffer.hpp: In member function 'dicom::Buffer dicom::Buffer::operator(T)': Buffer.hpp:84: error: 'is_fundamental' is not a member of 'boost' Buffer.hpp:84: error: '::value' has not been declared Buffer.hpp:90: error: template argument 1 is invalid Buffer.hpp:95: error: template argument 1 is invalid Buffer.hpp:96: error: expected unqualified-id before '}' token Buffer.hpp: In member function 'dicom::Buffer dicom::Buffer::operator(T)': Buffer.hpp:103: error: 'is_const' is not a member of 'boost' Buffer.hpp:103: error: '::value' has not been declared Buffer.hpp:104: error: template argument 1 is invalid Buffer.hpp:105: error: template argument 1 is invalid Buffer.hpp:105: error: invalid type in declaration before ';' token Buffer.hpp:105: error: declaration of 'typedef int data' shadows a parameter Buffer.hpp:109: error: 'pdata' was not declared in this scope Buffer.hpp:117: error: expected unqualified-id before '=' token Buffer.cpp: In member function 'dicom::Buffer dicom::Buffer::operator(std::vectorshort unsigned int, std::allocatorshort unsigned int )': Buffer.cpp:38: error: 'SwitchVectorEndian' was not declared in this scope Buffer.cpp: In member function 'void dicom::Buffer::AddVector(const std::vectorshort unsigned int, std::allocatorshort unsigned int )': Buffer.cpp:112: error: 'SwitchVectorEndian' was not declared in this scope Buffer.hpp: In member function 'dicom::Buffer dicom::Buffer::operator(T) [with T = char]': Buffer.cpp:51: instantiated from here Buffer.hpp:105: error: declaration of 'typedef int data' shadows a parameter Buffer.hpp: In member function 'dicom::Buffer dicom::Buffer::operator(T) [with T = UINT16]': Buffer.cpp:59: instantiated from here Buffer.hpp:105: error: declaration of 'typedef int data' shadows a parameter scons: *** [Buffer.o] Error 1 scons: building terminated because of errors. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attribute Doesnt Exist ... but.... it does :-s
Robert Rawlins wrote: Hello Guys, I’ve got an awfully aggravating problem which is causing some substantial hair loss this afternoon J I want to get your ideas on this. I am trying to invoke a particular method in one of my classes, and I’m getting a runtime error which is telling me the attribute does not exist. I’m calling the method from within __init__ yet it still seems to think it doesn’t exist. Code: # Define the RemoteDevice class. class *remote_device*: # I'm the class constructor method. def *__init__*(/self/, message_list=//): /self/.set_pending_list(message_list) def *set_pending_list*(/self/, pending_list): # Set the message list property. /self/.pending_list = message_list And the error message which I receive during the instantiation of the class: File: “/path/to/my/files/remote_device.py, line 22, in __init__ self.set_pending_list(message_list) AttributeError: remote_device instance has no attribute 'set_pending_list' Does anyone have the slightest idea why this might be happening? I can see that the code DOES have that method in it, I also know that I don’t get any compile time errors so that should be fine. I know it mentions line 22 in the error, but I’ve chopped out a load of non relevant code for the sake of posting here. Hi, I don't get this error if I run your code. Maybe the irrelevant code causes the error: my guess is that there's a parenthesis mismatch or an undeindented line. Btw, calls to set_pending_list will fail since the name message_list is not defined in its scope. Please follow Chris Mellon's advice. Cheers, RB -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a file with $SIZE
k.i.n.g. wrote: I think I am not clear with my question, I am sorry. Here goes the exact requirement. We use dd command in Linux to create a file with of required size. In similar way, on windows I would like to use python to take the size of the file( 50MB, 1GB ) as input from user and create a uncompressed file of the size given by the user. ex: If user input is 50M, script should create 50Mb of blank or empty file You mean all zero bytes? Python cannot guarantee that the system will not compress such a file. For testing data transfer rates, random data is a usually a better choice. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
RE: Attribute Doesnt Exist ... but.... it does :-s
Hi Guys, Well thanks for the response, I followed your advice and chopped out all the crap from my class, right down to the bare __init__ and the setter method, however, the problem continued to persist. However, Robert mentioned something about unindented lines which got me thinking so I deleted my tab indents on that method and replaces them with standard space-bar indents and it appears to have cured the problem. Usually my Eclipse IDE throws up an error about this but for some reason decided not too this time around, what a PITA. Thanks for the ideas guys, I appreciate it. Robert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Bossy Sent: 13 March 2008 15:51 To: python-list@python.org Subject: Re: Attribute Doesnt Exist ... but it does :-s Robert Rawlins wrote: Hello Guys, I've got an awfully aggravating problem which is causing some substantial hair loss this afternoon J I want to get your ideas on this. I am trying to invoke a particular method in one of my classes, and I'm getting a runtime error which is telling me the attribute does not exist. I'm calling the method from within __init__ yet it still seems to think it doesn't exist. Code: # Define the RemoteDevice class. class *remote_device*: # I'm the class constructor method. def *__init__*(/self/, message_list=//): /self/.set_pending_list(message_list) def *set_pending_list*(/self/, pending_list): # Set the message list property. /self/.pending_list = message_list And the error message which I receive during the instantiation of the class: File: /path/to/my/files/remote_device.py, line 22, in __init__ self.set_pending_list(message_list) AttributeError: remote_device instance has no attribute 'set_pending_list' Does anyone have the slightest idea why this might be happening? I can see that the code DOES have that method in it, I also know that I don't get any compile time errors so that should be fine. I know it mentions line 22 in the error, but I've chopped out a load of non relevant code for the sake of posting here. Hi, I don't get this error if I run your code. Maybe the irrelevant code causes the error: my guess is that there's a parenthesis mismatch or an undeindented line. Btw, calls to set_pending_list will fail since the name message_list is not defined in its scope. Please follow Chris Mellon's advice. Cheers, RB -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: What's Going On?
On Mar 13, 6:12 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: (Accompanied by Marvin Gaye) def f(list=[0]): ...list[0]+=1 ...return list[0] ... f() 1 f() 2 f() # 'list' is a name bound to a list (mutable) so this makes sense 3 f([5]) 6 f() # What's Going On? 4 That the same default argument is mutated? What did you expect, that it got replaced by you passing another list? That would kind of defy the meaning of default-arguments, replacing them whenever you call a function with actual parameters. f( ite, itr= ite.__iter__ ). Case 1: 'ite' is bound in outer scope. Case 2: not. function(code, globals[, name[, argdefs[, closure]]]) The optional argdefs tuple specifies the default argument values. TypeError: __defaults__ must be set to a tuple object import functools def k(): ... print( 'k call' ) ... class GT: ... def __init__( self, arg ): ... self._arg= arg ... def latebound( fun ): ... @functools.wraps( fun ) ... def post( *ar ): ... lar= list( fun.__defaults__ ) ... for i, a in enumerate( lar ): ... if isinstance( lar[ i ], GT ): ... lar[ i ]= eval( a._arg) ... return fun( *( list( ar )+ lar ) ) ... return post ... @latebound ... def f( ite, itr= GT('k()') ): ... return itr ... f( 2 ) k call f( 2 ) k call f( 2 ) k call Furthermore, ... @latebound ... def f( ite, itr= GT('ar[0]+ 1') ): ... return itr ... f( 2 ) 3 f( 2 ) 3 f( 2 ) 3 Unfortunately, ... @latebound ... def f( ite, itr= GT('ite+ 1') ): ... return itr ... f( 2 ) Traceback (most recent call last): File stdin, line 1, in module File stdin, line 7, in post File string, line 1, in module NameError: name 'ite' is not defined The moral of the story is, wouldn't it be nice if wrappers could access the post-invocation bindings of the wrappee's internal variables? Certainly the 'TypeError: __defaults__ must be set to a tuple object' is unnecessarily restrictive: let it be a mutable, or, if it's not a tuple, call it. Just add a __call__ method to that tuple that does nothing, if a type-test isn't faster-- perhaps even a null __call__ which does -actually- nothing. (Why is __defaults__ None when empty, not an empty tuple?) What are the use case proportions of function-static vs. call-time evaluation? Function-static is nice in that it keeps objects floating around with the function, both in information design, and in encapsulation. They both have easy workarounds: import functools def auto( fun ): ... @functools.wraps( fun ) ... def post( *ar ): ... return fun( post, *ar ) ... return post ... @auto ... def f( self ): ... print( self.ite ) ... f.ite= [] f() [] f.ite.append( 2 ) f() [2] @auto adds the binding function to its called parameter list, which is nice if the function will change names ever-- that is, become bound to other variables-- because its statics still stay with it, and because it's not a global either. g= f del f g() Traceback (most recent call last): File stdin, line 1, in module File stdin, line 4, in post File stdin, line 3, in f NameError: global name 'f' is not defined But on the other hand, if the Python community on the whole wants to keep the status quo, def f( ite, itr= None ): ... if None is itr: ... itr= ite+ 1 ... return itr ... f( 2 ) 3 f( 2 ) 3 f( 2 ) 3 isn't so bad. (If you think it is, lobby!) @latebound is a good compromise. It keeps the information in the right place, but takes a little redundancy if the evalled expression refers to another variable, and but costs the additional GT class, and adds an O( n ) argument-length boilerplate rearrangement. @auto frees us to allow a different behavior to default parameters while keeping both statics and call-times explicit, keeping the information in the right place, but it's a change in the language. Lastly, we have: @late( itr= 'ite+ 1' ) ... def f( ite, itr= latearg, j= 0 ): ... return itr, j ... print( f( 2 ) ) (3, 0) Proof of concept: import functools latearg= object() def late( **kw ): def pre( fun ): _defs= fun.__defaults__ if None is _defs: _defs= () _names= fun.__code__.co_varnames _deflen= len( _defs ) _namelen= fun.__code__.co_argcount for k in kw: if k not in _names: raise TypeError( 'Non-parameter' ' keyword \'%s\' in \'late\'' ' call.'% k ) print( _defs ) print( _names ) print( _deflen ) for a, b in zip( _names[ -_deflen: ], _defs ): if b is latearg and a not in kw: raise TypeError( 'Non-bound' ' latearg \'%s\' in \'late\'' ' call.'% k ) @functools.wraps( fun ) def post( *ar ): _arglen= len( ar )
Re: wx and pil conversion
azrael wrote: A little problem. Can I directly show Pil objects image.open(bla.jpg) in Wx or do I have to transform them. If I have to transofm them How can I do it. Pixel by pixel or is there somethin built in in pil or wx or python. pilj-wx and wx-pil. PIL doesn't depend on wx, so if anything then wx knows about PIL. But I doubt it. Instead, use cStringIO and save a PIL-Image to memory, then use that as file-argument to something that works for wx - no idea what, but there should be means to load JPEGs and so forth. If file-objects aren't enough, create a temp-file. No, that's not to slow. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attribute Doesnt Exist ... but.... it does :-s
2008/3/13, Robert Rawlins [EMAIL PROTECTED]: Hi Guys, Well thanks for the response, I followed your advice and chopped out all the crap from my class, right down to the bare __init__ and the setter method, however, the problem continued to persist. However, Robert mentioned something about unindented lines which got me thinking so I deleted my tab indents on that method and replaces them with standard space-bar indents and it appears to have cured the problem. Usually my Eclipse IDE throws up an error about this but for some reason decided not too this time around, what a PITA. Thanks for the ideas guys, I appreciate it. Robert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] ] On Behalf Of Robert Bossy Sent: 13 March 2008 15:51 To: python-list@python.org Subject: Re: Attribute Doesnt Exist ... but it does :-s Robert Rawlins wrote: Hello Guys, I've got an awfully aggravating problem which is causing some substantial hair loss this afternoon J I want to get your ideas on this. I am trying to invoke a particular method in one of my classes, and I'm getting a runtime error which is telling me the attribute does not exist. I'm calling the method from within __init__ yet it still seems to think it doesn't exist. Code: # Define the RemoteDevice class. class *remote_device*: # I'm the class constructor method. def *__init__*(/self/, message_list=//): /self/.set_pending_list(message_list) def *set_pending_list*(/self/, pending_list): # Set the message list property. /self/.pending_list = message_list And the error message which I receive during the instantiation of the class: File: /path/to/my/files/remote_device.py, line 22, in __init__ self.set_pending_list(message_list) AttributeError: remote_device instance has no attribute 'set_pending_list' Does anyone have the slightest idea why this might be happening? I can see that the code DOES have that method in it, I also know that I don't get any compile time errors so that should be fine. I know it mentions line 22 in the error, but I've chopped out a load of non relevant code for the sake of posting here. Hi, I don't get this error if I run your code. Maybe the irrelevant code causes the error: my guess is that there's a parenthesis mismatch or an undeindented line. Btw, calls to set_pending_list will fail since the name message_list is not defined in its scope. Please follow Chris Mellon's advice. Cheers, RB -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list All the more reason to use VIM and set it to auto-indent / remove 4 spaces with tab backspace. =) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
On Mar 13, 7:02 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Alex a écrit : (sni) First of all thanks all for answering! I have some environment check and setup in the beginning of the code. I would like to move it to the end of the script. Why ? (if I may ask...) But I want it to execute first, so the script will exit if the environment is not configured properly. If you want some code to execute first when the script/module is loaded, then keep this code where it belongs : at the beginning of the script. I concur with Bruno's recommendation: stuff you want to do first should come first in the script. Things like BEGIN blocks hurt readability because you can't identify where execution begins without reading the whole file. Having said that, one thing that often happens in Python scripts is that all the functions are defined first, then the script logic follows. So you could put the meat of your script in a function, then the BEGIN stuff after that functions: def run_script(): # # script contained in this long function # # Then test preconditions here... if os.environ[HELLO] != WORLD: sys.exit(2) # Then call the run_script functions run_script() But having said THAT, I don't recommend you do that with preconditions. If the script has a quick early exit scenario, you really ought to put that near the top, before the function definitions, to clearly show to a human reader what is necessary to run the script. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Attribute Doesnt Exist ... but.... it does :-s
Robert Rawlins wrote: Hi Guys, Well thanks for the response, I followed your advice and chopped out all the crap from my class, right down to the bare __init__ and the setter method, however, the problem continued to persist. However, Robert mentioned something about unindented lines which got me thinking so I deleted my tab indents on that method and replaces them with standard space-bar indents and it appears to have cured the problem. Aha! Killed the bug at the first guess! You owe me a beer, mate. RB -- http://mail.python.org/mailman/listinfo/python-list
Re: wx and pil conversion
I thought of using Temp files but I am afraid of the JPG destorsion while saving because of the compresion.I am looking for a way to directly transform it. On Mar 13, 5:09 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: azrael wrote: A little problem. Can I directly show Pil objects image.open(bla.jpg) in Wx or do I have to transform them. If I have to transofm them How can I do it. Pixel by pixel or is there somethin built in in pil or wx or python. pilj-wx and wx-pil. PIL doesn't depend on wx, so if anything then wx knows about PIL. But I doubt it. Instead, use cStringIO and save a PIL-Image to memory, then use that as file-argument to something that works for wx - no idea what, but there should be means to load JPEGs and so forth. If file-objects aren't enough, create a temp-file. No, that's not to slow. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send a var to stdin of an external software
Benjamin Watine wrote: And if somebody need it : to get the stdout in a var (myNewVar), not in the shell : cat = subprocess.Popen('cat', shell = True, stdin = subprocess.PIPE, stdout=subprocess.PIPE) cat.stdin.write(myVar) cat.stdin.close() cat.wait() myNewVar = cat.stdout.read() Is it correct ? No, not really. It is prone to deadlock. The external program might work by iteratively reading a little input and writing a little output, as 'cat' almost surely does. If the size of myVar exceeds the buffer space in cat and the pipes, you get stuck. Your Python program can block at cat.stdin.write(myVar), waiting for cat to read from its input pipe, while cat blocks at a write to its output stream, waiting for you to start reading and freeing up buffer space. Pipe loops are tricky business. Popular solutions are to make either the input or output stream a disk file, or to create another thread (or process) to be an active reader or writer. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: no more comparisons
Dan Bishop wrote: def cmp_key(cmp_fn): class CmpWrapper(object): def __init__(self, obj): self.obj = obj def __cmp__(self, other): return cmp_fn(self.obj, other.obj) return CmpWrapper Apparently I'm overlooking something obvious ... how is this supposed to work if __cmp__ is no longer being called? (Which was my understanding.) Thank you, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: no more comparisons
On Mar 13, 12:38 pm, Alan Isaac [EMAIL PROTECTED] wrote: Dan Bishop wrote: def cmp_key(cmp_fn): class CmpWrapper(object): def __init__(self, obj): self.obj = obj def __cmp__(self, other): return cmp_fn(self.obj, other.obj) return CmpWrapper Apparently I'm overlooking something obvious ... how is this supposed to work if __cmp__ is no longer being called? (Which was my understanding.) It won't. In Python 3.0 you'd have to write this class in terms of rich comparisons (__lt__, __gt__, etc.). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to send a var to stdin of an external software
I wrote: [...] Pipe loops are tricky business. Popular solutions are to make either the input or output stream a disk file, or to create another thread (or process) to be an active reader or writer. Or asynchronous I/O. On Unix-like systems, you can select() on the underlying file descriptors. (MS-Windows async mechanisms are not as well exposed by the Python standard library.) -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: Socket Performance
On Mar 13, 9:33 am, Brian Smith [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Sent: Wednesday, March 12, 2008 9:47 PM To: [EMAIL PROTECTED] Subject: Socket Performance Can anyone explain why socket performance (throughput) varies depending on the amount of data send and recv are called with? For example: try creating a local client/server (running on the same computer) where the server sends the client a fixed amount of data. Using method A, recv(8192) and sendall( ) with 8192 bytes worth of data. Do this 100 times. Using method B, recv(1) and sendall( ) with 1 byte worth of data. Do this 819200 times. If you time both methods, method A has much greater throughput than method B. Why is it faster to drink a liter of water a cupful at a time than to drink it out of an eyedropper? - Brian Well, lets say you have a situation where you're going to be alternating between sending large and small chunks of data. Is the solution to create a NetworkBuffer class and only call send when the buffer is full, always recv(8192)? -- http://mail.python.org/mailman/listinfo/python-list
RE: Attribute Doesnt Exist ... but.... it does :-s
Haha, I could use a stiff whisky myself after the stress that caused me :-) Robert -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robert Bossy Sent: 13 March 2008 16:10 To: python-list@python.org Subject: Re: Attribute Doesnt Exist ... but it does :-s Robert Rawlins wrote: Hi Guys, Well thanks for the response, I followed your advice and chopped out all the crap from my class, right down to the bare __init__ and the setter method, however, the problem continued to persist. However, Robert mentioned something about unindented lines which got me thinking so I deleted my tab indents on that method and replaces them with standard space-bar indents and it appears to have cured the problem. Aha! Killed the bug at the first guess! You owe me a beer, mate. RB -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: wx and pil conversion
azrael wrote: I thought of using Temp files but I am afraid of the JPG destorsion while saving because of the compresion.I am looking for a way to directly transform it. Then don't use JPEG, use PNG. It's lossless. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: wx and pil conversion
On Mar 13, 6:57 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: azrael wrote: I thought of using Temp files but I am afraid of the JPG destorsion while saving because of the compresion.I am looking for a way to directly transform it. Then don't use JPEG, use PNG. It's lossless. Diez thnx. i did't think about that. i totaly forgot png. -- http://mail.python.org/mailman/listinfo/python-list
getattr/setattr still ASCII-only, not Unicode - blows up SGMLlib from BeautifulSoup
Just noticed, again, that getattr/setattr are ASCII-only, and don't support Unicode. SGMLlib blows up because of this when faced with a Unicode end tag: File /usr/local/lib/python2.5/sgmllib.py, line 353, in finish_endtag method = getattr(self, 'end_' + tag) UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 46: ordinal not in range(128) Should attributes be restricted to ASCII, or is this a bug? John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Socket Performance
On 2008-03-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: For example: try creating a local client/server (running on the same computer) where the server sends the client a fixed amount of data. Using method A, recv(8192) and sendall( ) with 8192 bytes worth of data. Do this 100 times. Using method B, recv(1) and sendall( ) with 1 byte worth of data. Do this 819200 times. If you time both methods, method A has much greater throughput than method B. Why is it faster to drink a liter of water a cupful at a time than to drink it out of an eyedropper? Well, lets say you have a situation where you're going to be alternating between sending large and small chunks of data. Is the solution to create a NetworkBuffer class and only call send when the buffer is full, always recv(8192)? If you need to send large and small chumks of data, the solution is to send large and small chunks of data. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 13, 2:36 pm, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above I undertake to summarise answers posted to complete this survey. - Hendrik I think I'll choose 3. Well, no, I suppose the correct behavior _should_ be undefined (i.e. what it returns is an implementation details that should not be relied on). The fact that it returns None is just a coincidence that happens to happen every time you tested it (you can't prove by ignorance) -- http://mail.python.org/mailman/listinfo/python-list
Re: app runs fine with interpreter, but not under py2exe
Doug, Precision.py is part of the Numeric package. AFAIKT, the problem is during the module initialization. The first lines of Precision.py are: from multiarray import zeros import string [.] and your program is crashing on the lst.append( (zeros( (1,), t ).itemsize()*8, t) ) -- Line 18 line... Please, try the following: import multiarray from multiarray import zeros import string (adding the line import multiarray before zeros are imported from it) I used this workaround with various packages I py2exed - maybe it also works for you? please keep us updated, Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: frequency count or number of occurences of a number in an array
d'oh! On 12 mar, 07:58, John Machin [EMAIL PROTECTED] wrote: On Mar 12, 10:29 pm, Bernard [EMAIL PROTECTED] wrote: Hey Larry, that one is fairly easy: from array import array array('i', [1, 2, 3, 4, 5, 1, 2]) def count(x, arr): cpt = 0 # declare a counter variable for el in arr: # for each element in the array if el == x: # when it is equal to the 'x' value cpt+=1 # increment the counter variable by one return cpt # return the counter after the loop count(1,a) 2 Hey Bernard, you have just laboriously reinvented the count method: from array import array a = array('i', [1, 2, 3, 4, 5, 1, 2]) a.count(1) 2 which Larry has already said doesn't do the job -- the job is to create a histogram!! -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen pipeline bug?
Marko Rauhamaa wrote: This tiny program hangs: #!/usr/bin/env python import subprocess a = subprocess.Popen('cat',shell = True,stdin = subprocess.PIPE, stdout = subprocess.PIPE) b = subprocess.Popen('cat /dev/null',shell = True,stdin = a.stdout) a.stdin.close() b.wait() # hangs a.wait() # never reached To make it work, add close_fds=True in the Popen that creates b. It shouldn't, should it? Not sure. I think what's happening is that the second cat subprocess never gets EOF on its stdin, because there are still processes with an open file descriptor for the other end of the pipe. The Python program closes a.stdin, and let's suppose that's file descriptor 4. That's not enough, because the subshell that ran cat and the cat process itself inherited the open file descriptor 4 when they forked off. It looks like Popen is smart enough to close the extraneous descriptors for pipes it created in the same Popen call, but that one was created in a previous call and passed in. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
Dustan wrote: On Mar 13, 2:36 am, Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the following three lines of code at the interactive prompt: foo = [1,2,3,4] x = foo.append(5) print x What will be the output (choose one): 1) [1,2,3,4] 2) [1,2,3,4,5] 3) That famous picture of Albert Einstein sticking out his tongue 4) Nothing - no output 5) None of the above 5. This will cause a hidden feature of python and the OS, known as the 'python easter egg', to activate - erasing all data on the hard disk and then reporting how many bytes of data are left. Usually None ;-} - This really is a 'gotcha' (Aren't you sorry you cheated and typed this in !!) So the answer is 5 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
On Mar 12, 6:37 pm, Carl Banks [EMAIL PROTECTED] wrote: On Mar 12, 8:11 pm, Justus Schwabedal [EMAIL PROTECTED] wrote: What do you need it for anyway? I just read about it and I think it's useless in python. Perl, like Python, has a separate compilation and run times. One day, someone who was trying to use Perl for something asked, You know, wouldn't it be neat-o if you could execute some Perl code *before* you compiled the script? And so (since that's usually enough reason to add something to Perl) was borne the BEGIN block. I believe the official rationale was that they wanted to add some magic variables that affected Perl's compilation and couldn't do it without a magic block that executed at compile time. It's a bit different. Python's import and perl's use statements aren't very similar at all. See, perl looks for any use statements and runs those first. That's not the way for Python at all. It's ok to import a module right before you need it in a function. If you never call the function, you'll never import the module. What if you want to reprogram the search path before you use a module? Well, in Python, you just work on sys.path before the import statement. But in perl, if you put a statement that mucks with the perl path, then it will be ignored until it is too late. So you have to throw it into the BEGIN block to have it do anything at all. What was an obvious task in Python that uses only constructs and concepts you already know about, requires a new concept and syntax that wasn't needed before in perl. Also, Jeff has it right. Those who don't get it should look closely at the '-p' option passed to perl. (It has a cousin '-n' that is also just as useful.) Here, he wants to initialize some code before the loop starts, but he can't specify that initializing code outside of the loop without a BEGIN block. BEGIN is a dirty, ugly, stupid bandage to an underlying weakness in perl. That is, there is magic that needs more magic to override it. (And then you'll need magic to override the overriding magic, ad infinitum.) Rather than adding more magic, what you really need to do is get rid of magic that gets in people's way, or change the magic so it is actually useful for everyone. Python has it right. Tokenize, parse, (skip compile-link-import magic), and run. And leave out the magical -p and -n. If you want to iterate through a file, for line in sys.stdin:. -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 13, 10:42 am, Paul Rubin http://[EMAIL PROTECTED] wrote: [...] By Python convention, methods that mutate the object return None, and also stuff that returns None doesn't generate output at the interactive prompt. A convention that does not always hold: l = [1, 2, 3] l.pop() 3 l [1, 2] There is also the .next() method: i = iter([1, 2, 3]) i.next() 1 i.next() 2 I can't think of others ATM in python 2.x but there might be some. Moreover PEP 3119 introduces .add(), .discard(), .toggle() for MutableSets which all mutate self and return a non None object. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
On Mar 13, 7:03 pm, Jonathan Gardner [EMAIL PROTECTED] wrote: On Mar 12, 6:37 pm, Carl Banks [EMAIL PROTECTED] wrote: Snip And leave out the magical -p and -n. If you want to iterate through a file, for line in sys.stdin:. Or better still: import fileinput for line in fileinput.input(): process(line) - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
Paddy wrote: On Mar 13, 7:03 pm, Jonathan Gardner [EMAIL PROTECTED] wrote: On Mar 12, 6:37 pm, Carl Banks [EMAIL PROTECTED] wrote: Snip And leave out the magical -p and -n. If you want to iterate through a file, for line in sys.stdin:. Or better still: import fileinput for line in fileinput.input(): process(line) I write maybe a dozen one-liners a day. It's not practical to do this with Python, or at least it's not nearly as convenient as Perl. I'm fine with the magic. Abusing the magic is another story; Perl language features are meant to be used in particular contexts, and BEGIN blocks are rarely if ever necessary in Perl modules. -- http://mail.python.org/mailman/listinfo/python-list
Re: no more comparisons
Dan Bishop wrote: def cmp_key(cmp_fn): class CmpWrapper(object): def __init__(self, obj): self.obj = obj def __cmp__(self, other): return cmp_fn(self.obj, other.obj) return CmpWrapper On Mar 13, 12:38 pm, Alan Isaac wrote: how is this supposed to work if __cmp__ is no longer being called? (Which was my understanding.) Carl Banks wrote: It won't. In Python 3.0 you'd have to write this class in terms of rich comparisons (__lt__, __gt__, etc.). Exactly. So something simple (define an anonymous function) has become a bit of a pain. On the other hand, I've looked through my extant code and have not found a use of ``cmp`` that I cannot work around. So maybe this is not as bad as I feared. What are some use cases that will clearly be harder (i.e., at least require a slightly elaborate wrapper) after this change? Cheers, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Python regex
I hope posting is ok here for this question... I am attempting to extract the text from a CSS comment using 're' such as... string = /* CSS comment /* exp = [^(/*)].*[^(*/)] p = re.compile(exp) q = p.search(string) r = q.group() print r CSS comment although this works to a degree... I know the within the brackets everything is taken literally so the pattern I am to negating is (/*). ie. includes the parenthesis. So my question is... Is there a way to negate a pattern that is more than on character long? eg. where rather than saying if forward slash OR astrisk appear..negate. I would be saying if parenthesis AND asterisk appear in this order... negate -- Andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regex
made error on last line... read as... I would be saying if forward-slash AND asterisk appear in this order... negate -- -- Andrew Andrew Rekdal @comcast.net nospam wrote in message news:[EMAIL PROTECTED] I hope posting is ok here for this question... I am attempting to extract the text from a CSS comment using 're' such as... string = /* CSS comment /* exp = [^(/*)].*[^(*/)] p = re.compile(exp) q = p.search(string) r = q.group() print r CSS comment although this works to a degree... I know the within the brackets everything is taken literally so the pattern I am to negating is (/*). ie. includes the parenthesis. So my question is... Is there a way to negate a pattern that is more than on character long? eg. where rather than saying if forward slash OR astrisk appear..negate. I would be saying if parenthesis AND asterisk appear in this order... negate -- Andrew -- http://mail.python.org/mailman/listinfo/python-list
Ping and ARP on both Win and Linux in Python
Hi, this is my question: I want to know if several switch (about 50) in a big lan are up and then know their MAC addresses to do a list that contains host name, ip and mac. I know only the range of their IP addresses (the host name it's simply to know using socket.gethostn. The first idea it's to ping all ip, parse the response and then execute the command arp -a and parse the response. However this way depends on the operating system and the ping response depends too from the language. Another way it's to open the main page of the switch and parse the HTML code where i can find the MAC address. However this way depends on the particular brand's switch. I know (or better i think) that there is a third way: make ping and arp building the packets with socket and so on (but i dont have understand in what way do this). Any suggestion? (i've already search in google, found many sources but a lot of them don't works or don't do what im trying to do...) Regards, Mauretto. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regex
On Mar 13, 8:03 pm, Andrew Rekdal nospam@comcast.net wrote: I hope posting is ok here for this question... I am attempting to extract the text from a CSS comment using 're' such as... string = /* CSS comment /* exp = [^(/*)].*[^(*/)] p = re.compile(exp) q = p.search(string) r = q.group() print r CSS comment although this works to a degree... I know the within the brackets everything is taken literally so the pattern I am to negating is (/*). ie. includes the parenthesis. So my question is... Is there a way to negate a pattern that is more than on character long? eg. where rather than saying if forward slash OR astrisk appear..negate. I would be saying if parenthesis AND asterisk appear in this order... negate -- Andrew There would be many ways to do this. One: import re r = re.compile(r'/\*(.*?)\*/') tst = '.a { color: 0xAACC66; /* Fav color */ }' m = r.search(tst) m.group(1) ' Fav color ' HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
This actually works.
I couldn't believe it. Screw programming Python anymore! I'm totally serious. This actually works! It is SO EASY to make money this way. Anyone, and I mean ANYONE can do it. You should start seeing returns within a day or two. Do yourself a favour and at least check it out: http://agentb.affstocks.hop.clickbank.net/ Troy -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there Python equivalent to Perl BEGIN{} block?
In article [EMAIL PROTECTED], Jeff Schwab [EMAIL PROTECTED] wrote: I write maybe a dozen one-liners a day. It's not practical to do this with Python, or at least it's not nearly as convenient as Perl. That is a defensible position, but my take is that writing the one-liners in Python is more convenient than remembering enough Perl to make writing one-liners useful. Especially when the one-liners often start expanding. -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ All problems in computer science can be solved by another level of indirection. --Butler Lampson -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regex
-- -- Andrew Arnaud Delobelle [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Mar 13, 8:03 pm, Andrew Rekdal nospam@comcast.net wrote: I hope posting is ok here for this question... I am attempting to extract the text from a CSS comment using 're' such as... string = /* CSS comment /* exp = [^(/*)].*[^(*/)] p = re.compile(exp) q = p.search(string) r = q.group() print r CSS comment although this works to a degree... I know the within the brackets everything is taken literally so the pattern I am to negating is (/*). ie. includes the parenthesis. So my question is... Is there a way to negate a pattern that is more than on character long? eg. where rather than saying if forward slash OR astrisk appear..negate. I would be saying if parenthesis AND asterisk appear in this order... negate -- Andrew There would be many ways to do this. One: import re r = re.compile(r'/\*(.*?)\*/') tst = '.a { color: 0xAACC66; /* Fav color */ }' m = r.search(tst) m.group(1) ' Fav color ' HTH -- Arnaud Arnaud, in your expression above.. r = re.compile(r'/\*(.*?)\*/') what does the 'r' do? -- andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: This actually works.
On 2008-03-13, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I couldn't believe it. Screw programming Python anymore! OMG, IT'S FREE MONEY! I guess you've got to give the wanker credit for actually mention Python programming. :) -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regex
On Mar 13, 8:22 pm, Andrew Rekdal nospam@comcast.net wrote: [...] in your expression above.. r = re.compile(r'/\*(.*?)\*/') what does the 'r' do? It means the literal is a 'raw string' : print 'Hi\nthere!' Hi there! print r'Hi\nthere!' Hi\nthere! If you haven't done so already, I suggest reading the tutorial. Here is a link to the relevant section on strings: http://docs.python.org/tut/node5.html#SECTION00512 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: how to pass the workspace ?
Gary Herron wrote: Stef Mientki wrote: hello, I've GUI tree with drag and drop nodes, where each nodes contains a code snippet. Now I want to run one or more branches in that tree, so I enumerate over the nodes and have to run something like this: execfile ( node1 ) execfile ( node2 ) etc.. Now how do I pass the workspace created in node1, to node 2, etc ? thanks, Stef Mientki RTFM! In particular: http://docs.python.org/lib/built-in-funcs.html#l2h-26 thanks Gary, I read that, but sorry, unfortunately I don't understand it, this is what I tried: tree_globs = {} tree_locals = {} tree_globs [ 'NewVar' ] = 24 filename = self.Get_Editor_Filename (nodename) execfile ( filename, tree_globs, tree_locals ) print dir ( tree_globs) print dir ( tree_locals ) where the code in the executed file is: beer = 'testje' print dir() print dir (globals) print dir (locals) the output I get is: aap ['beer'] ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__str__'] ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__str__'] ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] The result of globals and locals in the file is eaxctly the same and none of them mentions 'NewVar' and 'beer' The result of tree_globs and tree_locals is exactly the same and both doesn't contain 'NewVar' and 'beer' Maybe it's very simple after reading the manual, but apperently I'm missing the essential clue. What am I missing ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Update pytz timezone definitions
I am looking at using pytz in a scheduling application which will be used internationally. I would like to be able to update the definition files that pytz uses monthly or bi-monthly. As far as I can tell, pytz seems to be updated (fairly) regularly to the newest tzdata, but I don't want to have to update my pytz, just it's definitions. http://www.twinsun.com/tz/tz-link.htm says that pytz compiles tz source into Python. Does this mean that there is already a method for updating the definitions? Any help would be greatly appreciated, even if it is to point out something obvious which I over looked. - Robby -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen pipeline bug?
[EMAIL PROTECTED]: Not sure. I think what's happening is that the second cat subprocess never gets EOF on its stdin, because there are still processes with an open file descriptor for the other end of the pipe. You are right. However, the close_fds technique seems a bit heavy-handed. Well, that's what you get when you try to combine fork and exec into a single call. Marko -- Marko Rauhamaa mailto:[EMAIL PROTECTED] http://pacujo.net/marko/ -- http://mail.python.org/mailman/listinfo/python-list
Python-PHP bridge?
Hi all, I'm starting to translate a large legacy php app to python (django), and was wondering if anyone knew of a bridge between the 2 languages. (access php objects from python and vice versa). Some of the solutions I've come across so far include using php's passthru() ( http://us3.php.net/passthru ) and pyphp. passthru(): I'm concerned about the potential performance hit of all these system calls. Isn't this the equivalent of a CGI app? pyphp: Seems closer to what I'm looking for, but I haven't been able to get the examples working yet. Maybe it is to alpha? If anyone has any experience with these tools or others and can share some advice, I'd appreciate it! Thanks! Erik -- http://mail.python.org/mailman/listinfo/python-list
Re: List mutation method gotcha - How well known?
On Mar 14, 6:13 am, Arnaud Delobelle [EMAIL PROTECTED] wrote: On Mar 13, 10:42 am, Paul Rubin http://[EMAIL PROTECTED] wrote: [...] By Python convention, methods that mutate the object return None, and also stuff that returns None doesn't generate output at the interactive prompt. A convention that does not always hold: l = [1, 2, 3] l.pop() 3 l [1, 2] Try this then for the convention: Any function/method that is not documented to return something else should be assumed to return None. Note: no nexus with whether or not the function/method mutates its args. -- http://mail.python.org/mailman/listinfo/python-list