ANN: Paste 1.2
Paste 1.2 - I'm happy to release Paste 1.2. This release contains a mix of small features and bug fixes. This is only a release of core Paste (not Paste Script or Deploy), which contains the WSGI tools. What Is Paste? -- URL: http://pythonpaste.org Install: easy_install -U Paste News: http://pythonpaste.org/news.html Paste is a set of WSGI components, each of which can be used in isolation. But mixing them together leads to powerful chemical reactions which can be harnessed for good. These components let you do things like create applications that proxy to other websites, mount multiple applications under different prefixes, catch exceptions and interactively inspect the environment, and much more. Paste Deploy is a configuration system for these components. Paste Script is a jack of all trades that builds new project file layouts, runs WSGI server stacks, and does application deployment. Interesting News See http://pythonpaste.org/news.html for details * Backward incompatible change in paste.fileapp.FileApp to make it support GET and HEAD properly. If you subclassed FileApp or DataApp you may need to change your code. * Parsing of Accept and Accept-Language * paste.wsgiwrappers.WSGIRequest can optionally decode unicode values in form submissions. * paste.httpserver supports all request methods (e.g., MKCOL), no longer blocks if you read past the end of wsgi.input, and includes code to control the thread pool and kill threads that are wedged. -- Ian Bicking | [EMAIL PROTECTED] | http://blog.ianbicking.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Creating Web 2.0 sites using Python2.5, without a database.
LinuxWorld has published my article about the Relative Static approach to web application design (BoSStats, FlightFeather and the Relative Static Web). http://www.linuxworld.com/news/2007/012907-flightfeather.html This method tries to capture as much system state as possible in static HTML files, which the webserver can use directly. While the resulting site is dynamic, it is static from the webserver's point of view. I use this approach in my FlightFeather and Flightdeck-UI Online Free/Open Source projects. The article describes why Python (specifically version 2.5) is such a good choice for Relative Static web applications. The discussion focuses on the newly introduced with statement and the context manager type (see link to page 5, below). http://www.linuxworld.com/news/2007/012907-flightfeather.html?page=5 -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Pyrex 0.9.5.1a
Pyrex 0.9.5.1a is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ This is a glitch-fix nanorelease to correct a problem with the setup.py file. The list of packages to install is now calculate dynamically, so that it will work with or without the testing files. What is Pyrex? -- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
OT: Variant name spellings (Re: how to free an object/var ?)
Steven D'Aprano wrote: Ste_ph_en??? I knew someone once who referred to the two ways of spelling Ste{v,ph}en as the dry way and the wet way... It's not like I spell my name with four M's and a silent Q like the famous author Farles Wickens *wink* Or Mr. Luxury-Yacht, which as we all know is pronounced Throatwarbler-Mangrove. With a silent hyphen. -- Greg Psmith (pronounced You-ing) -- http://mail.python.org/mailman/listinfo/python-list
Re: division by 7 efficiently ???
In [EMAIL PROTECTED], Paul McGuire wrote: On Jan 31, 11:36 pm, Paddy [EMAIL PROTECTED] wrote: On Feb 1, 2:42 am, [EMAIL PROTECTED] wrote: How to divide a number by 7 efficiently without using - or / operator. We can use the bit operators. I was thinking about bit shift operator but I don't know the correct answer. int.__div__(14,2) 7 Not a minus or division operator in sight ;-) - Paddy. Now I'm confused - was the OP trying to divide by 7 or 2? I read it as divide by 7. And the `int.__div__()` Method limits this somehow -- a more polymorphic approach would be:: import operator operator.div(14, 7) :-) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: how to free an object/var ?
Steven D'Aprano wrote: Ste_ph_en??? I know the ph-form of the name is marginally more popular, but dammit my name is right there just two lines above where Paddy started typing, how hard is it to get it right? It's not like I spell my name with four M's and a silent Q like the famous author Farles Wickens *wink* I knew a guy whose first name was Ed. He was so cool, he spelled it with a hyphen. -- George Carlin -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM, Y!M erikmaxfrancis If the sky should fall, hold up your hands. -- (a Spanish proverb) -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
Jean-Paul Calderone wrote: [---] Software is hard. But I absolutely agree with this point, anyway :) Software is _crazy_ hard. I merely dispute the claim that threads are somehow _easier_. :) Threads aren't easier. Nor are they harder. They are just different. I used to be heavily into OS/2 programming. In OS/2, you use threads heavily - almost by tradition. Its relatively low context switch latency and its nice set of IPC routines (almost all API's are thread safe and reentrant), make developing multithreaded applications quite natural. Guess what happened when I started programming on NetBSD and Windows. I struggled to write singlethreaded applications(!). I was so used to kicking off a worker thread as soon as I needed to do something that I knew could just as well be done in the background. An I *constantly* thought in terms of How could I make full use of an SMP system?. I would never claim that multithreading is *easier* than singlethreaded. It's mererly a different way of thinking. OTOH, multithreaded does have a steeper learning curve. But once you get past that, there's really not a lot of difference, IMHO. YMMV. -- Kind regards, Jan Danielsson -- http://mail.python.org/mailman/listinfo/python-list
how do I pipe two processes?
Hi, I want to pipe output of process A to B, and read output of B from python. On Unix if I do the following: child_out, child_in = popen2(program_a | program_b) line = child_out.readline() I get IOError: bad file descriptor from Python, and broken pipe error from program_b. How do I do this right? Thanks, Bahadir -- http://mail.python.org/mailman/listinfo/python-list
retrbinary ! how does it work ?
Hello dear community ! I'm a bit ashamed to ask such an easy question, but I didn't find my answer on previous posts. I'd like to copy files with FTP protocol in a subdirectory. So far, my code look like that : import ftplib session = ftplib.FTP('222.33.44.55','usr','pwd') session.cwd('/') files = session.nlst() for file in files: session.retrbinary('RETR '+file, open(file, 'wb').write) It does work but the files are copied in the same directory as the python file. And I would like to copy the file in this relative directory : ../archives For example, if the python file is in this directory : C:\SCOR\Bat\, the FTP files gotta be in C:\SCOR\archives\ . Can anyone help me. Thanks a lot by advance. Yvan Blancmunier -- http://mail.python.org/mailman/listinfo/python-list
Re: division by 7 efficiently ???
This is maybe not so efficient :) but it implements integer division by 7 for positive integers without - and /. def div2(num): return num 1 def div4(num): return num 2 def div8(num): return num 3 def mul2(num): return num 1 def mul4(num): return num 2 def mul7(num): return mul4(num) + mul2(num) + num def div7_help(num, lo, hi): avg = div2(lo + hi) if avg == lo or avg == hi: if mul7(hi) == num: return hi return lo avg7 = mul7(avg) if avg7 num: return div7_help(num, lo, avg) elif avg7 num: return div7_help(num, avg, hi) return avg def div7(num): lo = div8(num) hi = div4(num) return div7_help(num, lo, hi) for nr in range(0, 2): #print %d // 7 = %d % (nr, nr // 7) #print div7(%d) = %d % (nr, div7(nr)) assert nr // 7 == div7(nr) A somewhat better approach is to convert the recursion to an interative method. But that is.. um.. left as an exercise. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: retrbinary ! how does it work ?
[EMAIL PROTECTED] wrote: Hello dear community ! I'm a bit ashamed to ask such an easy question, but I didn't find my answer on previous posts. I'd like to copy files with FTP protocol in a subdirectory. So far, my code look like that : import ftplib session = ftplib.FTP('222.33.44.55','usr','pwd') session.cwd('/') files = session.nlst() for file in files: session.retrbinary('RETR '+file, open(file, 'wb').write) It does work but the files are copied in the same directory as the python file. And I would like to copy the file in this relative directory : ../archives For example, if the python file is in this directory : C:\SCOR\Bat\, the FTP files gotta be in C:\SCOR\archives\ . Can anyone help me. The problem is your callback-function that you create like this: open(file, 'wb').write If all you pass here is file, where else than in the current working directory do you expect files to appear? Either provide a full destination path like this open(os.path.join('../', file), 'wb').write or change the current working directory beforehand, using os.cwd. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: retrbinary ! how does it work ?
En Thu, 01 Feb 2007 06:17:34 -0300, [EMAIL PROTECTED] [EMAIL PROTECTED] escribió: I'd like to copy files with FTP protocol in a subdirectory. So far, my code look like that : import ftplib session = ftplib.FTP('222.33.44.55','usr','pwd') session.cwd('/') files = session.nlst() for file in files: session.retrbinary('RETR '+file, open(file, 'wb').write) (hmm, using file as a variable name is not a good idea, it hides the builtin type of the same name) It does work but the files are copied in the same directory as the python file. And I would like to copy the file in this relative directory : ../archives For example, if the python file is in this directory : C:\SCOR\Bat\, the FTP files gotta be in C:\SCOR\archives\ . Let's say, if the file name were abc.txt, you should open the output using this name: '../archives/abc.txt' To build a path from its components, use os.path.join So, replace open(file,... above, with open(os.path.join('../archives',file),... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I import a file without file extension .py?
On Feb 1, 12:51 am, Jia Lu [EMAIL PROTECTED] wrote: def make_module_from_file(module_name, file_name): Make a new module object from the code in specified file from types import ModuleType module = ModuleType(module_name) module_file = open(file_name, 'r') exec module_file in module.__dict__ Thank you very much. And can you tell me what does exec module_file in module.__dict__ mean? Thanx http://docs.python.org/ref/exec.html It executes whatever code is in module_file and dumps all variables defined in the process into module.__dict__. -- http://mail.python.org/mailman/listinfo/python-list
stlib name clash when using python as ASP language
Hi guys, I have couple of simple python based active server pages that make use of httplib2 which uses gzip.py. IIS, however, also has a gzip.dll located at the iis/inetsrv path. When using ASP the iis/inetsrv path is placed as the first item in sys.path. Consequently importing httplib2 will cause the following error: import httplib2 File c:\python24\lib\site-packages\httplib2-0.2.0-py2.4.egg \httplib2\__init__.py, line 25, in ? import gzip ImportError: dynamic module does not define init function (initgzip) This is, of course, because it tries to load the gzip.dll file instead of the gzip.py file. The following per page hack *fixes* the problem most of the time: import sys sys.path[0] = c:/python24/lib Strangely, even with this code loaded in every page the import error sporadically occurs. What would be the preferred way to solve this name clash? -- http://mail.python.org/mailman/listinfo/python-list
Re: Correct db adapter
Ok, i see.. Thanks a lot all of you for the help. I know from my Win/.Net/Sql Server expertise that odbc put a layer in the mix. That's why, for example, in .Net we have a native SqlClient data provider that talks to Sql Server directly. But one of the reasons that i started learning Python, is to NOT to be tied-up again with ANY company or specific product again (i had enough MS addiction over these years...). So, based on this direction, i am using pyodbc, which is DB-API2 compliant and i suppose that the code i write this way, will have little changes to use another db in the future. I dig the net and found that there are several efforts for modules specific to some databases but some of them are incomplete, faded, or not db-api2 compliant. So, i will check mxOdbc and see if there is a reason to use it over pyodbc. -- http://mail.python.org/mailman/listinfo/python-list
Re: retrbinary ! how does it work ?
Thanks a lot Diez and Gabriel. It works perfectly ! Have a nice day Yvan -- http://mail.python.org/mailman/listinfo/python-list
SWIG overhead
Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it spends quiet some time in functions like _swig_setattr_nondinamic, _swig_setattr, _swig_getattr. -- http://mail.python.org/mailman/listinfo/python-list
Help me with this!!!
Hi all, I've this code: regex = re.compile(r(?si)(\x8B\xF0\x85\xF6)(?Pcontents.*) (\xC6\x44\x24),re.IGNORECASE) file = open(fileName, rb) for line in file: if (match): print line file.close() It search a text inside that hex value. It works perfecly on a txt file but if I open a binary file (.exe,.bin ecc...) with the same value it wont work, why? Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On 1 Feb 2007 02:21:35 -0800, Bart Ogryczak [EMAIL PROTECTED] wrote: Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it spends quiet some time in functions like _swig_setattr_nondinamic, _swig_setattr, _swig_getattr. Before you decide to go low level consider to use Boost.Python. According to this( http://tinyurl.com/322d3p ) post it gives pretty good performance. P.S. The post does not contain numbers -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: pil, histogram, mask
Daniel Nogradi I don't need the histogram really, only the mean color value, but as far as I can see the 'mean' attribute only applies to an image and a mask can not be specified. You can slice parts of the image, and then use the ImageStat.Stat(im).mean On it. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On Thursday 01 February 2007 10:21 am, Bart Ogryczak wrote: Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it spends quiet some time in functions like _swig_setattr_nondinamic, _swig_setattr, _swig_getattr. There was a EuroPython paper describing some benchmarks. It's from 2004 so things have probably changed a bit (SIP is now fully documented for example). http://people.web.psi.ch/geus/talks/europython2004_geus.pdf Phil -- http://mail.python.org/mailman/listinfo/python-list
Play UK Lotto + Euromillions fo FREE
Play the UK lotto + Euromillions for free. see www.carlnalex.pwp.blueonder.co.uk -- http://mail.python.org/mailman/listinfo/python-list
ZSI and WSDL schema
Hi all. I have problem with ZSI and WSDL schema.I generate from WSDL by wsdl2py client method for webservice. I made soap call and something goes wrong. Doeas anyone know hot to create some server code by ZSI from WSDL?? I just suspectes that my return data from webservice is in incorrect envelope - so maybe wsdl2py can help mi generate correct server method, or just generate correct structure that webservice should return. Thanks for any help. Gregor -- http://mail.python.org/mailman/listinfo/python-list
Re: how do I pipe two processes?
On Feb 1, 10:12 am, [EMAIL PROTECTED] wrote: Hi, I want to pipe output of process A to B, and read output of B from python. On Unix if I do the following: child_out, child_in = popen2(program_a | program_b) line = child_out.readline() I get IOError: bad file descriptor from Python, and broken pipe error from program_b. How do I do this right? Thanks, Bahadir Use the subprocess module, see the examples here: http://docs.python.org/dev/lib/node539.html Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes error on exit of win32 application
On Jan 31, 8:49 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: Maybe process_record expects some minimum buffer size? The cpp example uses char record[100], but you are allocating only a few bytes with the string My Record No, I've already tried padding record out to the full size. But thank you for the suggestion. -- Jeff Bauer Rubicon, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On Feb 1, 12:12 pm, Phil Thompson [EMAIL PROTECTED] wrote: On Thursday 01 February 2007 10:21 am, Bart Ogryczak wrote: Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it spends quiet some time in functions like _swig_setattr_nondinamic, _swig_setattr, _swig_getattr. There was a EuroPython paper describing some benchmarks. It's from 2004 so things have probably changed a bit (SIP is now fully documented for example). http://people.web.psi.ch/geus/talks/europython2004_geus.pdf Yeah, found that one googling around. But I haven´t fund anything more up to date. I imagine, that the performance of all of these wrappers has been improved since then. But the performance of Python/C API would too? Anyways, it´s not about exact number, it´s more about taking decision if doing rewrite is worth it´s time. -- http://mail.python.org/mailman/listinfo/python-list
Re: ZSI and WSDL schema
On 1 Feb 2007 03:14:14 -0800, Grzegorz Smith [EMAIL PROTECTED] wrote: Hi all. I have problem with ZSI and WSDL schema.I generate from WSDL by wsdl2py client method for webservice. I made soap call and something goes wrong. It might help if you were a little more specific. -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
Yeah, found that one googling around. But I haven´t fund anything more up to date. I imagine, that the performance of all of these wrappers has been improved since then. But the performance of Python/C API would too? Anyways, it´s not about exact number, it´s more about taking decision if doing rewrite is worth it´s time. The wrappers essentially create the boilerplate-code that invokes the Python C-API. So whatever improvements the latter has been developed, the wrappers will benefit from it. I doubt that there are major performance penalties associated with any of them. More important for a wrapper-decision is the question how easy they are to use. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for the IPod shuffle ...
On 1/31/07, Analog Kid [EMAIL PROTECTED] wrote: Hi all: Im looking for a python module thatll let me do simple reads/writes from and to an iPod shuffle similar to iTunes ... I read about the gPod module ... but Im not sure whether it will work in Windows ... This any good? http://superduper.net/?page=pypod -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Correct db adapter
On 1 Feb 2007 02:13:01 -0800, king kikapu [EMAIL PROTECTED] wrote: But one of the reasons that i started learning Python, is to NOT to be tied-up again with ANY company or specific product again (i had enough MS addiction over these years...). So, based on this direction, i am using pyodbc, which is DB-API2 compliant and i suppose that the code i write this way, will have little changes to use another db in the future. I don't know if this product will meet your needs, but I've read recently on the Dabo list that they've added support for Microsoft SQL Server. I don't work with databases, so I have no idea how this might compare to what you're looking at, but I do know that in general their code is solid and the authors are responsive. So you might want to check out Dabo: http://dabodev.com -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Scrolling
I'm sure this is a simple question to the Tkinter experts - I have a very basic Tkinter application that consists of 1 master window and buttons within that window. My problem is that, I need to be able to scroll (up and down) when I get to the point that the buttons go off the screen. What's the easiest way to do this? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On 31 Jan 2007 22:02:36 -0800, Michele Simionato [EMAIL PROTECTED] wrote: On Jan 31, 8:31 pm, Carl J. Van Arsdall [EMAIL PROTECTED] wrote: Well, since it will be io based, why not use threads? They are easy to use and it would do the job just fine. Then leverage some other technology on top of that. You could go as far as using wget via os.system() in a thread, if the app is simple enough. Calling os.system in a thread look really perverse to me, you would loose CTRL-C without any benefit. Why not to use subprocess.Popen instead? I am unhappy with the current situation in Python. Whereas for most things Python is such that the simplest things look simple, this is not the case for threads. Unfortunately we have a threading module in the standard library, but not a Twisted for pedestrian module, so people overlook the simplest solution in favor of the complex one. Another thing I miss is a facility to run an iterator in the Tkinter mainloop: since Tkinter is not thread-safe, writing a multiple-download progress bar in Tkinter using threads is definitely less obvious than running an iterator in the main loop, as I discovered the hard way. Writing a facility to run iterators in Twisted is a three-liner, but it is not already there, nor standard :-( Have you seen the recently introduced twisted.internet.task.coiterate()? It sounds like it might be what you're after. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me with this!!!
TOXiC wrote: Hi all, I've this code: No you don't. regex = re.compile(r(?si)(\x8B\xF0\x85\xF6)(?Pcontents.*) (\xC6\x44\x24),re.IGNORECASE) file = open(fileName, rb) for line in file: if (match): print line file.close() It search a text inside that hex value. It works perfecly on a txt file but if I open a binary file (.exe,.bin ecc...) with the same value it wont work, why? Please help! Because the pattern isn't in the file, perhaps. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: how do I pipe two processes?
[EMAIL PROTECTED] wrote: Hi, I want to pipe output of process A to B, and read output of B from python. On Unix if I do the following: child_out, child_in = popen2(program_a | program_b) line = child_out.readline() I get IOError: bad file descriptor from Python, and broken pipe error from program_b. How do I do this right? In through the out door? From the docs: ... Returns the file objects (child_stdin, child_stdout) ... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: ZSI and WSDL schema
Ok here goes a detail: I call two methods by soap. The response of that methods is described by xml. Here is first request: (method name QuickSearch, one parameter called name) xsd:element name=QuickSearch xsd:complexType xsd:sequence xsd:element name=name minOccurs=0 maxOccurs=1 type=xsd:int/ /xsd:sequence /xsd:complexType /xsd:element So here go 1 response (part of the wsdl): xsd:element name=QuickSearchReturn xsd:complexType xsd:sequence xsd:element name=name minOccurs=0 maxOccurs=1 type=xsd:int/ /xsd:sequence /xsd:complexType /xsd:element and the methods that I call is here: def QuickSearch(name): #here done something by name paramater passed by #and return parameter name return {'name':50} I don't know how to pack returned data to the proper envelope. When I made SOAP call by hand (just like examples from ZSI everything goes well), but when I made SOAP by WSDL everything goes wrong. And here is the second question I descripe response from my second SOAP Method, it looks like this: xsd:complexType name=AlbumResult xsd:sequence xsd:element name=NALB minOccurs=0 maxOccurs=1 type=xsd:int/ xsd:element name=NFTG minOccurs=0 maxOccurs=1 type=xsd:int/ xsd:element name=NAZW minOccurs=0 maxOccurs=1 type=xsd:string/ xsd:element name=KATG minOccurs=0 maxOccurs=1 type=xsd:string/ xsd:element name=DTWO minOccurs=0 maxOccurs=1 type=xsd:string/ xsd:element name=MISC minOccurs=0 maxOccurs=1 type=xsd:string/ xsd:element name=LOCL minOccurs=0 maxOccurs=1 type=xsd:string/ xsd:element name=OPIS minOccurs=0 maxOccurs=1 type=xsd:string/ /xsd:sequence /xsd:complexType I have data prepared in Python script, but still don't know how to made proper response envelop with that data. As you see it's complicated type, but I don't what It should look like to be proper response. Any help? Please Gregor Thanks Simon On 1 Lut, 12:42, Simon Brunning [EMAIL PROTECTED] wrote: On 1 Feb 2007 03:14:14 -0800, Grzegorz Smith [EMAIL PROTECTED] wrote: Hi all. I have problem with ZSI and WSDL schema.I generate from WSDL by wsdl2py client method for webservice. I made soap call and something goes wrong. It might help if you were a little more specific. -- Cheers, Simon B [EMAIL PROTECTED]://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: division by 7 efficiently ???
On Feb 1, 3:13 am, [EMAIL PROTECTED] wrote: Its not an homework. I appeared for EA sports interview last month. I was asked this question and I got it wrong. I have already fidlled around with the answer but I don't know the correct reasoning behind it. In that case, observer that a/b == a * (1/b), and if b is constant you can compute (1/b) in advance. Since the problem was set by game programmers I'd hazard that they are OK with relatively limited precision and the answer that they were looking for was: a = (b * 045L) 32 Note that the constant there is in octal. Nicko -- http://mail.python.org/mailman/listinfo/python-list
newbie question: nested archives and zipfile
I sorry, but I'm not very familiar with Python. Please, help to solve my problem with reading file from nested zip archive. There is an ear_file.ear and inside this file there is a war_file.war and inside this file there is a jar_file.jar. I have to read content of a file (my_file.txt) from inside a jar_file.jar: ear_file.ear war_file.war jar_file.jar my_file.txt Is it possible to directly read my_file.txt from inside this kind of nested archive? Please, give an example how to do that. Do I have to open ear_file.ear, read war_file.war, write it to file and then open writed war_file.war, read jar_file.jar, write it to file and then open wreted jar_file.jar and read my_file.txt?? Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On Feb 1, 1:43 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 31 Jan 2007 22:02:36 -0800, Michele Simionato [EMAIL PROTECTED] wrote: Another thing I miss is a facility to run an iterator in the Tkinter mainloop: since Tkinter is not thread-safe, writing a multiple-download progress bar in Tkinter using threads is definitely less obvious than running an iterator in the main loop, as I discovered the hard way. Writing a facility to run iterators in Twisted is a three-liner, but it is not already there, nor standard :-( Have you seen the recently introduced twisted.internet.task.coiterate()? It sounds like it might be what you're after. Ops! There is a misprint here, I meant writing a facility to run iterators in TKINTER, not in Twisted. Twisted has already everything, even too much. I would like to have a better support for asynchronous programming in the standard library, for people not needing the full power of Twisted. I also like to keep my dependencies at a minimum. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie question: nested archives and zipfile
[EMAIL PROTECTED] wrote: I sorry, but I'm not very familiar with Python. Please, help to solve my problem with reading file from nested zip archive. There is an ear_file.ear and inside this file there is a war_file.war and inside this file there is a jar_file.jar. I have to read content of a file (my_file.txt) from inside a jar_file.jar: ear_file.ear war_file.war jar_file.jar my_file.txt Is it possible to directly read my_file.txt from inside this kind of nested archive? Please, give an example how to do that. No. Do I have to open ear_file.ear, read war_file.war, write it to file and then open writed war_file.war, read jar_file.jar, write it to file and then open wreted jar_file.jar and read my_file.txt?? Yes. Depending on the size of the files, it might be possible to use StringIO to keep the files in-memory without using temp-files. Diez -- http://mail.python.org/mailman/listinfo/python-list
Inconsistent list/pointer problem
I am having a problem with the corruption of a list. It occurs only the first time that I call a function and never happens on subsequent calls. Any suggestions would be appreciated. I call the function, passing in a list as the input data. The function must manipulate and operate on a copy of that list's data, without altering the list in the calling routine. def myFunc(listA): listB = listA work on modify listB return(listB) The first time this function touches listB, listA is corrupted. However, I get the right results from the function. On subsequent calls to the function, listA is not corrupted further and the function will always return the same wrong results, which would be correct given the corruption of listA created in the first call. I concluded that it appears that listB is still pointing at elements of listA and I need to force Python to reassign those pointers to point to copies of listA's elements. I've tried copying listA to a tuple and then change the copy back to a list. That sometimes works if the input data is a simple list. It does not work if the input data is a list extracted from a list of lists. listB = tuple(listA) listB = list(listB) I've tried building the copy of listA, element by element, but that doesn't work. listB = [] for x in listA: listB.append(x) I finally had to do some type changing during the element by element copy and that does seem to work. Thanks in advance for any suggestions. Doug -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistent list/pointer problem
Doug Stell: The standard module copy has deepcopy, it's slow but it may be a simple solution to your problem. A better solution is to look where data is changed and fix that. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistent list/pointer problem
Doug Stell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I call the function, passing in a list as the input data. The function must manipulate and operate on a copy of that list's data, without altering the list in the calling routine. Then you will want to make a copy: listB = copy.deepcopy( listA) -- http://mail.python.org/mailman/listinfo/python-list
Python design project
Dear community, I dont really know if this is the right way to do, otherwise my excuses for that. I'm a Dutch student, and graduating this year on my graphic design study. For my graduating study, I want to do some Python work and i'm lokking for a partner wich can help/ cooperate me in programming python. The project In short: The project subject is type, and i want to create a self generating type. I hope there are some interests, otherwist, thank you all.. Bye.. Rick -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me with this!!!
Peter Otten ha scritto: TOXiC wrote: Hi all, I've this code: No you don't. ! regex = re.compile(r(?si)(\x8B\xF0\x85\xF6)(?Pcontents.*) (\xC6\x44\x24),re.IGNORECASE) file = open(fileName, rb) for line in file: if (match): print line file.close() It search a text inside that hex value. It works perfecly on a txt file but if I open a binary file (.exe,.bin ecc...) with the same value it wont work, why? Please help! Because the pattern isn't in the file, perhaps. This pattern IS in the file (I made it and I double check with an hex editor). It display the file correcltly (print line) but... -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me with this!!!
On Feb 1, 4:21 am, TOXiC [EMAIL PROTECTED] wrote: Hi all, I've this code: regex = re.compile(r(?si)(\x8B\xF0\x85\xF6)(?Pcontents.*) (\xC6\x44\x24),re.IGNORECASE) file = open(fileName, rb) for line in file: if (match): print line file.close() It search a text inside that hex value. It works perfecly on a txt file but if I open a binary file (.exe,.bin ecc...) with the same value it wont work, why? Please help! Where do you assign the value of 'match'? Perhaps you are missing a line such as match=regex.match(line) or match=regex.search(line)? Perhaps this is why Peter Otten says that this code can't possibly be the code that works for text files? What is the significance of for line in file when file is opened in binary mode? Are EOLs properly interpreted in binary mode? ('file' is not the best variable name, by the way, as it masks Python's built- in file. How about file_, or inputfile, or fileToBeSearched?) -- Paul -- http://mail.python.org/mailman/listinfo/python-list
ANN: Pyrex 0.9.5.1a
Pyrex 0.9.5.1a is now available: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/ This is a glitch-fix nanorelease to correct a problem with the setup.py file. The list of packages to install is now calculate dynamically, so that it will work with or without the testing files. What is Pyrex? -- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- http://mail.python.org/mailman/listinfo/python-list
Re: The reliability of python threads
Carl J. Van Arsdall wrote: Steve Holden wrote: [snip] Are you using memory with built-in error detection and correction? You mean in the hardware? I'm not really sure, I'd assume so but is there any way I can check on this? If the hardware isn't doing that, is there anything I can do with my software to offer more stability? You might be able to check using the OS features (have you said what OS you are using?) - alternatively Google for information from the system supplier. If you don't have that feature in hardware you are up sh*t creek without a paddle, as it can't be emulated. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
NoName wrote: Perl: @char=(A..Z,a..z,0..9); do{print join(,@char[map{rand @char}(1..8)])}while(); If you generate passwords like that to normal computer users, you'll end up with a lot of my password doesn't work tickets. You should skip the symbols that are easy to mistake for each other. Skip at least Il1 and 0O. On the other hand, you could probably use other characters besides letters and digits to make the passwords stronger. Which ones to use is unfortunately platform dependent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On Jan 31, 3:37 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 31 Jan 2007 12:24:21 -0800, Carl Banks [EMAIL PROTECTED] wrote: Michele Simionato wrote: On Jan 31, 5:23 pm, Frank Potter [EMAIL PROTECTED] wrote: I want to find a multithreaded downloading lib in python, can someone recommend one for me, please? Thanks~ Why do you want to use threads for that? Twisted is the obvious solution for your problem, Overkill? Just to download a few web pages? You've got to be kidding. Better overkill (whatever that is) than wasting time re-implementing the same boring thing over and over for no reason. I need to download some web pages in parallel. Here's tremendously large and complex framework. Download, install, and learn this large and complex framework. Then you can write your very simple throwaway script with ease. Is the twisted solution even shorter? Doing this with threads I'm thinking would be on the order of 20 lines of code. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On 1 Feb 2007 06:14:40 -0800, Carl Banks [EMAIL PROTECTED] wrote: On Jan 31, 3:37 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 31 Jan 2007 12:24:21 -0800, Carl Banks [EMAIL PROTECTED] wrote: Michele Simionato wrote: On Jan 31, 5:23 pm, Frank Potter [EMAIL PROTECTED] wrote: I want to find a multithreaded downloading lib in python, can someone recommend one for me, please? Thanks~ Why do you want to use threads for that? Twisted is the obvious solution for your problem, Overkill? Just to download a few web pages? You've got to be kidding. Better overkill (whatever that is) than wasting time re-implementing the same boring thing over and over for no reason. I need to download some web pages in parallel. Here's tremendously large and complex framework. Download, install, and learn this large and complex framework. Then you can write your very simple throwaway script with ease. Is the twisted solution even shorter? Doing this with threads I'm thinking would be on the order of 20 lines of code. The /already written/ solution I linked to in my original response was five lines shorter than that. Hmm. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistent list/pointer problem
Doug Stell a écrit : I am having a problem with the corruption of a list. It occurs only the first time that I call a function and never happens on subsequent calls. Any suggestions would be appreciated. I call the function, passing in a list as the input data. The function must manipulate and operate on a copy of that list's data, without altering the list in the calling routine. def myFunc(listA): listB = listA work on modify listB return(listB) return is a statement, not a function. Please remove these useless (and possibly harmful) parens. The first time this function touches listB, listA is corrupted. It's not. It's just that you did *not* copy listA - you just made listB reference the same object. I concluded that it appears that listB is still pointing at elements of listA It's even worse : both names listA and listB are pointing to the exact same object. listA = ['A', 'B', 'C'] listB = listA assert listA is listB and I need to force Python to reassign those pointers s/pointers/references/ to point to copies of listA's elements. copy.deepcopy() is your friend then. -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On Feb 1, 12:48 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Yeah, found that one googling around. But I haven´t fund anything more up to date. I imagine, that the performance of all of these wrappers has been improved since then. But the performance of Python/C API would too? Anyways, it´s not about exact number, it´s more about taking decision if doing rewrite is worth it´s time. The wrappers essentially create the boilerplate-code that invokes the Python C-API. So whatever improvements the latter has been developed, the wrappers will benefit from it. Without doubt it´s true in case of SWIG, but if I understand Python.Boost documentation correctly, it does *not* use Python/C API. I doubt that there are major performance penalties associated with any of them. Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/ europython2004_geus.pdf More important for a wrapper-decision is the question how easy they are to use. Well, SWIG is easy to use. But I´ve gotta make hundreds of millions of calls, which do tasks as simple, as getting one int from an array and returning it. With functions that simple SWIG´s overhead seems to be a problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On Feb 1, 9:20 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 1 Feb 2007 06:14:40 -0800, Carl Banks [EMAIL PROTECTED] wrote: On Jan 31, 3:37 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 31 Jan 2007 12:24:21 -0800, Carl Banks [EMAIL PROTECTED] wrote: Michele Simionato wrote: On Jan 31, 5:23 pm, Frank Potter [EMAIL PROTECTED] wrote: I want to find a multithreaded downloading lib in python, can someone recommend one for me, please? Thanks~ Why do you want to use threads for that? Twisted is the obvious solution for your problem, Overkill? Just to download a few web pages? You've got to be kidding. Better overkill (whatever that is) than wasting time re-implementing the same boring thing over and over for no reason. I need to download some web pages in parallel. Here's tremendously large and complex framework. Download, install, and learn this large and complex framework. Then you can write your very simple throwaway script with ease. Is the twisted solution even shorter? Doing this with threads I'm thinking would be on the order of 20 lines of code. The /already written/ solution I linked to in my original response was five lines shorter than that. And I suppose re-implementing the same boring thing over and over is ok if it's 15 lines but is too much to bear if it's 20 (irrespective of the additional large framework the former requires). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Problem saving changes in MoinMoin pages
[I'm having some difficulty contacting 'real' MoinMoin support channels so I am posting this question here. Hope that's ok.] I have a pressing need to get a wiki up and running in a fairly short timeframe. I did some investigations and the Python MoinMoin wiki seemed to be the best choice for me based on simplicity, the fact that I am already familiar with Python :-), it's free double :-) , and the installation was a snap! I'm having one initial problem however... When I edit a page and click 'Save', the next page that displays is an 'HTTP 500' error. I have to refresh the page to see the changes. I am missing something fundamental but I can't determin what it is as yet. I'm currently perusing the source code to see if I can figure it out, but any pre-help will be gladly accepted. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On 1 Feb 2007 06:41:56 -0800, Carl Banks [EMAIL PROTECTED] wrote: On Feb 1, 9:20 am, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 1 Feb 2007 06:14:40 -0800, Carl Banks [EMAIL PROTECTED] wrote: On Jan 31, 3:37 pm, Jean-Paul Calderone [EMAIL PROTECTED] wrote: On 31 Jan 2007 12:24:21 -0800, Carl Banks [EMAIL PROTECTED] wrote: Michele Simionato wrote: On Jan 31, 5:23 pm, Frank Potter [EMAIL PROTECTED] wrote: I want to find a multithreaded downloading lib in python, can someone recommend one for me, please? Thanks~ Why do you want to use threads for that? Twisted is the obvious solution for your problem, Overkill? Just to download a few web pages? You've got to be kidding. Better overkill (whatever that is) than wasting time re-implementing the same boring thing over and over for no reason. I need to download some web pages in parallel. Here's tremendously large and complex framework. Download, install, and learn this large and complex framework. Then you can write your very simple throwaway script with ease. Is the twisted solution even shorter? Doing this with threads I'm thinking would be on the order of 20 lines of code. The /already written/ solution I linked to in my original response was five lines shorter than that. And I suppose re-implementing the same boring thing over and over is ok if it's 15 lines but is too much to bear if it's 20 (irrespective of the additional large framework the former requires). It's written. Copy it and use it. There's no re-implementation to do. And if you don't want to _limit_ the number of concurrent connections, then you don't even need those 15 lines, you need four, half of which are imports. I could complain about what a waste of time it is to always have to import things, but that'd be silly. :) Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
Bart Ogryczak wrote: On Feb 1, 12:48 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Yeah, found that one googling around. But I haven´t fund anything more up to date. I imagine, that the performance of all of these wrappers has been improved since then. But the performance of Python/C API would too? Anyways, it´s not about exact number, it´s more about taking decision if doing rewrite is worth it´s time. The wrappers essentially create the boilerplate-code that invokes the Python C-API. So whatever improvements the latter has been developed, the wrappers will benefit from it. Without doubt it´s true in case of SWIG, but if I understand Python.Boost documentation correctly, it does *not* use Python/C API. It has to. In the end, marshalling data between e.g. python datastructures and C++ is done that way. I doubt that there are major performance penalties associated with any of them. Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/ europython2004_geus.pdf Ok, I see. I really wonder what SWIG does. Well, SWIG is easy to use. But I´ve gotta make hundreds of millions of calls, which do tasks as simple, as getting one int from an array and returning it. With functions that simple SWIG´s overhead seems to be a problem. Still I think you should first use wrappers for ease of use. Then when you hit a performance bottleneck, it might be worth wrapping that class manually. However, it _might_ of course be that this isn't integrating too seamless with the wrapped classes, but I can't say anything about that really. Diez -- http://mail.python.org/mailman/listinfo/python-list
Ubunu - Linux - Unicode - encoding
Hello NG, a little longer question, I'm working on our project DrPython and try fix bugs in Linux, (on windows, it works very good now with latin-1 encoding). On Windows, it works good now, using setappdefaultencoding and the right encoding for open with styled text control with the right encoding the files. (I see the german Umlauts äöü and the strong 's' ß) The case: I have a file on a WindowsXP partition which has as contents german umlauts and the filename itself has umlauts like iÜüäßk.txt If I want to append this file to a list, I get somehow latin-1, cannot decode 'utf-8'. sys.setappdefaultencoding(self.prefs.defaultencoding) would be the easiest solution which should be the same aus sys.setdefaultencoding in linux. Why is there a setappdefaultencoding on Windows and sys.setdefaultencoding on linux. I googled, and I found a strange solution (sys.setdefaultencoding is not available) import sys reload (sys) only then this function is available. Why is this setdefaultencoding otherwise not working on linux? (Also Filemanagers like Nautilus or Krusader cannot display the files correctly). Is there a system wide linux language setting (encoding), which I have to install and adjust? I know, there are the methods encode, unicode, decode, but how do I know, when they are needed, I don't want to replace all the source for encode, ... for string access. So setappdefaultencoding would be the easiest way. Should I use also/instead the wx.SetDefaultPyEncoding in DrPython? This would be the easiest solution, setappdefaultencoding, (getting it from preferences) but it doesn't work. Beside I tried other editors like spe, pype, boa, ulipad, but none of them displayed the file, which have german umlauts in the filesnames, correctly. Thank you vey much in advance for a possible solution. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python scripts to do parallel downloading?
On Feb 1, 12:40 am, Michele Simionato [EMAIL PROTECTED] wrote: On Jan 31, 9:24 pm, Carl Banks [EMAIL PROTECTED] wrote: Well, of all the things you can use threads for, this is probably the simplest, so I don't see any reason to prefer asynchronous method unless you're used to it. Well, actually there is a reason why I prefer the asynchronous approach even for the simplest things: I can stop my program at any time with CTRL-C. When developing a threaded program, or I implement a mechanism for stopping the threads (which should be safe enough to survive the bugs introduced while I develop, BTW), or I have to resort to kill -9, and I *hate* that. Especially since kill -9 does not honor try .. finally statements. In short, I prefer to avoid threads, *especially* for the simplest things. I use threads only when I am forced to, typically when I am using a multithreaded framework interacting with a database. Fair enough. I'm just saying that just because something is good for funded, important, enterprise tasks, it doesn't mean very simple stuff automatically has to use it as well. For Pete's sake, even Perl works for simple scripts. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On 2/1/07, Diez B. Roggisch [EMAIL PROTECTED] wrote: Bart Ogryczak wrote: On Feb 1, 12:48 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Yeah, found that one googling around. But I haven´t fund anything more up to date. I imagine, that the performance of all of these wrappers has been improved since then. But the performance of Python/C API would too? Anyways, it´s not about exact number, it´s more about taking decision if doing rewrite is worth it´s time. The wrappers essentially create the boilerplate-code that invokes the Python C-API. So whatever improvements the latter has been developed, the wrappers will benefit from it. Without doubt it´s true in case of SWIG, but if I understand Python.Boost documentation correctly, it does *not* use Python/C API. It has to. In the end, marshalling data between e.g. python datastructures and C++ is done that way. As I understand it, part of the Boost.Python internals is a C++ wrapper over the Python C api, and there's no separate code generation phase because it uses template magic to generate the wrappers. So while obviously the C API is used at some level, it's not visible to the wrapper author. I doubt that there are major performance penalties associated with any of them. Take a look at pages 23 and 24 of http://people.web.psi.ch/geus/talks/ europython2004_geus.pdf Ok, I see. I really wonder what SWIG does. SWIG generates a low-level C module, and then a Python one on top of it. It allows for quite some versatility in wrapping (because you can have (almost) arbitrary Python code generated). Most of the other tools generate a .pyd which you import directly. Well, SWIG is easy to use. But I´ve gotta make hundreds of millions of calls, which do tasks as simple, as getting one int from an array and returning it. With functions that simple SWIG´s overhead seems to be a problem. Still I think you should first use wrappers for ease of use. Then when you hit a performance bottleneck, it might be worth wrapping that class manually. However, it _might_ of course be that this isn't integrating too seamless with the wrapped classes, but I can't say anything about that really. Personally, I'd favor *correctness* first, then ease of use, and then speed. Diez -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Ubunu - Linux - Unicode - encoding
Il Thu, 01 Feb 2007 16:02:52 +0100, Franz Steinhaeusler ha scritto: The case: I have a file on a WindowsXP partition which has as contents german umlauts and the filename itself has umlauts like iÜüäßk.txt Could you please tell us a) which filesystem is that partition using (winxp may be installed on fat32 or ntfs partitions) and b) which driver are you using to read that partition (may be vfat, ntfs or fuse/ntfs-3g) and, last but not least, c) which options are passed to that driver? -- Alan Franzoni [EMAIL PROTECTED] - Togli .xyz dalla mia email per contattarmi. Remove .xyz from my address in order to contact me. - GPG Key Fingerprint (Key ID = FE068F3E): 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem saving changes in MoinMoin pages
Dan When I edit a page and click 'Save', the next page that displays is Dan an 'HTTP 500' error. I have to refresh the page to see the changes. ... Dan I'm currently perusing the source code to see if I can figure it Dan out, but any pre-help will be gladly accepted. You might check your web server error log for Python traceback or error info. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 hangs forever where there is no network interface
dumbkiwi [EMAIL PROTECTED] writes: I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with. So, can someone point me in the right direction, so that I can catch an exception where there is no network interface? Are you on Windows or something Unixy? Presumably Windows? (Unix systems almost always have at least a loopback interface) John -- http://mail.python.org/mailman/listinfo/python-list
Creating a simple arithmetic expressions tree
So I'm not sure how to write a code that could create a tree placing data at every node... and then retrieve that information as I go by a node... here is what I have ==CODE=== from itertools import izip class Node: def __init__(self, left, right): self.left = left self.right = right def __str__(self): return Node(%s, %s)%(self.left, self.right) = -- http://mail.python.org/mailman/listinfo/python-list
Re: Germany issues warrants for 13 American CIA agents
On Jan 31, 10:52 pm, Overlord [EMAIL PROTECTED] wrote: Fuck the Germans. Didn't we kick their ass a couple times already? OL Thank god, I can just get my world news from c.l.p instead of having to find another news site. I salute you [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Ubunu - Linux - Unicode - encoding
On 1 Feb, 16:02, Franz Steinhaeusler [EMAIL PROTECTED] wrote: The case: I have a file on a WindowsXP partition which has as contents german umlauts and the filename itself has umlauts like iÜüäßk.txt If I want to append this file to a list, I get somehow latin-1, cannot decode 'utf-8'. You mean that you expect the filename in UTF-8, but it arrives as ISO-8859-1 (Latin1)? How do you get the filename? Via Python standard library functions or through a GUI toolkit? What does sys.getfilesystemencoding report? [...] Why is this setdefaultencoding otherwise not working on linux? My impression was that you absolutely should not change the default encoding. Instead, you should react to encoding information provided by your sources of data. For example, sys.stdin.encoding tells you about the data from standard input. (Also Filemanagers like Nautilus or Krusader cannot display the files correctly). This sounds like a locale issue... Is there a system wide linux language setting (encoding), which I have to install and adjust? I keep running into this problem when installing various distributions. Generally, the locale needs to agree with the encoding of the filenames in your filesystem, so that if you've written files with UTF-8 filenames, you'll only see them with their proper names if the locale you're using is based on UTF-8 - things like en_GB.utf8 and de_AT.utf8 would be appropriate. Such locales are often optional packages, as I found out very recently, and you may wish to look at the language-pack-XX and language-pack-XX-base packages for Ubuntu (substituting XX for your chosen language). Once they are installed, typing locale -a will let you see available locales, and I believe that changing /etc/environment and setting the LANG variable there to one of the available locales may offer some kind of a solution. Another thing I also discovered very recently, after doing a debootstrap installation of Ubuntu, was that various terminals wouldn't reproduce non-ASCII characters without an appropriate (UTF-8) locale being set up, even though other desktop applications were happy to accept and display the characters. I thought this was a keyboard issue, compounded by the exotic nested X server plus User Mode Linux solution I was experimenting with, but I think locales were the main problem. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module for the IPod shuffle ...
hi simon: thanks a lot for that resource ... i downloaded it and tried to use it ... but when i try to import pypod, i get an error, which is as follows... ImportError: No module named _gpod I guess I have to do something more than merely putting the two files ( pypod.py and gpod.py) in my site-packages. what am i missing? thanks for your help. -ajay On 2/1/07, Simon Brunning [EMAIL PROTECTED] wrote: On 1/31/07, Analog Kid [EMAIL PROTECTED] wrote: Hi all: Im looking for a python module thatll let me do simple reads/writes from and to an iPod shuffle similar to iTunes ... I read about the gPod module ... but Im not sure whether it will work in Windows ... This any good? http://superduper.net/?page=pypod -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list -- BBQ - Spare (My) Ribs being contemplated -- http://mail.python.org/mailman/listinfo/python-list
Quad Perspective Transformation
I have a need to tile a bitmap across an arbitrary quadrilateral, and apply perspective to it. The Python Imaging Library (PIL) has an undocumented function that might work, but I can't figure out how to make it work. You're supposed to pass it 8 parameters, a b c d e f g h . What I want is to take a rectangular texture map and 'flop it down on the floor' - pinch in the left and right with perspective, and squash down the top with perspective. I've modified those 8 parameters and examined the results, but that hasn't brought me any closer to my goal. The PIL function is this: im2 = im.transform(im.size, Image.PERSPECTIVE, (1, 0, 0, 0, 1, -100, 0, .001), Image.BILINEAR) Here's hoping someone can shed some light on this function! -- http://mail.python.org/mailman/listinfo/python-list
Question about a single underscore.
I saw this and tried to use it: --8--- const.py- class _const: class ConstError(TypeError): pass def __setattr__(self,name,value): if self.__dict__.has_key(name): raise self.ConstError, Can't rebind const(%s)%name self.__dict__[name]=value import sys sys.modules[__name__]=_const() --8--- const.py- Then when I go to try to use it I'm supposed to say: const.pi= 3.14159 const.e = 2.7178 Two questions: 1. Why do I not have to say _const.pi= 3.14159 _const.e = 2.7178 and is this in the tutorial? 2. Can I make this behave in such a way that I can create my constants with a classname that is different for different uses? e.g., irrational_const.pi= 3.14159 irrational_const.e = 2.7178 even_const.first= 2 even_const.firstPlus= 4 TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net -- http://mail.python.org/mailman/listinfo/python-list
how to add class attributes in __new__
I am subclassing the array class and have __new__ to initialize and create my class. In that class I create not only do I create an array object, but I also create some other data in __new__ I want to have access to outside of __new__. I tried self.mydata = mydata but that didn't work. Can someone point me in the right direction? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me with this!!!
It search a text inside that hex value. It works perfecly on a txt file but if I open a binary file (.exe,.bin ecc...) with the same value it wont work, why? Please help! Because the pattern isn't in the file, perhaps. This pattern IS in the file (I made it and I double check with an hex editor). It display the file correcltly (print line) but... No! Peter is right. Regular expressions match ASCII representation of data, not hex. In simple terms, do you see your pattern when you open the file in notepad (or other text editor)? You do not use regex to search binary files. Ravi Teja. -- http://mail.python.org/mailman/listinfo/python-list
Python SECS-II module
Hi, I searching for a python module which implements SEMI E-4 / E-5 SECS-II/HSMS communication protocol. Is anyone have informations about this ? Regards, Laurent Laffont [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
Steven W. Orr [EMAIL PROTECTED] writes: --8--- const.py- ... sys.modules[__name__]=_const() __name__ is 'const' since this file is const.py. So you've juset set the const module to actually be a const instance. 1. Why do I not have to say _const.pi= 3.14159 const.pi refers to item 'pi' in the const module, which you've set in sys.modules above. 2. Can I make this behave in such a way that I can create my constants with a classname that is different for different uses? e.g., irrational_const.pi= 3.14159 Yes, irrational_const = _const() -- http://mail.python.org/mailman/listinfo/python-list
LDAP/LDIF Parsing
All, I am hoping someone would be able to help me with a problem. I have an LDAP server running on a linux box, this LDAP server contains a telephone list in various groupings, the ldif file of which is - dn: dc=example,dc=com objectClass: top objectClass: dcObject objectClass: organization dc: example o: Example Organisation dn: ou=groupa,dc=example,dc=com ou: groupa objectClass: top objectClass: organizationalUnit description: Group A dn: cn=johnsmith,ou=groupa,dc=example,dc=com cn: johnsmith objectClass: top objectClass: person sn: Smith telephoneNumber: 112 dn: cn=davesteel,ou=groupa,dc=example,dc=com cn: davesteel objectClass: top objectClass: person sn: Steel telephoneNumber: 113 dn: ou=groupb,dc=example,dc=com ou: groupb objectClass: top objectClass: organizationalUnit description: Group B dn: cn=williamdavis,ou=groupb,dc=example,dc=com cn: williamdavis objectClass: top objectClass: person sn: Davis telephoneNumber: 122 dn: cn=jamesjarvis,ou=groupb,dc=example,dc=com cn: jamesjarvis objectClass: top objectClass: person sn: Jarvis telephoneNumber: 123 I am creating a python client program that will display the telephone list in the same directory structure as is on the LDAP server (i.e. it starts with buttons of all the groups, when you click on a group it comes up with buttons of all the numbers or groups available, and you can continually drill down). I was wondering the best way to do this? I have installed and used the python-ldap libraries and these allow me to access and search the server, but the searches always return a horrible nesting of lists, tuples and dictionaries, below is an example of returning just one record - ('dc=example,dc=com', {'objectClass': ['top', 'dcObject', 'organization'], 'dc': ['example'], 'o': ['Example Organisation']}) Basically i think i need to parse the search results to create objects and build the python buttons around this, but i was hoping someone would be able to point me in the correct direction of how to do this? Is there a parser available? (there is an ldif library available but it is not obvious how this works, i cannot see much documentation, and it seems to be deprecated...). Many thanks. Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
On Feb 1, 5:52 pm, Steven W. Orr [EMAIL PROTECTED] wrote: I saw this and tried to use it: --8--- const.py- [...] sys.modules[__name__]=_const() __name__ == 'const', so you´re actually doing const = _const() -- http://mail.python.org/mailman/listinfo/python-list
Re: LDAP/LDIF Parsing
I was wondering the best way to do this? I have installed and used the python-ldap libraries and these allow me to access and search the server, but the searches always return a horrible nesting of lists, tuples and dictionaries, below is an example of returning just one record - ('dc=example,dc=com', {'objectClass': ['top', 'dcObject', 'organization'], 'dc': ['example'], 'o': ['Example Organisation']}) But this is exactly what your LDAP-record contains. What else should there be? And no, you don't need a parser, as the above _is_ the parsed result. No parser can possibly give you anything else. You can of course create wrapper-objects, that you instantiate based on the values in 'objectClass', and that allow convenient access to certain properties. Yet this is entirely up to you, as there is no one else who can forsee how things should look and work like in _your_ application. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On Feb 1, 3:21 am, Bart Ogryczak [EMAIL PROTECTED] wrote: Hi, I´m looking for some benchmarks comparing SWIG generated modules with modules made directly with C/Python API. Just how much overhead does SWIG give? Doing profile of my code I see, that it spends quiet some time in functions like _swig_setattr_nondinamic, _swig_setattr, _swig_getattr. This isn't exactly what you're looking for, but I tried SWIG a while ago, back when I still had a C compiler, and then decided to use c- types. The reason: I've got an aversion to anything that generates huge steaming piles of incomprehensible code. Especially when I found a couple of bugs in a SWIG-generated module I'd gotten from someone else. This wasn't SWIG's fault, it was the author's for not understanding the API he was wrapping properly, but I had to dig into the SWIG code before I could figure out what was going on. Bottom line: the c-types module was a lot smaller, in Python, and completely comprehensible. And while I didn't measure the performance, I doubt if it was slower. John Roth -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
John Bottom line: the c-types module was a lot smaller, in Python, and John completely comprehensible. And while I didn't measure the John performance, I doubt if it was slower. One advantage SWIG (or Boost.Python) has over ctypes is that it will work with C++. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: data design
James Stroud kirjoitti: snip For instance, I have a copy_files section of a configuration. In order to know what goes with what you have to resort to gymnastics with the option names [copy_files] files_dir1 = this.file that.file path_dir1 = /some/path files_dir2 = the_other.file yet_another.file path_dir2 = /some/other/path snip James You don't have to. With a config file: ### [copy_files] /some/path = this.file that.file C:\a windows\path with spaces= one.1 two.two a_continuation_line_starting_with_a_tab.xyz and_another_starting_with_a_some_spaces.abc /some/other/path = the_other.file yet_another.file ### the following program: ### #!/usr/bin/python import ConfigParser config = ConfigParser.ConfigParser() config.readfp(open(r'ConfigTest.INI')) opts = config.options('copy_files') print opts print 'Files to be copied:' for opt in opts: path = opt optVal = config.get('copy_files', opt) #print opt, optVal fileNames = optVal.split() ### The following lines are only needed for Windows ### because the use of ':' in Windows' file name's ### device part clashes with its use in ConfigParser pathParts = '' for ind in range(len(fileNames)): if fileNames[ind][-1] in ':=': path += ':' + pathParts + fileNames[ind][:-1] del fileNames[:ind+1] break pathParts += fileNames[ind] + ' ' ### Windows dependent section ends print 'Path:', '' + path + '' for fn in fileNames: print '' + fn + '' ### produces the following output: ### ['c', '/some/other/path', '/some/path'] Files to be copied: Path: c:\a windows\path with spaces one.1 two.two a_continuation_line_starting_with_a_tab.xyz and_another_starting_with_a_some_spaces.abc Path: /some/other/path the_other.file yet_another.file Path: /some/path this.file that.file ### Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Suggestions ?
Greetings, I am new to programming and have heard so much about Python. I have a couple of books on Python and have been to python.org many times. I am faced with a project at work where I need to develop a searchable database to include training materials for new hires.This will include descriptions of the apps we support along with information on which group supports them and will also include links within the descriptions to allow users to navigate to other pertinent information. I would like to lay the master directory out in an index format and would like to include a search window within the master index to provide a quick search to relative documents. I believe this is where Python will come in very handy as opposed to MS Access for example. I realize I may have to lay out the master index in an HTML format. I guess I have something else to learn now as well.Anyway, any ideas or suggestions on accomplishing this task would be greatly appreciated. Thank You in advance, Jeff James -- http://mail.python.org/mailman/listinfo/python-list
Marangozov's shmmodule (System V shared memory for Python IPC)
Hi all, In the late 90s Vladimir Marangozov wrote a module that provided an interface to System V shared memory on *nix platforms. I found a copy on the Net, dusted it off, compiled it, plugged a couple of memory leaks, intergrated others' changes, etc. Vlad hasn't posted on Usenet since the summer of 2000 and I can't find a working email address for him, so I assume this module is orphaned; this is a last-ditch effort to track him down before I post the module with my changes (retaining his name as the author of 99.9% of the code, of course). Does anyone know where I can contact Vladimir? The email addresses I can find for him don't work. If anyone knows him personally and would be kind enough to forward my email address ([EMAIL PROTECTED]) to him, I'd appreciate it. Thanks -- Philip http://NikitaTheSpider.com/ Whole-site HTML validation, link checking and more -- http://mail.python.org/mailman/listinfo/python-list
Heap problems in Mulithreaded Python extension
Hi, I'm near the ground and need help. I'm building a multithreaded extension with boost.python. python extension - import extension extension.init() -PyEval_InitThreads(); setup 3 threads (pthreads) and do a lot of things, but no python api calls while true: time.sleep(0.1) PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); So my questions: - Is it enough to do the following in the extension, regardless wich thread it does ? PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); What happens is, that inside the extension (C++) from time to time _CrtIsValidHeapPointer(...) fails. Any comments/experience on python and threaded extensions is very welcome. Alexander -- http://mail.python.org/mailman/listinfo/python-list
Re: Heap problems in Mulithreaded Python extension
ok, once more my scheme python extension - import extension extension.init() -PyEval_InitThreads(); setup 3 threads (pthreads) and do a lot of things, but no python api calls while true: time.sleep(0.1) PyGILState_STATE gGILState; gGILState = PyGILState_Ensure(); (...) // Do python API calls PyGILState_Release(gGILState); -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 hangs forever where there is no network interface
On Feb 2, 5:02 am, [EMAIL PROTECTED] (John J. Lee) wrote: dumbkiwi [EMAIL PROTECTED] writes: I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with. So, can someone point me in the right direction, so that I can catch an exception where there is no network interface? Are you on Windows or something Unixy? Linux Presumably Windows? (Unix systems almost always have at least a loopback interface) John Sorry, I should have been more specific. The network interfaces are up - ie lo and eth1, it's where the wireless connection has dropped out. Is the best solution to test for a wireless connection through / proc before trying to download data? -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG overhead
On 2/1/07, Chris Mellon [EMAIL PROTECTED] wrote: As I understand it, part of the Boost.Python internals is a C++ wrapper over the Python C api, That's true. and there's no separate code generation phase because it uses template magic to generate the wrappers. Well, actually it depends on the size of the project. If project is small you can use Boost.Python without a code generator. For big projects you have to use the code generator. The advantage is that generated code is pretty readable. So while obviously the C API is used at some level, it's not visible to the wrapper author. Boost.Python hides it pretty well :-) -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
On Thursday, Feb 1st 2007 at 09:25 -0800, quoth Bart Ogryczak: =On Feb 1, 5:52 pm, Steven W. Orr [EMAIL PROTECTED] wrote: = I saw this and tried to use it: = = --8--- const.py- =[...] = sys.modules[__name__]=_const() = =__name__ == 'const', so you?re actually doing =const = _const() So how can I say this in const.py? class _const: class ConstError(TypeError): pass def __setattr__(self,name,value): if self.__dict__.has_key(name): raise self.ConstError, Can't rebind const(%s)%name self.__dict__[name]=value def __init__(self): sys.modules[self]=_const() import sys to cause a different instantiation a la foo = _const() The goal would be to create different instances of consts. I did try the previous suggestion irrational_consts = _const() but I got import const iii=_const() Traceback (most recent call last): File stdin, line 1, in ? NameError: name '_const' is not defined * iii=const() Traceback (most recent call last): File stdin, line 1, in ? AttributeError: _const instance has no __call__ method For ref: class _const: class ConstError(TypeError): pass def __setattr__(self,name,value): if self.__dict__.has_key(name): raise self.ConstError, Can't rebind const(%s)%name self.__dict__[name]=value import sys sys.modules[__name__]=_const() -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net-- http://mail.python.org/mailman/listinfo/python-list
mysqldb duplicate entry error handling
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql=INSERT INTO emails (email) values ('%s') %(email) db=_mysql.connect(host = localhost, user = db_user, passwd = db_pass, db = db_name) try: db.query(sql) except IndentationError: print duplicate pass also try to (raise, continue) but can't continue in loop error output is: File inser_in_db.py, line 85, in email_insert_in_db db.query(sql) IntegrityError: (1062, Duplicate entry '[EMAIL PROTECTED]' for key 1) thanks for your help Baurzhan Zhakashev Kazakhstan / Shymkent city -- http://mail.python.org/mailman/listinfo/python-list
Re: mysqldb duplicate entry error handling
On 1 Feb 2007 10:17:31 -0800, baur79 [EMAIL PROTECTED] wrote: Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql=INSERT INTO emails (email) values ('%s') %(email) db=_mysql.connect(host = localhost, user = db_user, passwd = db_pass, db = db_name) try: db.query(sql) except IndentationError: print duplicate pass also try to (raise, continue) but can't continue in loop error output is: File inser_in_db.py, line 85, in email_insert_in_db db.query(sql) IntegrityError: (1062, Duplicate entry '[EMAIL PROTECTED]' for key 1) thanks for your help Baurzhan Zhakashev Kazakhstan / Shymkent city -- If you want to catch IntegrityError, why are you actually catching IndentationError? -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
Steven W. Orr [EMAIL PROTECTED] writes: to cause a different instantiation a la foo = _const() The goal would be to create different instances of consts. The idea of putting it in sys.modules is so it's visible in all modules. import const iii=_const() You need iii = const._const -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
On Thursday, Feb 1st 2007 at 10:36 -0800, quoth Paul Rubin: =Steven W. Orr [EMAIL PROTECTED] writes: = to cause a different instantiation a la = foo = _const() = The goal would be to create different instances of consts. = =The idea of putting it in sys.modules is so it's visible in all modules. = = import const = iii=_const() = =You need = iii = const._const =-- =http://mail.python.org/mailman/listinfo/python-list = 547 python Python 2.3.5 (#2, May 4 2005, 08:51:39) [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2 Type help, copyright, credits or license for more information. import const iii = const._const Traceback (most recent call last): File stdin, line 1, in ? AttributeError: _const instance has no attribute '_const' * iii = const._const() Traceback (most recent call last): File stdin, line 1, in ? AttributeError: _const instance has no attribute '_const' What am I missing here? (Sorry if it should be obvious) -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net -- http://mail.python.org/mailman/listinfo/python-list
Re: mysqldb duplicate entry error handling
now it gives this error except IntegrityError, NameError: NameError: global name 'IntegrityError' is not defined any idea i have python 2.3.2 installed -- http://mail.python.org/mailman/listinfo/python-list
Overloading the tilde operator?
I am trying to overload the __invert__ operator (~) such that it can take a second argument, other than self, so that I can express: x ~ y by using: def __invert__(self, other): do something for example. Is this possible? Thanks in advance, -- http://mail.python.org/mailman/listinfo/python-list
Re: mysqldb duplicate entry error handling
On 1 Feb 2007 10:51:09 -0800, baur79 [EMAIL PROTECTED] wrote: now it gives this error except IntegrityError, NameError: NameError: global name 'IntegrityError' is not defined any idea i have python 2.3.2 installed IntegrityError will most likely be defined in the namespace of whatever you're using for MySQL access. -- http://mail.python.org/mailman/listinfo/python-list
gdesklets question: import problem
Hi, sorry for posting here, but the forum in the projects page is not working. Maybe there is a gdesklet developer lurking... :-) I cant import anything from a script, it gives me a runtime error. is this a bug or a feature? without being able to import from python standard library or other modules, applets are rather limited in functionality... thanks, Flávio -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about a single underscore.
Steven W. Orr [EMAIL PROTECTED] writes: AttributeError: _const instance has no attribute '_const' What am I missing here? (Sorry if it should be obvious) Oh I see. No it's not obvious. module const has gotten overwritten by the _const instance. I think that module author was too clever for his or her own good. -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading the tilde operator?
Chris wrote: I am trying to overload the __invert__ operator (~) such that it can take a second argument, other than self, so that I can express: x ~ y by using: def __invert__(self, other): do something for example. Is this possible? No, you will get a syntax error before python even look up the names: x Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'x' is not defined x ~ x File stdin, line 1 x ~ x ^ SyntaxError: invalid syntax Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: how to make a python windows service know it's own identity
Chris Curvey wrote: Hi all, I have used the win32com libraries to set up a service called MyService under Windows. So far, so good. Now I need to run multiple copies of the service on the same machine. I also have that working. For monitoring and logging, I'd like each instance of the service to know it's own identity (MyService1, MyService2, etc.) But I can't quite seem to grasp how to do this. In the code below, the command line parameter -i gives the service an identity, but how do I get the service to understand it's identity when it is started? Many thanks! class MyService(win32serviceutil.ServiceFramework): NT Service. _svc_name_ = MyService _svc_display_name_ = My Service _id_ = '' def SvcDoRun(self): provider = MyServiceClass(identifier=self._id_) provider.start() # now, block until our event is set... win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE) # __init__ and SvcStop snipped ### if __name__ == '__main__': import optparse parser = optparse.OptionParser() parser.add_option(-i, --identifier, dest=identifier) (opts, args) = parser.parse_args() if opts.number is not None: MyService._svc_name_ += opts.identifier MyService._svc_display_name_ += opts.identifier MyService._provider_id_ = opts.identifier win32serviceutil.HandleCommandLine(MyService, customInstallOptions=i:) What is your use case for this? Why not make a single server process multiple providers (store them in a list or other container)? -Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Scrolling
On 2007-02-01 05:35:30 -0700, D [EMAIL PROTECTED] said: I'm sure this is a simple question to the Tkinter experts - I have a very basic Tkinter application that consists of 1 master window and buttons within that window. My problem is that, I need to be able to scroll (up and down) when I get to the point that the buttons go off the screen. What's the easiest way to do this? Thanks in advance. The super-easiest way is to make the background a Text() widget, add its scrollbars, then add the buttons and whatever else to it. Of course you are then limited to the 'typewriter layout' of widget placement. The typical way to do it is to make a scrolling canvas and pack the buttons and other stuff into an empty Frame() and then pack the frame on to the canvas, which I haven't had to do yet. Bob -- http://mail.python.org/mailman/listinfo/python-list
asyncore DoS vulnerability
Hi all. I've just terminated a server application using asyncore / asynchat frameworks. I wrote a test script that performs a lot of connections to the server app and I discovered that asyncore (or better, select()) can manage only a limited number of file descriptors (aka simultaneous connections). When this number is reached select() raises an error but asyncore doesn't handle this exception (a crash occurs). If you want to try this I pasted two scripts below: a server and a client. On my Windows XP system server.py the crash occurs when 512 simultaneous connections are reached. Here's the traceback: Traceback (most recent call last): File C:\Documents and Settings\root\Desktop\test.py, line 31, in ? asyncore.loop(timeout=1) File C:\Python24\lib\asyncore.py, line 192, in loop poll_fun(timeout, map) File C:\Python24\lib\asyncore.py, line 122, in poll r, w, e = select.select(r, w, e, timeout) ValueError: too many file descriptors in select() Why does this exception isn't handled inside asyncore.py? # server.py import asyncore, socket class server(asyncore.dispatcher): The base class for the backend. def __init__(self): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.bind(('', 8080)) self.listen(5) def handle_accept(self): sock_obj, addr = self.accept() handler(sock_obj) class handler(asyncore.dispatcher): def __init__(self, sock_obj): asyncore.dispatcher.__init__(self, sock=sock_obj) def handle_write(self): pass def handle_read(self): pass server() asyncore.loop(timeout=1) - # client.py import socket, threading, os def client(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((127.0.0.1, 8080)) except: print x os._exit(0) while 1: s.recv(1024) x = 0 while 1: x +=1 threading.Thread(target=client).start() print x -- http://mail.python.org/mailman/listinfo/python-list
Re: how to add class attributes in __new__
jeremito a écrit : I am subclassing the array class and have __new__ to initialize and create my class. In that class I create not only do I create an array object, but I also create some other data in __new__ I want to have access to outside of __new__. I tried self.mydata = mydata but that didn't work. Can someone point me in the right direction? http://www.python.org/download/releases/2.2.3/descrintro/#__new__ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to make a python windows service know it's own identity
On Feb 1, 2:10 pm, Larry Bates [EMAIL PROTECTED] wrote: Chris Curvey wrote: Hi all, I have used the win32com libraries to set up a service called MyService under Windows. So far, so good. Now I need to run multiple copies of the service on the same machine. I also have that working. For monitoring and logging, I'd like each instance of the service to know it's own identity (MyService1, MyService2, etc.) But I can't quite seem to grasp how to do this. In the code below, the command line parameter -i gives the service an identity, but how do I get the service to understand it's identity when it is started? Many thanks! class MyService(win32serviceutil.ServiceFramework): NT Service. _svc_name_ = MyService _svc_display_name_ = My Service _id_ = '' def SvcDoRun(self): provider = MyServiceClass(identifier=self._id_) provider.start() # now, block until our event is set... win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE) # __init__ and SvcStop snipped ### if __name__ == '__main__': import optparse parser = optparse.OptionParser() parser.add_option(-i, --identifier, dest=identifier) (opts, args) = parser.parse_args() if opts.number is not None: MyService._svc_name_ += opts.identifier MyService._svc_display_name_ += opts.identifier MyService._provider_id_ = opts.identifier win32serviceutil.HandleCommandLine(MyService, customInstallOptions=i:) What is your use case for this? Why not make a single server process multiple providers (store them in a list or other container)? -Larry Bates The use case is that I have a queue of jobs that need to run. My service connects to a central distributor server, which hands out jobs to complete. I'd like to be able to run multiple copies of the distributed service so that I can make the most use of each machine where they run. (I'm not certain of the thread safety of some of the libraries I'm using, so I'm leery of going the multi-threaded route) Anyway, when my service gets a job to process, I'd like to know which copy of the service is working on which job. So I want my log messages to look like this: Job 123: Host: alpha Service: MyService A Job 124: Host: alpha Service: MyService B Job 124: Host: beta Service: MyService C Is that clear, or have I muddied the waters? -- http://mail.python.org/mailman/listinfo/python-list