read file with multiple data per line
Hello all, I googled a lot but couldn't find anything that i could consider a possible solution (though i am fairly new to the language and i think this is the main cause of my failure). This is the beginning of the file i have to parse: Modified System 32728 2NHST1 C1 56 3.263 2.528 16.345 and this is the end: 3.65396.4644 20. This line has 7 formatted fields [5 digits integer, 5 digits character, 5 digits character, 5 digits integer, three %8.3f fields]: 2NHST1 C1 56 3.263 2.528 16.345 and this one has 3 %10.4f fields: 3.65396.4644 20. Those rules cannot be ignored or the programs i use to simulate and analyze the results wont work. This file describes the xyz coordinates and atom type of all the atoms of the "system" i wish to simulate but i must sort all groups of molecules together and that's what i planned to do with a python code. I tried to accomplish this task using fortran wich is my main coding skills, but it proved to be unstable so i decided to handle files using a more apropriate languange while maintaining the number crunching tasks written in fortran. Thanks in advance and i apologise for eventual typos. Eduardo Martins -- http://mail.python.org/mailman/listinfo/python-list
Re: read file with multiple data per line
On Apr 14, 12:32 am, Steven D'Aprano wrote: > On Tue, 14 Apr 2009 00:15:18 -0700, Eduardo wrote: > > Hello all, > > > I googled a lot but couldn't find anything that i could consider a > > possible solution (though i am fairly new to the language and i think > > this is the main cause of my failure). > > You haven't actually said what the problem is. What are you having > trouble doing? > > -- > Steven Sorry for that Steven, my main problem is to devise a way to read all the content of that file into a dictionary or other structure where i could group atoms by molecule name. On Apr 14, 4:49 am, Piet van Oostrum wrote: > >>>>> Eduardo (E) wrote: > >E> Hello all, > >E> I googled a lot but couldn't find anything that i could consider a > >E> possible solution (though i am fairly new to the language and i think > >E> this is the main cause of my failure). > >E> This is the beginning of the file i have to parse: > >E> Modified System > >E> 32728 > >E> 2NHST1 C1 56 3.263 2.528 16.345 > >E> and this is the end: > >E> 3.6539 6.4644 20. > >E> This line has 7 formatted fields [5 digits integer, 5 digits > >E> character, 5 digits character, 5 digits integer, three %8.3f fields]: > >E> 2NHST1 C1 56 3.263 2.528 16.345 > >E> and this one has 3 %10.4f fields: > >E> 3.6539 6.4644 20. > >E> Those rules cannot be ignored or the programs i use to simulate and > >E> analyze the results wont work. > >E> This file describes the xyz coordinates and atom type of all the atoms > >E> of the "system" i wish to simulate but i must sort all groups of > >E> molecules together and that's what i planned to do with a python code. > >E> I tried to accomplish this task using fortran wich is my main coding > >E> skills, but it proved to be unstable so i decided to handle files > >E> using a more apropriate languange while maintaining the number > >E> crunching tasks written in fortran. > > I understand that the first two lines are special and that the third > line, or the third and fourth lines are repeated. > > Something like this will parse the lines. After each line you can > process the f* variables. > > inp = open('testinput', 'rt') > > line1 = inp.readline() > line2 = inp.readline() > > for line in inp: > line = line.rstrip('\n') > if len(line) == 44: > f1 = int(line[0:5]) > f2 = line[5:10] > f3 = line[10:15] > f4 = int(line[15:20]) > f5 = float(line[20:28]) > f6 = float(line[28:36]) > f7 = float(line[36:44]) > print f1,f2,f3,f4,f5,f6,f7 > elif len(line) == 30: > f1 = float(line[0:10]) > f2 = float(line[10:20]) > f3 = float(line[20:30]) > print f1,f2,f3 > else: > print("Sorry, I don't understand this format: %s" % line) > > -- > Piet van Oostrum > URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4] > Private email: p...@vanoostrum.org Thank you very much Piet, i will try your sugestion. -- http://mail.python.org/mailman/listinfo/python-list
Re: strip bug?
Well, from the docstring of strip: -- S.strip([chars]) -> string or unicode Return a copy of the string S with leading and trailing whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is unicode, S will be converted to unicode before stripping -- In this case 'http://thunder'.strip('http://') is the same as 'http://thunder'.strip('htp:/') and any character of the string that is passed to the method will be removed. -- https://mail.python.org/mailman/listinfo/python-list
Re: Unexpected python exception
Em Qua 11 Nov 2009, às 03:21:55, Diez B. Roggisch escreveu: > Richard Purdie schrieb: > > I've been having problems with an unexpected exception from python which > > I can summarise with the following testcase: > > > > def A(): > > import __builtin__ > > import os > > > > __builtin__.os = os > > > > def B(): > > os.stat("/") > > import os > > > > A() > > B() > > > > which results in: > > > > Traceback (most recent call last): > > File "./test.py", line 12, in > > B() > > File "./test.py", line 8, in B > > os.stat("/") > > UnboundLocalError: local variable 'os' referenced before assignment > > > > If I remove the "import os" from B(), it works as expected. > > > >>From what I've seen, its very unusual to have something operate > > > > "backwards" in scope in python. Can anyone explain why this happens? > > As the import-statement in a function/method-scope doesn't leak the > imported names into the module scope, python treats them as locals. > Which makes your code equivalent to > > > x = 1000 > > def foo(): > print x > x = 10 > > Throws the same error. The remedy is to inform python that a specific > name belongs to global scope, using the "global"-statement. > > def foo(): > global x > print x > x = 10 > > > Beware though that then of course *assigning* to x is on global level. > This shouldn't be of any difference in your case though, because of the > import-only-once-mechanics of python. > > Diez > So...it should not work def A(): import __builtin__ import os __builtin__.os = os A() os.stat("/") but it does. Why ? B() cannot see the import, but the global level can ? Thanks. Eduardo. -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
[ANN] doit 0.5
doit - Automation Tool doit comes from the idea of bringing the power of build-tools to execute any kind of task. It will keep track of dependencies between "tasks" and execute them only when necessary. It was designed to be easy to use and "get out of your way". doit can be used as: * a build tool (generic and flexible) * home of your management scripts (it helps you organize and combine shell scripts and python scripts) * a functional tests runner (combine together different tools) homepage: http://python-doit.sourceforge.net/ PyPi: http://pypi.python.org/pypi/doit license: MIT contact: https://launchpad.net/~schettino72 Regards, Eduardo -- http://mail.python.org/mailman/listinfo/python-list
ANN: doit 0.2.0 released
doit comes from the idea of bringing the power of build-tools to execute any kind of task. It will keep track of dependencies between “tasks” and execute them only when necessary. It was designed to be easy to use and “get out of your way”. check the new website http://python-doit.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Install NumPy in python 2.6
On Wednesday 22 April 2009 04:47:54 David Cournapeau wrote: > On Wed, Apr 22, 2009 at 6:38 PM, Ole Streicher wrote: > > Unfortunately, www.netlib.org is not reachable, so I cannot try to > > install lapack. > > > > What is the reason for that? > > I don't know, I think netlib.org will be back soon. You need LAPACK > for scipy, it is not possible to build it without it. I believe suse > has a package for it, though. > > David > -- > http://mail.python.org/mailman/listinfo/python-list try ATLAS instead. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: ODE, GUI, plotter in Python
Em Ter 16 Jun 2009, às 09:00:02, Ala escreveu: > Hello everyone. > > I am starting on implementing a simulator using python, and since it's > the first time I code in python would appreciate a few pointers: > > The simulator will use a coupled ODE for the most part of the > simulation, I plan to use scipy. (Anything considered faster/better > than scipy for solving coupled ODEs? ) > > I plan for a GUI program with network graph plotting. I am leaning > towards using Qt for the GUI (internet forums seem to recommend it, > anyone got other preferences? ) > > Since the GUI application will contain few buttons and a plot, I am > planning to implement matplotlib into the GUI. But does anyone know if > matplotlib allows for interaction with the graph plot? (say for a > network simulation, allowing to right click on nodes and disable them > for instance, or alter some other properties of nodes and/or links > across them). > > I am just starting out, hence I'd rather get some advice and experiment > a bit for my self as I go along. > > Thank you. you should take a look at http://pyode.sourceforge.net/ and pygame. []'s Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing in PDF
Em Seg 29 Jun 2009, às 20:39:22, Lawrence D'Oliveiro escreveu: > In message > d7fe56d05...@g19g2000yql.googlegroups.com>, Jun wrote: > > ... is there open source solution ? > > Poppler? pypdf -- http://pybrary.net/pyPdf/ A Pure-Python library built as a PDF toolkit. It is capable of: * extracting document information (title, author, ...), * splitting documents page by page, * merging documents page by page, * cropping pages, * merging multiple pages into a single page, * encrypting and decrypting PDF files. By being Pure-Python, it should run on any Python platform without any dependencies on external libraries. It can also work entirely on StringIO objects rather than file streams, allowing for PDF manipulation in memory. It is therefore a useful tool for websites that manage or manipulate PDFs. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing in PDF
Em Ter 30 Jun 2009, às 04:19:13, Grant Edwards escreveu: > On 2009-06-30, Eduardo Lenz wrote: > > Em Seg 29 Jun 2009, às 20:39:22, Lawrence D'Oliveiro escreveu: > >> In message >> > >> d7fe56d05...@g19g2000yql.googlegroups.com>, Jun wrote: > >> > ... is there open source solution ? > >> > >> Poppler? > > > > pypdf -- http://pybrary.net/pyPdf/ > > > > > > A Pure-Python library built as a PDF toolkit. It is capable of: > > > > * extracting document information (title, author, ...), > > * splitting documents page by page, > > * merging documents page by page, > > * cropping pages, > > * merging multiple pages into a single page, > > * encrypting and decrypting PDF files. > > While it may be a pure-python library, the problem is that > AFAICT it doesn't actually solve the problem at hand. The > requirement is to "draw" on the pages of an existing PDF > document (add annotations). > > > By being Pure-Python, it should run on any Python platform > > without any dependencies on external libraries. It can also > > work entirely on StringIO objects rather than file streams, > > allowing for PDF manipulation in memory. It is therefore a > > useful tool for websites that manage or manipulate PDFs. > > True, but does it allow you to add text/lines/etc. to a page? being a pure python library makes "easy" to add those features. And also, one can ask for those features for the developers. I think that this list is a good place to point the existing solutions (not always the exact solution) and also to collect valuable information about python libraries. Please, lets keep in mind that this is not the debian list :). []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: psyco V2
Em Qui 16 Jul 2009, às 19:48:18, Christian Tismer escreveu: > Announcing Psyco V2 source release > -- > > This is the long awaited announcement of Psyco V2. > > Psyco V2 is a continuation of the well-known psyco project, > which was called finished and was dis-continued by its author > Armin Rigo in 2005, in favor of the PyPy project. > > This is a new project, using Psyco's code base with permission > of Armin. Questions and complaints should go to me > (tis...@stackless.com) or the mailing list > (psyco-de...@lists.sourceforge.net); > Armin is explicitly not in charge of (t)his project any longer! > > As one of the founders and an active member of the PyPy > project, I was very happy to be invited to work on Psyco > V2, by FATTOC, LLC. Psyco V2 tries to extend on the original Psyco > approach "an extension module that just makes Python faster". > > Psyco is a just-in-time compiler that accelerates arbitrary > Python code by specialization. We believe that Psyco's approach > can be carried out much further than it was tried so far, when > it's first version was abandoned. > > This first V2 release is source-only. There is no web-site, yet, > and there are no binaries for download. These will be available > in a few days on http://www.psyco.org . > > For the time being, please stick with subversion access, > building the extension module from source code. The repository > is here: > > http://codespeak.net/svn/psyco/v2/dist > > Check-out the repository, and run the setup.py script, > given that you have access to a C compiler. > > Psyco V2 will run on X86 based 32 bit Linux, 32 bit Windows, > and Mac OS X. Psyco is not supporting 64 bit, yet. But it > is well being considered. > > The current improvements are, shortly: > >- Support for Python 2.4, 2.5 and 2.6 >- a lot of new builtins >- generators, fast and fully supported. > > More information is coming soon on http://www.psyco.org . > > This is the beginning of a series of new Psyco versions. > Many more improvements are prepared and about to be published, > soon, starting with the current version 2.0.0 . > > Stay tuned, this is just the beginning of psyco's re-birth! > > For questions about Psyco V2, please join the mailing list > > psyco-de...@lists.sourceforge.net > > or contact me on IRC: > > #psyco on irc.freenode.net . > > Psyco V2 is fundamentally supported by FATTOC, LLC. > See http://www.fattoc.com . > > Without their continuous support, this work would not have > been possible at all. I wish to express my deepest thanks > to FATTOC, for allowing me to continue on Psyco with all the > energy that this ambitious project needs, and will need. > > Further special thanks are going to > Armin Rigo, John Benediktsson, David Salomon, Miki Tebeka, > Raymond Hettinger, Fabrizio Milo, Michael Foord, > Dinu Gherman, Stephan Diehl, Laura Creighton and Andrea Tismer, > for all the support and discussions. > > Looking forward to a great future of Psyco! > > July 17, 2009 I know its not the proper list but gcc -pthread -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -DNDEBUG - g -O3 -fPIC -Ic/i386 -Ic -I/usr/include/python2.6 -c c/mergepoints.c -o build/temp.linux-i686-2.6/c/mergepoints.o c/mergepoints.c:250: error: ‘RAISE_VARARGS’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘JUMP_IF_FALSE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘JUMP_IF_TRUE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘DUP_TOPX’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘IMPORT_STAR’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘SLICE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘STORE_SLICE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘DELETE_SLICE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘PRINT_EXPR’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘PRINT_ITEM’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘PRINT_ITEM_TO’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘PRINT_NEWLINE’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘PRINT_NEWLINE_TO’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘BUILD_CLASS’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘IMPORT_NAME’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘IMPORT_FROM’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘MAKE_FUNCTION’ undeclared here (not in a function) c/mergepoints.c:250: error: ‘BUILD_SLICE’ undeclared here (not in a function) error: command 'gcc' failed with ex
Re: Wanted: Python solution for ordering dependencies
On Sun, Apr 25, 2010 at 4:53 AM, Jonathan Fine wrote: > Hi > > I'm hoping to avoid reinventing a wheel (or other rolling device). I've got > a number of dependencies and, if possible, I want to order them so that each > item has its dependencies met before it is processed. > > I think I could get what I want by writing and running a suitable makefile, > but that seems to be such a kludge. > > Does anyone know of an easily available Python solution? http://pypi.python.org/pypi/doit -- http://mail.python.org/mailman/listinfo/python-list
Re: Wanted: Python solution for ordering dependencies
On Sun, Apr 25, 2010 at 11:44 PM, Jonathan Fine wrote: > Eduardo Schettino wrote: >> >> On Sun, Apr 25, 2010 at 4:53 AM, Jonathan Fine wrote: >>> >>> Hi >>> >>> I'm hoping to avoid reinventing a wheel (or other rolling device). I've >>> got >>> a number of dependencies and, if possible, I want to order them so that >>> each >>> item has its dependencies met before it is processed. >>> >>> I think I could get what I want by writing and running a suitable >>> makefile, >>> but that seems to be such a kludge. >>> >>> Does anyone know of an easily available Python solution? >> >> http://pypi.python.org/pypi/doit > > > Thank you for this, Eduardo. However, all I require is a means of ordering > the items that respects the dependencies. This rest I can, and pretty much > have to, manage myself. > > So probably something more lightweight would suit me. you just want a function? def order_tasks(tasks): ADDING, ADDED = 0, 1 status = {} # key task-name, value: ADDING, ADDED task_order = [] def add_task(task_name): if task_name in status: # check task was alaready added if status[task_name] == ADDED: return # detect cyclic/recursive dependencies if status[task_name] == ADDING: msg = "Cyclic/recursive dependencies for task %s" raise Exception(msg % task_name) status[task_name] = ADDING # add dependencies first for dependency in tasks[task_name]: add_task(dependency) # add itself task_order.append(task_name) status[task_name] = ADDED for name in tasks.keys(): add_task(name) return task_order if __name__ == '__main__': task_list = {'a':['b','c'], 'b':['c'], 'c':[]} print order_tasks(task_list) -- http://mail.python.org/mailman/listinfo/python-list
[ANN] doit - automation tool 0.8 released
pypi: http://pypi.python.org/pypi/doit homepage: http://python-doit.sourceforge.net/ `doit` comes from the idea of bringing the power of build-tools to execute any kind of task. It will keep track of dependencies between "tasks" and execute them only when necessary. It was designed to be easy to use and "get out of your way". Features: * Easy to use, "no-API" * Use python to dynamically create tasks on-the-fly * Flexible, adapts to many workflows for creation of tasks/rules/recipes * Support for multi-process parallel execution * Built-in integration of inotify (automatically re-execution) `doit` can be used as: * a build tool (generic and flexible) * home of your management scripts (it helps you organize and combine shell scripts and python scripts) * a functional tests runner (combine together different tools) -- http://mail.python.org/mailman/listinfo/python-list
confusing error with nntplib
When trying to use nntplib to connect to the news server nntp.aioe.org, a bizarre sequence of events occurs: 1) I import the module, and create an instance, as follows: s = nntplib.NNTP('nntp.aioe.org') I get no errors, which leads me to believe all went well. The I try fetching info on a newsgroup (in this case, comp.lang.python): s.group('comp.lang.python') I then get the following error: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/nntplib.py", line 345, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python2.6/nntplib.py", line 259, in shortcmd return self.getresp() File "/usr/lib/python2.6/nntplib.py", line 214, in getresp resp = self.getline() File "/usr/lib/python2.6/nntplib.py", line 206, in getline if not line: raise EOFError EOFError Running this a *second* time, gives me the following, different error: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/nntplib.py", line 345, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python2.6/nntplib.py", line 258, in shortcmd self.putcmd(line) File "/usr/lib/python2.6/nntplib.py", line 198, in putcmd self.putline(line) File "/usr/lib/python2.6/nntplib.py", line 193, in putline self.sock.sendall(line) File "", line 1, in sendall socket.error: [Errno 32] Broken pipe As this is a broken pipe, I reconnect to the server, the same way as before. When I *then* retrieving the newsgroup's info, I get no errors. I'm pretty baffled by this. It might be an issue with the server itself, but still, any input would be very appreciated. yours, -- Eduardo Alvarez "Stercus, Stercus, Stercus, moriturus sum" -- Rincewind The Wizzard -- http://mail.python.org/mailman/listinfo/python-list
Nautilus Python
I'm a python noob and wrote the following code for a nautilus extension: #!/usr/local/bin/python # -*- coding: utf-8 -*- import urllib import gtk import pygtk import nautilus import gconf import gtk.glade class Slide (nautilus.MenuProvider): f = None def __init__(self): self.client = gconf.client_get_default() self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() def oi (self): self.window.show() def menu_activate_cb(self, menu, file): self.oi() def get_file_items(self, window,files): if len(files) != 1: return item = nautilus.MenuItem('NautilusPython::slide_file_item','Slide','Slide') item.connect('activate', self.menu_activate_cb, files[0]) return item, def get_background_items(self, window, file): item = nautilus.MenuItem('NautilusPython::slide_item','Slide','Slide') item.connect('activate', self.menu_background_activate_cb, file) return item, def menu_background_activate_cb(self, menu, file): self.oi() But it doesn't work. If I comment the lines: self.f = gtk.glade.XML( "papel.glade" ) self.window = self.f.get_widget("window1") gtk.main() the code works but I can't see any problem in those lines. Any help? -- http://mail.python.org/mailman/listinfo/python-list
Using PSE under Win32
Hello, I've been playing around with mod_python these days (using Publisher and PSP), and it has been working smoothly under Windows XP (using Apache 2.2). But when I installed PSE and went to use it with mod_python, it didn't work. The error I get whenever I try to load a PSE page is: Traceback (most recent call last): File "C:\Python25\lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "C:\Python25\lib\site-packages\mod_python\importer.py", line 1229, in _process_target result = _execute_target(config, req, object, arg) File "C:\Python25\lib\site-packages\mod_python\importer.py", line 1128, in _execute_target result = object(arg) TypeError: 'module' object is not callable I thought it could be some incompatibility issue between PSE and mod_python, but I tried both installing the PSE binary and building the sources, and it didn't make a difference. Has anyone out there had success using PSE under Windows? (Just for the record, I did install matching versions, at least for Apache (2.2.3), Python (2.5) and mod_python (3.3.1). PSE doesn't seem to have a strict version requirement.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Do eval() and exec not accept a function definition? (like 'def foo: pass) ?
Hey, I think you could use lambda functions for that matter (Ever heard of them?). You could write something like: def generate_html_tag_function(tag_name, start_or_end): start_or_end.lower() assert(start_or_end in ('start', 'end')) if start_or_end == 'start': function = lambda: '<' + tag_name + '>' else: function = lambda: '' return function Then you would create the functions using the same code you had written before: start_html = generate_html_tag_function('html', 'start') start_body = generate_html_tag_function('body', 'start') end_html = generate_html_tag_function('html', 'end') end_body = generate_html_tag_function('body', 'end') That seems to do what you want. Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Using PSE under Win32
On 24 jun, 21:19, Graham Dumpleton <[EMAIL PROTECTED]> wrote: > What do you have PythonHandler set to and what does it identify? The > error above suggests that whatever you identify as the handler is not > a callable object like a function. Are you perhaps identifying some > sort of PSE template object as target when you shouldn't be? Post your > handler code so we can see it. > > Graham Hello, thanks for the answer. I just found the problem. I had written in my Apache conf PythonHandler pse_handler because I had seen it in PSE manual. But now I tried to google some more and found this wiki page <http://trac.gerf.org/pse/wiki/ PSE4Setup> that says that I should instead write PythonHandler pse_handler::mp_handler Apparently this behaviour changed in 4.0 beta (I found no mention to it in PSE's official site), but I'm almost sure the same error happened when I installed 3.0.6 and tried to run a test script. Anyway, I think that's it for now. Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Libraries in python
Hy people, I'm new in python and comming from JAVA. Something I really like in java is the easy way to add a library to the project. Just put the jar file in the folder ( WEB-INF/lib ) and doesn't need to restart the server ( tomcat ). Can I do some like using python - I'm using apache mod_python? thanks a lot -- http://mail.python.org/mailman/listinfo/python-list
Extending and Embedding
How can I load a module (written in C as a shared library (.so)) through "PyRun_SimpleString"? I've tried "from import *", but a got a message: ImportError: No module named Thanks in advance. Erocha Yahoo! Mail - Com 250MB de espaço. Abra sua conta! http://mail.yahoo.com.br/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Extending and Embedding
Sorry, I guess that I wasn't clear. I've made a module using swig that wrap functions written in C. If I load that module in python using: >>> from import * it works fine. But if I execute this same command using PyRun_SimpleString in another code written in C, it doesn't work, i.e. I can't load a module (made by swig) in a embedding code. Erocha --- "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Eduardo Rodrigues wrote: > > > How can I load a module (written in C as a shared > > library (.so)) through "PyRun_SimpleString"? > > > > I've tried "from import *", but a got a > > message: ImportError: No module named > > You can't do this. You have to either wrap the > module - which is possible in > several ways, including hand-written code, pyrex, > swig and sip. Maybe even > more, I don't know. > > Or you access it using the module ctypes that allows > to invoke arbitrary > methods/funtctions of C-libs. google for it. > -- > Regards, > > Diez B. Roggisch > -- > http://mail.python.org/mailman/listinfo/python-list > Yahoo! Mail - Com 250MB de espaço. Abra sua conta! http://mail.yahoo.com.br/ -- http://mail.python.org/mailman/listinfo/python-list
newbie, help with pythonpath
Hi all, In order not to make a mess my system, i have installed a packaged called pygtkglext in /usr/local/pygtkglext instead of /usr/local (using the --prefix in ./configure). Hence, i have the directories /usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gtkgl /usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk-2.0/gtk/gdkgl with the python packages i have compiled. I'm trying to set the python path variable so i can use them, but i haven't got it. Any hint? I have also installed the gtk package in: /usr/lib/python2.3/site-packages/gtk-2.0/gtk Is there a way to make it work? Thanks a lot, -Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie, help with pythonpath
What do i need to add to the path? I have already tried the same with the PYTHONPATH variable. Thanks in advance, -Eduardo [otto:eduardo/ 501]$ python Python 2.3.5 (#2, Feb 9 2005, 00:38:15) [GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append('/usr/local/pygtkglext-1.0.1') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk -2.0') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk -2.0/gtk') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> sys.path.append('/usr/local/pygtkglext-1.0.1/lib/python2.3/site-packages/gtk -2.0/gtk/gtkgl') >>> import gtk.gtkgl Traceback (most recent call last): File "", line 1, in ? ImportError: No module named gtkgl >>> Chmouel Boudjnah wrote: Eduardo Suarez wrote: I'm trying to set the python path variable so i can use them, but i haven't got it. Any hint? sys.path.append('/usr/blah/blah/blah/directory') -- http://mail.python.org/mailman/listinfo/python-list
Function parameter passing problem
Hi, I am new to python and tried to pass parameters between one function to another. I tried two approaches in doing this but failed. The first is, I tried to assign a variable in foo1() inside an HTML tag so that I can retreive it in foo2() using (get_form_var()). But failed using my limited python knowledge. The sample code. def foo1(request, result) ... ... Id_No, FirstName, LastName = result """ .. .. # I would like to assign Id_No variable to id. ... .. """ The second is, I tried using "return Id_No" statement foo2() function using a return statement below the tag. I tried this option but unfortunately when I hit the SUBMIT button it only displayed the variable and got stucked and didn't continue to the called foo2(). I also have a problem with my user defined function foo2() which I created at first with one parameter to accept the variable of foo1(). But when I added another parameter to accomodate some more and executed the code, an error message TypeError: foo2() takes exactly 2 arguments (1 given). I thought I can put as many parameters I could since this is user defined function, am I correct in this? I have no more options to this problem, hope you will help me . Thank you in advance. Cheers! Ed Discover Yahoo! Have fun online with music videos, cool games, IM and more. Check it out! http://discover.yahoo.com/online.html -- http://mail.python.org/mailman/listinfo/python-list
Called function conditional testing (if) of form variables problem
Hi, I have a problem making conditional testing (if) of a form variable "ans01"(refer generated error). When the form variable is tested (if) by a called function (foo) the value of "ans01" is not properly represented. def foo(request): ans01 = request.get_form_var("ans01") if ans01 == 4: ans_1 = 1 return ans_1 The browser returns a blank screen or ans_1 is blank. I tried to "return ans01" and the browser returned the number 4. I am quiet sure of the above code and searched python resources but found no solution. Please help. Thank you in advance. ** Below is a generated error to check the contents of submitted form. ___ .. NameError: ... Form: ans01 4 ans02 1 ans03 1 ans04 1 ans05 1 ans06 1 ans07 1 comments headid 068A114 id 0646205 submit Submit *** __ Discover Yahoo! Get on-the-go sports scores, stock quotes, news and more. Check it out! http://discover.yahoo.com/mobile.html -- http://mail.python.org/mailman/listinfo/python-list
problem writing to a file each record read
I am a python newbie and I have a problem with writing each record read to a file. The expected output is 10 rows of records, but the actual output of the code below is only one row with a very long record (10 records are lump into one record). Thank you in advance for your help. Here is the code: infile = open('c:/grad3650txt.csv', 'r') outfile = open('c:/idmast01.txt', 'w') a = 1 b = 10 for line in infile.readlines(): if a <= b: c1 = line.find(',',0) ln = line[1:c1] l2 = line.find('"', c1) l2a = l2 - 1 l2c = l2 if line[l2a] == '.': l2b = l2 - 3 if line[l2b] == ' ': mi = line[l2b+1:l2a+1] l2c = l2b else: mi = ' ' l2c = l2 fn = line[c1+2:l2c] c2 = line.find(',', l2) c3 = line.find(',', c2+1) deg = line[c2+1:c3] l5 = len(line) c4 = line.find(',', c3+1) l7 = c3 + 14 if l5 <= l7 or c4 <= l5: l8 = l5 if c4 <= l5: dat = line[c3+1:c4] #--- # This is the problem code. Ten records # is lump into 1 row and written # in the output file. # # My expected output is 10 rows. #--- info = string.join([fn, mi, ln, deg, dat] outfile.write(info) #-- # a = 1 + a else: a = 1 + a infile.close() outfile.close() # Thank you very much for your help. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
multiprocessing question/error
Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code class Pygen3(self) def calcula(self,indiv): def evaluate(self): indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antiv�rus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic module import?
On Friday 16 January 2009 15:03:51 Lawson Hanson wrote: > Is it possible to import a module of Python code > where I do not know the name of the module > until run-time? > > The Python statement: > > from someModule import * > > requires that "someModule" be the name of the module, > but what I would like is to be able to define a value > for "someModule" ... and provided that such a module > exists (in an extended "sys.path" directory), then > import from the specified module at run-time > > If I have a module called "dummy.py" in my own "myModules" > directory (just below my HOME directory in Linux) > > If I do this: > > import os, sys > > myModDir = os.environ["HOME"] + "/myModules" > > sys.path.append(myModDir) > > modName = "%s/%s" % (myModDir, "dummy") > > from modName import * > > I get the following error: > > ImportError: No module named modName > > So is there any way to get Python to import the named module > without just doing "from dummy import *", because I will > not know that the user wants to use the "dummy" module > until run-time ... I'm trying to import control data > for different run scenarios which will be defined in > differently named Python modules which the user will > specify at run-time with a command-line option > > And help with this would be most appreciated > > Best regards, > > Lawson Hanson > -- > Melbourne, Victoria, Australia > -- > http://mail.python.org/mailman/listinfo/python-list modu = "os" exec("from " + modu + " import *") []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
multiprocessing question/error
Hi, I was using the former processing package with python 2.5 with no problems. After switching to python 2.6.1 I am having some problems with the same code. The problem seems to be related to the fact that I am using Pool.map with a bounded method, since it is inside a class. To clarify a little bit, let me show some parts of the code class Pygen3(self) def calcula(self,indiv): def evaluate(self): indiv = range(mult*self.popsize,(mult+1)*self.popsize) pool = Pool(processes=nproc) results = pool.map(self.calcula,indiv) ... ... the error is the following Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 477, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) PicklingError: Can't pickle : attribute lookup __builtin__.instancemethod failed Thanks for your help. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antiv�rus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic module import?
On Friday 16 January 2009 16:13:49 Steven D'Aprano wrote: > On Fri, 16 Jan 2009 21:34:01 -0800, Eduardo Lenz wrote: > > modu = "os" > > exec("from " + modu + " import *") > > "from module import *" is generally frowned upon, although it does > occasionally have its uses. > > By the way, I think your computer's clock is set wrong. My newsclient is > reporting that you sent your post at 4:30pm today -- and I'm writing this > at 11am. Perhaps your timezone is set wrong? > > Regards, > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list OK, my point was about the exec statement, not the import * (it was just an example). Well, my clock is OK here..maybe the time zone is wrong. I will check this out. Thanks for the advice. []'s Lenz. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing question/error
On Saturday 17 January 2009 00:43:35 Aaron Brady wrote: > On Jan 16, 11:39 pm, Eduardo Lenz wrote: > > Hi, > > > > I was using the former processing package with python 2.5 with no > > problems. After switching to python 2.6.1 I am having some problems with > > the same code. The problem seems to be related to the fact that I am > > using Pool.map with a bounded method, since it is inside a class. To > > clarify a little bit, let me show some parts of the code > > Hello, > > > class Pygen3(self) > > I infer this was a typo. > > > > > > > > > def calcula(self,indiv): > > > > > > > > > > def evaluate(self): > > > > > > indiv = range(mult*self.popsize,(mult+1)*self.popsize) > > pool = Pool(processes=nproc) > > results = pool.map(self.calcula,indiv) > > I infer the indentation drifted. > > > ... > > ... > > > > the error is the following > > > > Exception in thread Thread-1: > > Traceback (most recent call last): > > File "/usr/lib/python2.6/threading.py", line 522, in __bootstrap_inner > > self.run() > > File "/usr/lib/python2.6/threading.py", line 477, in run > > self.__target(*self.__args, **self.__kwargs) > > File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > > _handle_tasks > > put(task) > > PicklingError: Can't pickle : attribute lookup > > __builtin__.instancemethod failed > > > > Thanks for your help. > > Checking on two typos above. I have this working: > > from multiprocessing import Process > > class C(object): > def m1( self ): > p1 = Process(target=self.m2, args=('bob1',)) > p2 = Process(target=self.m2, args=('bob2',)) > p1.start() > p2.start() > p1.join() > p2.join() > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > But I get the same error as you with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= range( 10 ) > pool= Pool( 5 ) > results = pool.map(self.m2,arg) > print results > def m2( self, name ): > print 'hello', name > > if __name__ == '__main__': > c= C() > c.m1() > > I build a workaround with this: > > from multiprocessing import Process, Pool > > class C(object): > def m1( self ): > arg= zip( [ self ]* 10, range( 10 ) ) > pool= Pool( 5 ) > results = pool.map(C_m2,arg) > print results > def m2( self, arg ): > print 'hello', arg > return arg* 2 > def C_m2( ar, **kwar ): > return C.m2( *ar, **kwar ) > > if __name__ == '__main__': > c= C() > c.m1() > > Note that you have to explicitly include 'self' as a first parameter > when packing the arguments, and then explicitly unpack it in the > helper function. Also, wrapping 'm2' with '@staticmethod' also fails > with this error: > > Exception in thread Thread-1: > Traceback (most recent call last): > File "c:\programs\python26\lib\threading.py", line 522, in > __bootstrap_inner > self.run() > File "c:\programs\python26\lib\threading.py", line 477, in run > self.__target(*self.__args, **self.__kwargs) > File "c:\programs\python26\lib\multiprocessing\pool.py", line 225, > in _handle_tasks > put(task) > PicklingError: Can't pickle : attribute lookup > __builtin__.function failed > > If this works for you, it's possible to make the helper function more > dynamic, by accepting a class name and an attribute name as string > arguments, then retrieving them in the subprocesses. > -- > http://mail.python.org/mailman/listinfo/python-list Thanks for your help ! The only question remaninig is why it iused to work with the former processing package. Another question: is it possible to change a bound method to a function on the fly ? I was wondering if something like class.__dict__["function_name"] could do the job. Actually, I was wondering with something like a casting, but a guess it is not possible. Thanks again, Eduardo. -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Re: A different kind of interface
On Thursday 22 January 2009 08:13:49 Vic Kelson wrote: > How about IDLE? It's a nice tool for the Python programmer. I've tried > lots of IDEs, but when it comes down to it, on small-to-medium jobs I > am be very productive indeed using IDLE... > > --v > -- > http://mail.python.org/mailman/listinfo/python-list How about Eric ? -- Eduardo Lenz Cardoso Dr. Eng. Associate Professor State University of Santa Catarina Department of Mechanical Engineering 89223-100 - Joinville-SC - Brasil Tel: +55 47 4009-7971 - Fax: +55 47 4009-7940 E-mail: l...@joinville.udesc.br - -- Esta mensagem foi verificada pelo sistema de antivírus e acredita-se estar livre de perigo. -- http://mail.python.org/mailman/listinfo/python-list
Scales question
Hi all... I want to represent a point in 800 X 600 board in a 640 X 480 board..., for example (13, 50) in 640X480 to 800X600 so.. will be like this... Xscale = (13 * 800)/640 Xscale = 16.25 Yscale = (50 * 600)/480 Yscale = 62.5 what happend with the decimals??? I round up or down??? or there is another way to calculate this more accurate? Thks... -- http://mail.python.org/mailman/listinfo/python-list
Gobject
hi all... I'm trying to get a event when a pipe of a process is no longer receiving data, in this case a EOF... the process start with no problems... but... the gobject_io_add_watch does not trigger the test method when the file in mplayer has finish... any ideas?? Thks :) the codes is this (the relevant part): import gobject, sys,os def play(self,opciones ,target): mpc = "mplayer -slave -quiet \"" + target + "\" 2>/dev/null" self.pin, self.pout = os.popen2(mpc) #open pipe self.startEofHandler() def startEofHandler(self): self.eofHandler = gobject.io_add_watch(self.pout, gobject.IO_HUP, self.test) def test(self,source,condition): print 'Something happend!!' print source -- http://mail.python.org/mailman/listinfo/python-list
[ANN] DoIt 0.1.0 Released (build tool)
DoIt - A task execution tool (build-tool) = This is the first public release of DoIt Website: http://python-doit.sourceforge.net/ Release: DoIt 0.1.0 License: MIT About - DoIt is a build tool that focus not only on making/building things but on executing any kind of tasks in an efficient way. Designed to be easy to use and "get out of your way". DoIt like most build tools is used to execute tasks defined in a configuration file. Configuration files are python modules. The tasks can be python functions (or any callable) or an external shell script. DoIt automatically keeps track of declared dependencies executing only tasks that needs to be update (based on which dependencies have changed). In DoIt, unlike most(all?) build-tools, a task doesn't need to define a target file to use the execute only if not up-to-date feature. This make DoIt specially suitable for running test suites. DoIt can be used to perform any task or build anything, though it doesn't support automatic dependency discovery for any language. Cheers, Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Re: random.random(), random not defined!?
On Sun, Apr 20, 2008 at 12:58 AM, globalrev <[EMAIL PROTECTED]> wrote: > do i need to import something to use random? > -- you need to import random :) Python 2.5.1 (r251:54863, Mar 7 2008, 03:39:23) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import random >>> random.random() 0.76018998919085967 -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] DoIt 0.1.0 Released (build tool)
On Sun, Apr 20, 2008 at 2:04 AM, John Machin <[EMAIL PROTECTED]> wrote: > You may like to consider the possibility of confusion caused by the > similarity of some characters in some fonts (DoIt, Do1t, Dolt) ... > google("dictionary dolt") :-) > -- > http://mail.python.org/mailman/listinfo/python-list > hehehehe. i feel like a DOLT I never realized that it is confusing. I also didnt know this word "dolt" before. i wont use capital letters anymore. thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "make" like tools (was Re: [ANN] DoIt 0.1.0 Released (build tool))
> > I took a look at dolt syntax, and saw this: > > QQQ > > def create_folder(path): > """Create folder given by "path" if it doesnt exist""" > if not os.path.exists(path): > os.mkdir(path) > return True > > def task_create_build_folder(): > buildFolder = jsPath + "build" > return {'action':create_folder, > 'args': (buildFolder,) > } > > QQQ > > Wouldn't it be more convenient to provide syntax like this: > > @task("create_build_folder") > @depend("dep1 some_other_dep") > def buildf(): > buildFolder = jsPath + "build" > create_folder(buildFolder) > > I find the doit syntax a bit cumbersome, especially as you can avoid > 'args' by just returning a lamda in 'action'. My idea was to: do *not* add any new syntax (to avoid being cumbersome). It is just python, you dont have to import or subclass anything. You just need to create a function that returns a dictionary with some predefined keys. I though about using decorators in the beginning... but returning a dictionary looked easier to implement and more flexible. one important feature is how easy to define a group of task with the same action. Take a look at the example below on running pychecker in all python files from a folder. I couldnt figure out an easy way of doing it with decorators. import glob; pyFiles = glob.glob('*.py') def task_checker(): for f in pyFiles: yield {'action': "pychecker %s"% f, 'name':f, 'dependencies':(f,)} Another advantage of using just a dictionary to define a task is that it will be easy to read tasks from a text file (if it is very simple and you dont need to write any python script). but not implemented yet. I though about using decorator for simple python-tasks but in a different way: @task def create_folder(path): """Create folder given by "path" if it doesnt exist""" if not os.path.exists(path): os.mkdir(path) return True so if your python function is a task and you will use it only once you dont need to define a function for the 'action' and another function to create the task. but not implement yet also. > > I've looked around a bit for python "make" replacement, but there does > not seem to be a simple & straightforward solution around (read - > straight-python syntax, one .py file installation, friendly license). apart from one .py file installation (easy_install is not enough?) thats what i am trying to do. thanks for the feedback. cheers, Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "make" like tools (was Re: [ANN] DoIt 0.1.0 Released (build tool))
I guess I should post a link to the project in this thread... http://python-doit.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "make" like tools (was Re: [ANN] DoIt 0.1.0 Released (build tool))
On Wed, Apr 23, 2008 at 8:39 PM, Ville M. Vainio <[EMAIL PROTECTED]> wrote: > > Yeah, decorators get around this. > > > Perhaps you could do: > > for f in pyFiles: > @task("checker") > @depend(f) > def check(): > c("pychecker %s" % f) > > Never underestimate the magic that is nested scopes and name-agnostic > function object creation... > ok. it is possible to do everything with decorators... i agree. but i dont want "name-agnostic function object creation". i want to be able to execute every single task without executing all other tasks. thats why when defining sub-tasks it is required an extra parameter "name". I know you could add another decorator for this also :) I mean decorators could do the job i dont say they cant. *I* prefer to work with dictionaries though. Even if they are a bit more verbose. > > > > I though about using decorator for simple python-tasks but in a different > way: > > > > @task > > > > def create_folder(path): > >"""Create folder given by "path" if it doesnt exist""" > >if not os.path.exists(path): > >os.mkdir(path) > > return True > > > > > > so if your python function is a task and you will use it only once you > > dont need to define a function for the 'action' and another function > > to create the task. but not implement yet also. > > > > Yeah, this is what I consider much friendlier syntax (the aim is to not be > much more verbose than make). > > Maybe it is just a bad example. I tried to put all features on single example. but in *real* life I could do like this. import os jsPath = "./" jsFiles = ["file1.js", "file2.js"] sourceFiles = [jsPath + f for f in jsFiles] compressedFiles = [jsPath + "build/" + f + ".compressed" for f in jsFiles] def task_shrink_js(): # create output folder if not os.path.exists(path): os.mkdir(path) for jsFile,compFile in zip(sourceFiles,compressedFiles): action = 'java -jar custom_rhino.jar -c %s > %s'% (jsFile, compFile) yield {'action':action, 'name':jsFile, 'dependencies':(jsFile,), 'targets':(compFile,) } Can I challenge you to do this with any other build tool? i guess anything more complicated than this you want to create a python function separate from the task definition anyway. My examples are from scratch. I dont use a "standard library". I could also document the short-cuts :P. I was afraid that including the short-cuts would make it more complicated for who is trying to learn it. if you dont define any dependencies or args to the function you dont need to return a dictionary. just the action: def task_simple_shell(): return "echo spam" def task_simple_python(): def say_spam(): print "spam" return True return say_spam # or from our discussion def task_create_build_folder(): def create_folder(): path = jsPath + "build" if not os.path.exists(path): os.mkdir(path) return True return create_folder > > > apart from one .py file installation (easy_install is not enough?) > > thats what i am trying to do. > > > > easy_install is not really enough - it introduces a dependency that you > can't get around by just shipping a short .py file with your project. > what about shipping a single egg file with the whole package? ( I am not very much familiar with this subject) > 'Paver' seems to have the right idea: > > http://www.blueskyonmars.com/projects/paver/index.html > Thanks for the link. I took a quick look on its documentation. It seems that "paver" doesnt keep track of file-dependencies at all. So it is more like a setuptools extension commands than a "full-feature" build system with "smart" re-build and dependency support. "doit" target is not on creating releases for python projects only. it can do it also, but it can do much more. You can read about my motivation to start another build tool project on http://schettino72.wordpress.com/2008/04/14/doit-a-build-tool-tale/ > But it's still *slightly* too big: > man, it is hard to make you happy :) the doit egg file containg the whole packge is 27782 bytes on my system. but you also need the command line script 154 bytes. cheers, Eduardo -- http://mail.python.org/mailman/listinfo/python-list
argparse - specify order of argument parsing?
When using argparse, is there a way to specify in what order arguments get parsed? I am writing a script whose parameters can be modified in the following order: Defaults -> config file -> command-line switches. However, I want to give the option of specifying a config file using a command line switch as well, so logically, that file should be parsed before any other arguments are applied. However, it seems that parse_args() parses arguments in the order they're given, so if the config file switch is not given first, the config file will overwrite whatever was in the command-line switches, which should have higher priority. Thank you in advance, -- Eduardo Alvarez -- http://mail.python.org/mailman/listinfo/python-list
mailbox module difficulties
Hello, everyone, I'm in the process of learning how to use the mailbox module with python 3.2. I've noticed the following seemingly inconsistent behavior: if I call a Maildir object directly, the module works perfectly. I can, for example, call mailbox.Maildir("~/Maildir").items() and get the expected list of (key,Message) pairs. however, if I do the following: b = mailbox.Maildir("~/Maildir") b.items() I get an empty list. I don't understand why this is so, specially since the last example in the documentation shows a reference to a Maildir object being created. Why does this happen? yours, -- Eduardo Alvarez -- http://mail.python.org/mailman/listinfo/python-list
Re: mailbox module difficulties
On 2011-11-28, Peter Otten <__pete...@web.de> wrote: > Eduardo Alvarez wrote: > >> however, if I do the following: >> >> b = mailbox.Maildir("~/Maildir") >> b.items() >> >> I get an empty list. >> >> I don't understand why this is so, specially since the last example in >> the documentation shows a reference to a Maildir object being created. >> Why does this happen? > > Could this be > > http://bugs.python.org/issue13254 > > ? Peter and Chris, This is exactly it. I guess the version in my linux distribution is not patched. I'll let the maintainer know, thank you! Yours, -- Eduardo Alvarez -- http://mail.python.org/mailman/listinfo/python-list
Multiple threads
Hello, I have a py script that reads for all "m2ts" video files and convert them to "mpeg" using ffmpeg with command line. What I want to do is: I need my script to run 2 separated threads, and then when the first has finished, starts the next onebut no more than 2 threads. I know that Semaphores would help with that. But the problem here is to know when the thread has finished its job, to release the semaphore and start another thread. Any help would be great. Thank you in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: any(), all() and empty iterable
On Sun, Apr 12, 2009 at 8:53 AM, Tim Chase wrote: >>> From the docs: >> >> all(iterable) >> Return True if all elements of the iterable are true. >> Equivalent >> to: >> def all(iterable): >> for element in iterable: >> if not element: >> return False >> return True > > Then I'd say the comment is misleading. An empty list has no item that is > true (or false), yet it returns true. The comment in the docs should read > "Return False if any element of the iterable is not true" or "Return True if > all elements of the iterable are true or if the iterable is empty." I didn't knew about "Vacuous True" (my fault, it seems Discrete Math 101) until reading about on this thread (thanks everyone!), and reading on wikipedia it answered this exact question. > To get the behavior the original comment describes, would seem to require an > implementation something like this: > > def all(iterable): > iterable = iter(iterable) > try: > element = iterable.next() > except StopIteration: > raise UnderdefinedBecauseNoElementsToCompareToTrue > while element: > try: > element = iterable.next() > except StopIteration: > return True > return False > > > Tweaking the documentation seems like an easier and more backwards > compatible solution to me :) > > -tkc > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://importskynet.blogspot.com http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: List Comprehension Question: One to Many Mapping?
> For example, if I have x=[ [1,2], [3,4] ] > > What I want is a new list of list that has four sub-lists: > > [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]] [[a, [f(b) for b in a]] for a in x] -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Python 3.0 remove the global interpreter lock (GIL)
On 9/2/07, llothar <[EMAIL PROTECTED]> wrote: > I'm afraid that the GIL is killing the usefullness of python for some > types of applications now where 4,8 oder 64 threads on a chip are here > or comming soon. > > What is the status about that for the future of python? > > I know that at the moment allmost nobody in the scripting world has > solved this problem, but it bites and it bites hard. Only groovy as a > Java Plugin has support but i never tried it. Writing an interpreter > that does MT this seems to be extremely difficult to do it right, with > lots of advanced stuff like CAS and lock free programming. > > Even Smalltalk and Common Lisp didn't get it until know (with the > exception of certain experiments). No. http://www.artima.com/weblogs/viewpost.jsp?thread=211430 -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Python 3.0 remove the global interpreter lock (GIL)
> No. http://www.artima.com/weblogs/viewpost.jsp?thread=211430 Ops, I meant: http://www.artima.com/forums/threaded.jsp?forum=106&thread=211200 -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: self.member syntax seems /really/ annoying
On 9/13/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > because I'm trained to interpret the underscore as a synonym for one > space. It's not particularly beautiful, but that is probably a matter of > habituation. And that exact word is probably the reason why I'd still > use self or s (explained by a comment, because I can get very dumb if I > have to). Have you worked with code using gettext functions imported as "_"? When I see a single underscore as a name, i18n comes to mind. -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid overflow errors
On 9/14/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > I thought that overflow errors would be a thing of the past now that > Python automatically converts ints to longs as needed. Unfortunately, > that is not the case. > > >>> class MyInt(int): > ... pass > ... > >>> MyInt(sys.maxint) > 2147483647 > >>> MyInt(sys.maxint+1) > Traceback (most recent call last): > File "", line 1, in > OverflowError: long int too large to convert to int Not totally unrelated, but in Py3k, as it seems, overflows are really things of the past: Python 3.0a1 (py3k:58061, Sep 9 2007, 13:18:37) [GCC 4.1.3 20070831 (prerelease) (Ubuntu 4.1.2-16ubuntu1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class MyInt(int): ... pass ... >>> import sys >>> MyInt(sys.maxint) 2147483647 >>> MyInt(sys.maxint+1) 2147483648 Thanks to your mail, only now I see how important this change (int/liong unification) really is! > How do I subclass int and/or long so that my class also auto-converts > only when needed? What about just subclassing long - is this not an option? > Steven. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid overflow errors
On 14 Sep 2007 18:08:00 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > "Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > > Not totally unrelated, but in Py3k, as it seems, overflows are really > > things of the past: > > > > > > Python 3.0a1 (py3k:58061, Sep 9 2007, 13:18:37) > > [GCC 4.1.3 20070831 (prerelease) (Ubuntu 4.1.2-16ubuntu1)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> class MyInt(int): > > ... pass > > ... > > >>> import sys > > >>> MyInt(sys.maxint) > > 2147483647 > > >>> MyInt(sys.maxint+1) > > 2147483648 > > I'd be interested in knowing what happens in 3.0a1 with > > a = itertools.count(sys.maxint) > print a.next() > print a.next() >>> print(next(a)) Traceback (most recent call last): File "", line 1, in OverflowError: cannot count beyond PY_SSIZE_T_MAX Hum, you've got me there. it is the same as in 2.x. Maybe the message should be less crypt, at least - nothing that googling for PY_SSIZE_T_MAX cant help. -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid overflow errors
On 9/15/07, Carl Banks <[EMAIL PROTECTED]> wrote: > On Fri, 14 Sep 2007 22:59:13 -0300, Eduardo O. Padoan wrote: > > > On 14 Sep 2007 18:08:00 -0700, Paul Rubin > > <"http://phr.cx"@nospam.invalid> wrote: > >> "Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > >> > Not totally unrelated, but in Py3k, as it seems, overflows are really > >> > things of the past: > >> > > >> > > >> > Python 3.0a1 (py3k:58061, Sep 9 2007, 13:18:37) [GCC 4.1.3 20070831 > >> > (prerelease) (Ubuntu 4.1.2-16ubuntu1)] on linux2 Type "help", > >> > "copyright", "credits" or "license" for more information. > >> > >>> class MyInt(int): > >> > ... pass > >> > ... > >> > >>> import sys > >> > >>> MyInt(sys.maxint) > >> > 2147483647 > >> > >>> MyInt(sys.maxint+1) > >> > 2147483648 > >> > >> I'd be interested in knowing what happens in 3.0a1 with > >> > >> a = itertools.count(sys.maxint) > >> print a.next() > >> print a.next() > > > > > >>>> print(next(a)) > > Traceback (most recent call last): > > File "", line 1, in > > OverflowError: cannot count beyond PY_SSIZE_T_MAX > > > > Hum, you've got me there. it is the same as in 2.x. Maybe the message > > should be less crypt, at least - nothing that googling for > > PY_SSIZE_T_MAX cant help. > > This should demonstrate that OverflowError will not disappear entirely > even in Python 3. No one is denying that by now :) > Even if we were to get rid of all OverflowErrors resulting from integer > operations in Python, there are going to be some C extensions--including > some in the Python standard library--that will store 32-bit integers. > Modules such as array and struct will still raise it, and probably other > modules were a long integer sometimes doesn't make sense (socket, for > instance). itertools.count() should work for arbitrary integers, though. Agreed. I was lookind at itertoolsmodule.c, and even for my very limited C knowlegment, it does not seem to be too hard. Anyway: http://bugs.python.org/issue1165 > Carl Banks > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: how to join array of integers?
> > It's nice people have invented so many ways to spell the > > builting "map" ;) > > > ",".join(map(str,[1,2,3])) > > '1,2,3' > > IIRC, map's status as a builtin is going away. Actually, py3k built-in map == itertools.imap >>> map(str, []) -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Python statements not forcing whitespace is messy?
On 9/15/07, J. Cliff Dyer <[EMAIL PROTECTED]> wrote: > And I'd hate to have to remember all of the rules for what can go > together and what can't, especially when it comes time to debug. No. > I don't think it should be forced, but maybe put it in PEP8 or PEP3008. It is: see "Whitespace in Expressions and Statements" in PEP 8. -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: sybase open client 15_0
See: http://www.object-craft.com.au/pipermail/python-sybase/2006-May/000471.html Dan wrote: > I'm running SLES 9.3 on Tyan with 2 single core 64-bit Opteron & 8 GB of > memory and SWAP. > > OCS-15_0 > sybperl-2.18 > python 2.3.5 > > > > "Dan" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I have compiled and installed sybase-.037 , the module to add sybase to >> python. However, when I try to use it I get Import error: >> /usr/local/lib/python2.3/site-packages/sybasect.so >> >> undefined symbol: cs_dt_info >> >> I've seen some posts on the internet with other people having this issue. >> But nothing they've suggested has resolved this issue. Maybe python just >> needs to be installed again or upgraded to support sybase Open Client. >> >> Thanks, >> ~DjK >> > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Well written open source Python apps
This is an old thread in this subject that I bookmarked: http://groups.google.com/group/comp.lang.python/browse_thread/thread/984262217c1b3727/8793a0b7722bb32f -- http://mail.python.org/mailman/listinfo/python-list
Python in Optimized mode with /usr/bin/env
This is more of a shell or env question, but I believe others here have gone through this. I want to run an optimized python using the portable /usr/bin/env, but the obvious ways aren't working. #!/usr/bin/env python -O when I run ./test.py I get: /usr/bin/env: python -O: No such file or directory #!/usr/bin/env PYTHONOPTIMIZE=YES python freeezes when I run ./test.py #!/usr/local/bin/python -O works fine. Any suggestion about how to do it without using an ugly hack as making an shell script just to set the environment? thanks in advance for any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: python -i (interactive environment)
When I'm using pyunit and want to stop in a point during the test (skipping all the framework initialization), I just start the debugger: import pdb pdb.set_trace() You'll get the debugger prompt. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 16, Issue 324
703 861 4237 +1 800 494 3119 > > > > -- Forwarded message -- > From: "Erik Bethke" <[EMAIL PROTECTED]> > To: python-list@python.org > Date: 20 Jan 2005 06:20:46 -0800 > Subject: Re: ElementTree cannot parse UTF-8 Unicode? > There is something wrong with the physical file... I d/l a trial > version of XML Spy home edition and built an equivalent of the korean > test file, and tried it and it got past the element tree error and now > I am stuck with the wxEditCtrl error. > > To build the xml file in the first place I had code that looked like > this: > > d=wxFileDialog( self, message="Choose a file", > defaultDir=os.getcwd(), defaultFile="", wildcard="*.xml", style=wx.SAVE > | wxOVERWRITE_PROMPT | wx.CHANGE_DIR) > if d.ShowModal() == wx.ID_OK: > # This returns a Python list of files that were selected. > paths = d.GetPaths() > layout = '\n' > L1Word = self.t1.GetValue() > L2Word = 'undefined' > > layout += '\n' > layout += '\n' > layout += '' > open( paths[0], 'w' ).write(layout) > d.Destroy() > > So apprantly there is something wrong with physically constructing the > file in this manner? > > Thank you, > -Erik > > > > -- Forwarded message -- > From: "Fredrik Lundh" <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 20 Jan 2005 15:40:35 +0100 > Subject: Re: ElementTree cannot parse UTF-8 Unicode? > Erik Bethke wrote: > > > layout += '\n' > > layout += '\n' > > what does "print repr(L1Word)" print (that is, what does wxPython return?). > it should be a Unicode string, but that would give you an error when you write > it out: > > >>> f = open("file.txt", "w") > >>> f.write(u'\uc5b4\ub155\ud558\uc138\uc694!') > Traceback (most recent call last): > File "", line 1, in ? > UnicodeEncodeError: 'ascii' codec can't encode characters > in position 0-4: ordinal not in range(128) > > have you hacked the default encoding in site/sitecustomize? > > what happens if you replace the L1Word term with L1Word.encode("utf-8") > > can you post the repr() (either of what's in your file or of the thing, > whatever > it is, that wxPython returns...) > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Atte, Eduardo HenrÃquez A. 9-6975236 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 16, Issue 457
wrong with m2crypto? > > > > http://sandbox.rulemaker.net/ngps/m2/ > > > > Why not incorporate it into the standard distribution? > > > > Or, what about Andrew Kuchling's crypto toolkit? > > > > http://www.amk.ca/python/code/crypto.html > > > > > > Umm, is it just me or did we just discuss the legal issues of that?? > > > > -- Forwarded message -- > From: Mark McEahern <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 07:18:14 -0600 > Subject: Re: exclude binary files from os.walk > The OP wrote: > > > Is there an easy way to exclude binary files (I'm working on Windows > XP) from the file list returned by os.walk()? > > Sure, piece of cake: > > #!/usr/bin/env python > > import os > > def textfiles(path): >include = ('.txt', '.csv',) >for root, dirs, files in os.walk(path): >for name in files: >prefix, ext = os.path.splitext(name) >if ext.lower() not in include: >continue >filename = os.path.join(root, name) >yield filename > > path = os.getcwd() > for name in textfiles(path): >print name > > ;-) > > // m > > > > -- Forwarded message -- > From: Steve Holden <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 08:14:02 -0500 > Subject: Re: import hook, overwrite import? > Kartic wrote: > > > Hi Torsten, > > > > If you want to use other methods to import (other than good ole file > > system), yes, you can create an importer class and register it as an > > importer module, that import will use to search and import. > > > > For example, it is possible to use zip imports (this functionality is > > already builtin) to import from a zip archive. > > py>>> import zlib # required > > py>>> import sys > > py>>> sys.path.append('/location/to/zippedmodules.zip') > > py>>> import testzip > > py>>> testzip.__file__ > > '/location/to/zippedmodules.zip/testzip,py' > > > > To generally do it, you have to: > > 1. Create a class that provides a load_module method that returns a > > module type. > > 2. Install your class as a hook using > > sys.path_hooks.append(your_importer_class) > > > > Please take a look at the imp module : > > http://docs.python.org/lib/module-imp.html for a complete description > > on accessing the import internals. There is also a simple example in > > this section. > > > > Is this is what you are looking for? > > > > Thanks, > > --Kartic > > PS: This about how much I know...the more I find out, I will share :-) > > > I will just chime in to say I too am looking for information in this > area. I hope to put some sort of BoF or Open Space event together for > people wishing to learn about (and teach about) the import system from > PEP 302 at PyCon this year. > > Early bird registration rates are still available today and tomorrow! > > regards > Steve > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Atte, Eduardo Henríquez A. 9-6975236 -- http://mail.python.org/mailman/listinfo/python-list
Re: A different kind of interface
On Thu, Jan 22, 2009 at 7:10 AM, wrote: > I use the Python shell daily, plus of course normal editors to edit > python scripts. They both are very useful for different purposes. But > the default interactive shell isn't much handy if you want to modify > the past code to run it again, or you want to embed a bit of text in > the code, or if you want to produce something a bit more clean that > you can save, or just if you want to edit and debug 7-lines long > programs. You are almost *describing* reinteract: http://blog.fishsoup.net/2007/11/10/reinteract-better-interactive-python/ It is a mix of a shell and an editor, that lets you go back and rewirte history, and execute it again. It is GTK+, and you can write plugins to plot graphics or display html, for example. -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: A different kind of interface
On Thu, Jan 22, 2009 at 5:01 PM, wrote: > Eduardo O. Padoan: >> You are almost *describing* reinteract: > > - Thank you for the link and the software, I have not tried it yet, > but from the screencast it looks quite nice. > - I am glad that there are people that don't think that Emacs is > (despite being good) the alpha and omega of editing. There's space for > other ideas beside Emacs. But it is! > - Maybe I was describing reinteract there, but that's only the first > part of my post :-) > - I can see that reinteract is based on a interaction style quite > similar to the shell of Mathematica. I was talking about something > different, and more similar to TextCalc, but in the end I think > reinteract may be good enough for my purposes, so I'll try to run it. > And I may be happy enough. I dont known TextCalc, but I guess that reinteract is flexible enough to the general purpose of "experimenting with Live code". > - Eventually I may find the time and will to create my "interactive > python text" :-) I think there's space for many different solutions. > - Despite many years of experiments, development, shells, editors, and > the like, I am sure there are other designs not yet tried or not > common enough yet (beside the normal editors, shells, smart object- > oriented graphical shells like hotwire shell, Resolver One, and few > other weird things, like one where you can zoom text and images at > different scales, other text-based systems, etc). Sure, thats the spirit. > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3 - it's awesome
On Mon, Nov 17, 2008 at 7:30 AM, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello list, > > since I've read so much about Python 3 and ran into some trouble which > was supposed to be fixed with 3k, I yesterday came around to compile it > and try it out. > > To sum it up: It's awesome. All the promised things like Unicode support > "just work", all significant changes in the lanugage (try/except-Syntax, > float division, file opening, print) I've encountered so far made > absolute sense and it was quite easy to change over (I've been using 2.5 > so far). It was really easy to install it locally as my user (I want to > try it out some more before I install it system-wide). You can install it system-wide as "python3.0" or "python3" -- I think that "make install" acts as "make altinstall" on Python 3.0, and dont overide the default "python" binary. No, you probably dont want python3.0 as the *default* python yet -- many Python programs for Ubuntu or OS X, for example, depends on Python 2.X. > So, why I am posting this here: First, thanks to the great work to > anyone who has contributed. Secondly, I want to encourage anyone who > hasn't tried Python3 out yet to do - it really is easier than you think > and you won't be disappointed. +1. > Kind regards, > Johannes > > -- > "Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, > verlästerung von Gott, Bibel und mir und bewusster Blasphemie." > -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik > <[EMAIL PROTECTED]> > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: What about a decorator module version 3.0?
On Mon, Dec 1, 2008 at 9:16 AM, Michele Simionato <[EMAIL PROTECTED]> wrote: > I am thinking about releasing a new version of the decorator module, > [...] Just FYI, the module being discussed here is http://www.phyast.pitt.edu/~micheles/python/documentation.html I dont use it myself, but given how much I use decorators, I probably should. -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: "as" keyword woes
On Thu, Dec 4, 2008 at 7:44 AM, James Stroud <[EMAIL PROTECTED]> wrote: > alex23 wrote: >> >> On Dec 4, 3:42 pm, "Warren DeLano" <[EMAIL PROTECTED]> wrote: >>> >>> So you prefer broken code to broken rules, eh? Your customers must love >>> that! This is exactly the kind of ivory-tower thinking I feared might >>> be behind the decision (form over function, damn the users to hell, >>> etc.) >> >> Really? I find that believing something should remain static at the >> expense of actual improvement to the language is far more 'ivory-tower >> thinking' than embracing change. > > First, to quote Tim Peters, "practicality beats purity." Second, I might be > biased here because I happen to know Warren, but, although he hails from the > ivory tower, I imagine his concerns are purely practical. His contributions > to software in structural biology are legendary. > >>> Am I the only one picking up on the irony here? "as" exists largely to >>> provide a mechanism for working around namespace conflicts -- except, >>> apparently, conflicts involving "as". The fact that "as" itself creates >>> an insurmountable namespace collision is just killing me! How absurd. >> >> Speaking of irony, you're complaining about namespace conflicts with a >> -two character identifier- you've chosen. Here's a hint: choose better >> names. > > The name fit his needs until changes in the language broke the name. If a > name works and the code works, then the name is good enough. And speaking as > a professional user of his software at the level of the application and at > the level of the API, let me tell you his code works pretty damn good. > >>> But to be brutally honest...in this many-core world we must all accept >>> and deal with today, it is hard to imagine how a non-multithreaded AND >>> non-backwards compatible Python implementation can have much of a life >>> ahead of it, with or without an "as" keyword. I do sincerely hope I am >>> wrong about this, but it is seems quite possible that C/Python's glory >>> days are now behind us. >> >> To match your honesty, I'm somewhat tired with the trend of some >> people to hit -one- issue with Python and suddenly lash out like >> children over all the same old tired crap. Have you even looked at >> multiprocessing? Have you contributed to any projects working on GIL- >> less implementations? Or are you just regurgitating the same bullet >> points we've heard time and time again? >> >> For chrissake, if you cannot do ANYTHING but BITCH about a change, >> then you've no damn right to consider yourself a programmer. Real >> programmers find solutions, not excuses. > > Correction: Real programmers write programs. And no, at this point he can't > do anything but complain because, as others have noted, the change is not > going away. > >>> And if so, then thank you all for so many wonderful years of effort and >>> participation! >> >> You're welcome. Don't let the door hit you on the ass on your way out. > > You probably aren't a developer for the cPython implementation, but, if you > were, I'd recommend taking rants like Warren's to heart because they are > born of honest frustration and practical concern. Hopefully developers for > python 2.7 are listening and won't break backward compatibility just because > the "Zen of Python" suggests it might be a good idea. Even I, who am not, by really far, legendary on anything, could give my 2¢ one time or another on python-dev or python-ideas. If you really care and think you have a good argument, I'm sure you are welcome to post there! But they cant hold the release until everyone in the world have voiced his concerns, its just not pratical. -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ "Distrust those in whom the desire to punish is strong." -- Goethe, Nietzsche, Dostoevsky -- http://mail.python.org/mailman/listinfo/python-list
Re: Not fully OO ?
On Sat, Sep 20, 2008 at 11:26 AM, Kay Schluehr <[EMAIL PROTECTED]> wrote: > On 20 Sep., 12:14, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >> Kay Schluehr wrote: >> > Answer: if you want to define an entity it has to be defined inside a >> > class. If you want to access an entity you have to use the dot >> > operator. Therefore Java is OO but Python is not. >> >> you're satirising the quoted author's cargo-cultish view of object >> orientation, right? >> >> > > I wonder if the OO fetish hasn't already lost much of its magic > powers. What are the most powerful fetishes these days? A year ago I > would have suspected "purely functional" but I'm not sure it has > really caught on. I think the current fetish is paralelism and erlang's share-nothing concurrency model. Or something like it. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://djangopeople.net/edcrypt/ http://stopforwarding.us/etiq.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing objects
On Jan 23, 2008 9:55 AM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > For that to work, you need to give your class an __eq__ method, and have > it match by name: > > # put this in MyClass > def __eq__(self, other): > return self.name == self.other Do you mean: # put this in MyClass def __eq__(self, other): return self.name == other.name ? -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: PLEASE ACCEPT MY SINCERE APOLOGIES
On Feb 1, 2008 5:19 AM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > On Feb 1, 5:08 am, Paddy <[EMAIL PROTECTED]> wrote: > > On Feb 1, 1:26 am, "Blubaugh, David A." <[EMAIL PROTECTED]> wrote: > > > > > > > > > To Everyone on the planet Earth, > > > > > Please accept my apologies for > > > > > Why the Hell has nobody answered my question. > > > > > I am just trying to finish a Masters thesis that is quite beyond > > > anything in this world. > > > > > David Blubaugh > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > > > [mailto:[EMAIL PROTECTED] On Behalf > > > Of [EMAIL PROTECTED] > > > Sent: Thursday, January 31, 2008 7:30 PM > > > To: [EMAIL PROTECTED] > > > Subject: Python-list Digest, Vol 53, Issue 2 > > > > > Send Python-list mailing list submissions to > > > [EMAIL PROTECTED] > > > > > To subscribe or unsubscribe via the World Wide Web, visit > > >http://mail.python.org/mailman/listinfo/python-list > > > or, via email, send a message with subject or body 'help' to > > > [EMAIL PROTECTED] > > > > > You can reach the person managing the list at > > > [EMAIL PROTECTED] > > > > > When replying, please edit your Subject line so it is more specific than > > > "Re: Contents of Python-list digest..." > > > > > This e-mail transmission contains information that is confidential and > > > may be privileged. It is intended only for the addressee(s) named > > > above. If you receive this e-mail in error, please do not read, copy or > > > disseminate it in any manner. If you are not the intended recipient, any > > > disclosure, copying, distribution or use of the contents of this > > > information is prohibited. Please reply to the message immediately by > > > informing the sender that the message was misdirected. After replying, > > > please erase it from your computer system. Your assistance in correcting > > > this error is appreciated. > > > > Could you now specifically apologize for all those question > > marks!!! > > > > :-) > > > > Peace, Paddy. > > And for top-posting :) And for using ALL CAPS :) > -- > Arnaud -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Standardization: Wikipedia entry
On Jan 29, 2008 2:43 PM, John Nagle <[EMAIL PROTECTED]> wrote: >Submitting Python 2.5 to ISO/ANSI might be a good idea. >From GvR himself: """ - Does a specification (ISO, ECMA, ..) is planned for Python and when ? No, never. I don't see the point. """ http://blogs.nuxeo.com/sections/blogs/tarek_ziade/2005_04_11_guido_van_rossum -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: type, object hierarchy?
On Feb 4, 2008 1:36 AM, 7stud <[EMAIL PROTECTED]> wrote: > print dir(type) #__mro__ attribute is in here > print dir(object) #no __mro__ attribute > > > class Mammals(object): > pass > class Dog(Mammals): > pass > > print issubclass(Dog, type) #False > print Dog.__mro__ > > --output:-- > (, , ) > > > The output suggests that Dog actually is a subclass of type--despite > the fact that issubclass(Dog, type) returns False. In addition, the > output of dir(type) and dir(object): > > > ['__base__', '__bases__', '__basicsize__', '__call__', '__class__', > '__cmp__', '__delattr__', '__dict__', '__dictoffset__', '__doc__', > '__flags__', '__getattribute__', '__hash__', '__init__', > '__itemsize__', '__module__', '__mro__', '__name__', '__new__', > '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', > '__subclasses__', '__weakrefoffset__', 'mro'] > > ['__class__', '__delattr__', '__doc__', '__getattribute__', > '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', > '__repr__', '__setattr__', '__str__'] > > suggests that type inherits from object since type has all the same > attributes as object plus some additional ones. That seems to > indicate a hierarchy like this: > > > object > | > V > type > | > V > Mammals > | > V > Dog > > > But then why does issubclass(Dog, type) return False? Here you should find The Answer (tm): http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html (Beautifully ilustrated, BTW) -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Does anyone else use this little idiom?
On Feb 5, 2008 1:30 PM, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Ruby has a neat little convenience when writing loops where you don't > > care about the loop index: you just do n.times do { ... some > > code ... } where n is an integer representing how many times you want > > to execute "some code." > > > > In Python, the direct translation of this is a for loop. When the > > index doesn't matter to me, I tend to write it as: > > > > for _ in xrange (1,n): > > some code > > > > An alternative way of indicating that you don't care about the loop > > index would be > > > > for dummy in xrange (1,n): > > some code > > I use pychecker a lot. It views variables called [ '_', 'unused', > 'empty', 'dummy' ] as names to ignore if they haven't been used. > > So according to pychecker '_' and 'dummy' would both be OK. > > As for me personally, I usually use '_' but sometimes use 'dummy' > depending on the surrounding code. > > Note that this idiom is fairly common in python too > > wanted, _, _, _, also_wanted = a_list > > which looks quite neat to my eyes. > BTW and FWIW, in Py3k you can do: wanted, *_, also_wanted = a_list http://www.python.org/dev/peps/pep-3132/ -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Why must implementing Python be hard unlike Scheme?
On Feb 19, 2008 3:15 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Does this have to be true? Beneath the more complex syntax are there > a few core design principles/objects/relationships to help in grokking > the whole thing? Got any related links? Take a look at a simpler implementation, like "tinypy": http://www.philhassey.com/blog/2008/02/19/tinypy-64k-nearing-10-and-it-really-does-fit-in-64k/ -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Oh no, my code is being published ... help!
On Nov 30, 2007 11:36 AM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Eduardo O. Padoan" <[EMAIL PROTECTED]> writes: > > > No, writing this way will confound the 2to3 tool. > > Why? print("foo") is a perfectly valid Python 2 statement. Maybe > it's simply a matter of fixing the tool. > print("foo") -> print(("foo")) If you have any idea of how the tool could understand what you meant, please report it at bugs.python.org :) -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Oh no, my code is being published ... help!
On Nov 30, 2007 11:18 AM, Peter Decker <[EMAIL PROTECTED]> wrote: > On Nov 30, 2007 1:19 AM, Tim Roberts <[EMAIL PROTECTED]> wrote: > > > You also have a couple of instances of: > > print("Error Squeezing %s...") > > > > The parentheses serve no purpose here, and are unidiomatic. > > I thought that with the eventual dropping of 'print' as a statement in > Python 3, that writing it this way (as if it were a print function) is > preferred, since that will be one fewer thing to convert. > No, writing this way will confound the 2to3 tool. Just try for yourself. You would have to write print(something) all the time and disable the fix_print convertion. It is easier and safer to write the common 2.Xish way and let 2to3 do the work. -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug in __init__?
On Jan 18, 2008 3:09 PM, Zbigniew Braniecki <[EMAIL PROTECTED]> wrote: > I found a bug in my code today, and spent an hour trying to locate it > and then minimize the testcase. > > Once I did it, I'm still confused about the behavior and I could not > find any reference to this behavior in docs. > > testcase: > > class A(): > >def add (self, el): > self.lst.extend(el) > >def __init__ (self, val=[]): > print val > self.lst = val > > > def test (): >x = A() >x.add(["foo1","foo2"]) >b = A() > > > So, what I would expect here is that I will create two instances of > class A with empty self.lst property. Right? > > In fact (at least with my Python 2.5) > > [EMAIL PROTECTED]:~/projects/pyl10n$ ./scripts/test.py > [] > ['foo1', 'foo2'] > > This bug does not happen when I switch to __init__ (self, *args) and > assign self.lst= args[0]. > > Any clue on what's going on here, and/if where I should report it? It is a FAQ, not a bug: http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: HASH TABLES IN PYTHON
On Wed, May 14, 2008 at 12:20 PM, Blubaugh, David A. <[EMAIL PROTECTED]> wrote: > To Whom It May Concern, > > I was wondering if anyone has ever worked with hash tables within the Python > Programming language? I will need to utilize this ability for quick > numerical calculations. http://docs.python.org/lib/typesmapping.html > Thank You, > > David Blubaugh -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: can't delete from a dictionary in a loop
On Fri, May 16, 2008 at 6:40 PM, Gary Herron <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> >> On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: >> >>> >>> Dan Upton wrote: >>> >>>> >>>> for pid in procs_dict: >>>> if procs_dict[pid].poll() != None >>>> # do the counter updates >>>> del procs_dict[pid] >>>> The problem: >>>> RuntimeError: dictionary changed size during iteration >>>> >>> >>> I don't know if the setup with the pids in a dictionary is the best way >>> to >>> manage a pool of processes... I'll leave it others, presumably more >>> knowledgable, to comment on that. :-) But I can tell you how to solve >>> the >>> immediate problem: >>> >>> for pid in procs_dict.keys(): >>> > > No, keys() produces a list (which is what is wanted here). > It's iterkeys() that produces an iterator which would reproduce the OP's > problem. > > And then, in Python3, keys() produces something else altogether (call a view > of the dictionary) which would provoke the same problem, so yet another > solution would have to be found then. In Python 3.0, list(procs_dict.keys()) would have the same effect. > Gary Herron > >> >> I'm afraid this will do the same exact thing. A for loop on a dict >> iterates over the dict keys, so both statements are strictly >> equivalent from a practical POV. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: What is wrong with my Python threading?
On Tue, May 20, 2008 at 8:24 PM, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Tue, 20 May 2008 10:28:51 -0300, castironpi <[EMAIL PROTECTED]> > escribió: > >> You meant 'thd1.start( )' and 'thd2.start( )'. > > Wow! A message with a high S/N ratio coming from you! > And it's not the first I've seen - whatever pills you're taking, they're > good for you... This is why I shouldn't be so eager adding people to the killfile. -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: should I put old or new style classes in my book?
On Thu, May 29, 2008 at 3:06 PM, Jason <[EMAIL PROTECTED]> wrote: > I've got Python 3.0 alpha 2. In this version, it looks like you can > define classes in either the old style or new style. (I snipped the > top line a bit in the following example): Wrong. Py3k Classes are always new-style. They subclass object implicitly when no superclass is given. > Python 3.0a2 (r30a2:59405M, Dec 7 2007, 15:23:28 > Type "help", "copyright", "credits" or "license" >>>> class one(object): pass > ... >>>> class two: pass > ... >>>> two > >>>> one > >>>> type(one) > >>>> type(two) > >>>> Both classes are new style. -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Harry Potter?
On Thu, Jun 5, 2008 at 10:29 AM, Hans Nowak <[EMAIL PROTECTED]> wrote: > Helmut Jarausch wrote: >> >> Hi, >> just to let you know ... >> >> Today I've got an email from Amazon recommending me >> Harry Potter and the Deathly Hallows >> >> and they told me why they recommended this book, >> because I've bought >> Core PYTHON Programming >> >> Didn't know, Harry Potter is a Python fan. > > If you scan the alt.fan.harry-potter archives carefully, you will find at > least one well-known Python core developer. :-) Maybe Guido himself: "The Harry Potter Theory of Programming Language Design" http://www.artima.com/weblogs/viewpost.jsp?thread=123234 > -- > Hans Nowak (zephyrfalcon at gmail dot com) > http://4.flowsnake.org/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
On Wed, Jun 11, 2008 at 10:28 AM, Kless <[EMAIL PROTECTED]> wrote: > I understand very well that a service is a software which is accessed > through a network. > > And the description given on Wikipedia [1] is "A 'Web service' (also > Web Service) is defined by the W3C as "a software system designed to > support interoperable Machine to Machine interaction over a network." > > Now, to ending with this. I understand that (almos) everybody is pro > Google (and anti Microsoft), thinking that they have given a lot of > services for free. And it's very hard that people understand my > thinking. > > All that "free service" has a great price, that are the rights > about those data, and when Google want can to disable the free access > to that information. > > People don't realize that it's one more a company and like so it has > only an end, that is to obtain the greater number of benefits which > will be distributed between his shareholders. Within any years Google > will be as hated as Microsoft. > > At least I try to use the less possible those services than limit my > freedoms about data that has been contributed by me and another users. > > > [1] http://en.wikipedia.org/wiki/Web_service > -- > http://mail.python.org/mailman/listinfo/python-list > It is not a pro-GOOG/anti-MSFT child-thing. Google is a for-profit company. They are in it for the money. There is nothing wrong with it in a capitalist world, if you play by the rules. Also, services like this are scarce resources, it demands storage space, processing power, bandwidth, and etc to provide it, so it makes absolute sense that one would want money to keep providing it. Software per-se isn't scarce resources - you can copy it infinite times (but the work of writing it is, that is why there are programmers payed to write Free Software). Now you seem to be saying that if Google doesn't provide a scarce resource to you for Free (as in "Free Beer"), they will be hated just as you seem to hate Microsoft. I would hate Google if, after proving so much good stuff as free software, they gonne bankrupt for providing services without restrictions, completely for free. http://en.wikipedia.org/wiki/Scarcity -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Static memory allocation in Python
Hi, I am running a very simple python application and I noted that the memory allocation is something like 4,5M. This is a problem in my case, because I have to run 2 thousand process at the same time. The memory I need is 100k or less. Is there any way to set this for the python process? Regards, Eduardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 migration plans?
On 9/27/07, TheFlyingDutchman <[EMAIL PROTECTED]> wrote: > It seems that Python 3 is more significant for what it removes than > what it adds. > > What are the additions that people find the most compelling? - dict.items(), .values() and .keys() returns "dict views", and the .iter*() removal http://www.python.org/dev/peps/pep-3106/ - the new super() http://www.python.org/dev/peps/pep-3135/ etc... -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing
> What's the equivalent of unittest's "assertRaises"? > In certain situations it is also useful to test wether an exception > (along its type) is raised or not. > Does py.test support such thing? import py.test py.test.raises(NameError, "blablabla") -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Duck Typing and **kwds
On 10/11/07, Luis Zarrabeitia <[EMAIL PROTECTED]> wrote: > > Hi there. > > I just tried this test: > > > def f(**kwds): > print kwds > > import UserDict > d = UserDict.UserDict(hello="world") > f(**d) > > > And it fails with a TypeError exception ("f() argument after ** must be a > dictionary"). I find that weird, as UserDict should support all protocols that > dict supports, yet it doesn't seem to support ** unpacking. If instead of > UserDict I use a derivate class from dict (class mydict(dict):pass), the ** > operator works as expected. It also works if I execute f(**dict(d)) instead. > > Is that behavior expected? Is there any reason (performance, perhaps?) to > break > duck-typing in this situation? Reported, accepted and closed 5 months ago: http://bugs.python.org/issue1686487 -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Script to Download Ubuntu Gutsy ASAP
On 10/18/07, danfolkes <[EMAIL PROTECTED]> wrote: > I thought I would post the source to a program that I made that will > download the http://ubuntu.media.mit.edu/ubuntu-releases/gutsy/ > as soon as its posted. > > It checks the site every 10 min time.sleep(600) > > This is mostly untested so I would appreciate comments, and if you use > it, post that too! :) > > > import time > import urllib > > mysock = urllib.urlopen("http://ubuntu.media.mit.edu/ubuntu-releases/ > gutsy/ubunt > u-7.10-desktop-i386.iso") > #print mysock > while 1: > image = mysock.read() > if image[0:1]!='<': > oFile = open(r"image.iso",'wb') > oFile.write(image) > oFile.close > break > exit > print "Wait ", time.localtime() > time.sleep(600) > > > > > enjoy, Please, don't do it. Use the torrent, Luke. Also, use the HTTP error code - while the file is not at the server, you will receive a 404, I think. -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: A Python 3000 Question
On 10/29/07, brad <[EMAIL PROTECTED]> wrote: > Will len(a_string) become a_string.len()? I was just reading > > http://docs.python.org/dev/3.0/whatsnew/3.0.html > > One of the criticisms of Python compared to other OO languages is that > it isn't OO enough or as OO as others or that it is inconsistent. And > little things such as this seem to support those arguments. Not that it > matters really... just seems that classes with methods used in a more > consistent manner would be more appropriate in an OO langauage. Is there > a reason that len cannot be a method? > > a_string.lower() makes sense, as does a_string.split(), > a_string.strip()... why not a_string.len()? This is a FAQ: http://effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm -- http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple variable control in for loops. Doable in Python?
On Fri, Jul 18, 2008 at 4:21 PM, mark floyd <[EMAIL PROTECTED]> wrote: > I'm new to Python and have been doing work converting a few apps from Perl > to Python. I can not figure out the comparable Python structures for > multi-variable for loop control. > > Examples: > > # In Perl > for($i = 0, j = 0; $i < I_MAX && $j < J_MAX; $i+=5, $j += 10) > { >. do something > } > > // In Java > class test { > public static void main(String[] args){ > int i = 0; > int j = 1; > for(i=1, j = 0; i<11 && j < 10; i++, j++){ >System.out.println("I is: " + i); >System.out.println("J is: " + j); > } > } > } > > > // In C > #include > int main() > { > int j = 0; > int k = 0; > > for(j = 0, k = 0; j < 5 && k < 10; j++, k++) { > printf("J = %d\n", j); > printf("k = %d\n", k); > } > > return 0; > } > > I spent a good part of yesterday looking for a way to handle this style for > loop in Python and haven't been able to find an appropriate way to handle > this control style. We have this style for loop all over the place and not > being able to find a similar structure in Python could be a problem. Any > pointers to a Python equivalent structure would be much appreciated > > - Mark > > -- > http://mail.python.org/mailman/listinfo/python-list > Ops, sorry, sent only to Mark. Here is the asnwer again: for i, j in zip(range(0, I_MAX, 5), range(0, J_MAX, 10)): do_stuff(...) -- Eduardo de Oliveira Padoan http://www.petitiononline.com/veto2008/petition.html http://djangopeople.net/edcrypt/ http://whoisi.com/p/514 http://pinax.hotcluboffrance.com/profiles/edcrypt/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a good time to start learning python?
On Tue, Apr 1, 2008 at 3:57 PM, <[EMAIL PROTECTED]> wrote: > On Apr 1, 12:47 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: > > En Tue, 01 Apr 2008 13:57:55 -0300, <[EMAIL PROTECTED]> escribió: > > > > > > On Mar 31, 1:36 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > > > wrote: > > > > >> Don't be scared by the "backwards incompatible" tag - it's the way to > > >> get > > >> rid of nasty things that could not be dropped otherwise. > > > > > I would consider breaking production code to be "nasty" as well. > > > > > Please explain how the existence of Python 3.0 would break your production > > code. > > The existence of battery acid won't hurt me either, unless I come into > contact with it. If one eventually upgrades to 3.0 -- which is > ostensibly the desired path -- their code could break and require > fixing. And how would this happen? I dont know of any good software distribution that upgrades a component to another major revision without asking first. The desired path is that, if somene wants to port his software to Python 3.0, that he follow the migration plan. Final users will install Python 3.0 as python3.0 anyway, with Python 2.x as default 'python' binary. > Backward compatibility is important. C++ could break all ties with C > to "clean up" as well, but it would be a braindead move that would > break existing code bases upon upgrade. > C++ is not C. No one "upgrades" from C to C++. -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this a good time to start learning python?
On Tue, Apr 1, 2008 at 4:20 PM, <[EMAIL PROTECTED]> wrote: > > > > Please explain how the existence of Python 3.0 would break your > production > > > > code. > > > > > The existence of battery acid won't hurt me either, unless I come into > > > contact with it. If one eventually upgrades to 3.0 -- which is > > > ostensibly the desired path -- their code could break and require > > > fixing. > > > > > And how would this happen? I dont know of any good software > > distribution that upgrades a component to another major revision > > without asking first. The desired path is that, if somene wants to > > port his software to Python 3.0, that he follow the migration plan. > > Of course, that's the point. If you want to upgrade to the next > version of Python, you have to fix your code. That stinks. Your > other alternative is to remain stuck with Python 2.x, but eventually > the support for that will dry up. "Eventually" it will take a decade to happen. 2.x support will not be dropped untill gets (much) more users than Python 3.x. > > Final users will install Python 3.0 as python3.0 anyway, with Python > > 2.x as default 'python' binary. > > > > > > Backward compatibility is important. C++ could break all ties with C > > > to "clean up" as well, but it would be a braindead move that would > > > break existing code bases upon upgrade. > > > > > C++ is not C. No one "upgrades" from C to C++. > > You misunderstand. C++ has a lot of "warts" to maintain backwards > compatibility with C. The standards committee could eliminate these > warts to make the language "cleaner", but it would break a lot of > systems. It would not "break" anything that not move from C to C++, this is my point. People not willing to take the migration path (porting to 2.6, using the -3 flag, refactoring and re-running the tests untill the warning are gone, using the 2to3 tool...) will not upgrade. No one will force you to do it. 2.6 will not desappear from the python.org site anytime soon. -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie to python --- why should i learn !
On Thu, May 8, 2008 at 7:25 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hi, > > i was reading/learning some hello world program in python. > I think its very simillar to Java/C++/C#. What's different (except > syntax) ? > > what can i do easily with python which is not easy in c++/java !? Programming in a pure duck typing style http://en.wikipedia.org/wiki/Duck_typing > Tnx, > Raxit > www.mykavita.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: copy on write
El 13/01/12 11:33, Eduardo Suarez-Santana escribió: I wonder whether this is normal behaviour. Even simpler: $ python Python 2.7.2 (default, Oct 31 2011, 11:54:55) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> r={'a':1}; >>> d={}; >>> d['x']=r; >>> d['y']=r; >>> d['x']['a']=3 >>> d['y'] {'a': 3} >>> -- http://mail.python.org/mailman/listinfo/python-list
copy on write
I wonder whether this is normal behaviour. I would expect equal sign to copy values from right to left. However, it seems there is a copy-on-write mechanism that is not working. Anyone can explain and provide a working example? Thanks, -Eduardo $ python Python 2.7.2 (default, Oct 31 2011, 11:54:55) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class n: ... def __init__(self, id, cont): ... self.id = id; ... self.cont = cont; ... >>> r={'a':1}; >>> d={}; >>> d['x']=r; >>> d['y']=r; >>> x1 = n('x',d['x']); >>> y1 = n('y',d['y']); >>> x1.cont['a']=2; >>> y1.cont {'a': 2} >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Pickled objects over the network
On 7/18/07, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Tue, 17 Jul 2007 14:57:16 -0700, Walker Lindley <[EMAIL PROTECTED]> wrote: [...] > The obvious thing you're doing wrong is using pickle over a network. ;) > > http://jcalderone.livejournal.com/15864.html Ok, maybe not the best tools to the job, but there are some more secure alternatives: http://trustedpickle.sourceforge.net/ http://home.gna.org/oomadness/en/cerealizer/index.html -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Flatten a list/tuple and Call a function with tuples
def flatten(listOfLists): return list(chain(*listOfLists)) >From http://www.python.org/doc/2.4/lib/itertools-recipes.html -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWBIE: Extending a For Statement.
> > Perhaps you meant that second one to be: > > (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == > > 3) > > > Clearly not! Its called *list*-comprehension, not tuple-comprehension. ;) With () instead of [], it is a generator expression. http://docs.python.org/ref/genexpr.html -- http://mail.python.org/mailman/listinfo/python-list
Re: strange PyLint configuration (was: PEP 8 style enforcing program)
On 5/31/07, Bjoern Schliessmann <[EMAIL PROTECTED]> wrote: > Alexander Eisenhuth wrote: > > > Pylint is one of them (http://www.logilab.org/857) > > BTW: Why does pylint want all names with underscores? I tested it > and it complains about malformed names in e.g. the following cases > that are conformant to PEP 8: > > - single letter as parameter This seems to be an Logilab internal restriction. > - firstLowerCamelCase names for instances and instance methods in > class declarations ("should match [a-z_][a-z0-9_]{2,30}$") > - all lowercase method names in class declarations > No. Quoting PEP 8: Functions: """ mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. """ Methods and instances: """ Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability. """ > Those policies are barely usable, IMHO, and neither practical. I Desagree. -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Should: "for k,v in **dictionary_instance" work?
> Actually since you asked, I had to try this out > > x = range(10) > a, *b = x PEP 3132: Extended Iterable Unpacking http://www.python.org/dev/peps/pep-3132/ -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 3107 and stronger typing (note: probably a newbie question)
On 6/22/07, John Nagle <[EMAIL PROTECTED]> wrote: > Paul Boddie wrote: > > P.S. I agree with the sentiment that the annotations feature of Python > > 3000 seems like a lot of baggage. Aside from some benefits around > > writing C/C++/Java wrappers, it's the lowest common denominator type > > annotation dialect that dare not be known as such, resulting from a > > lack of consensus about what such a dialect should really do, haunted > > by a justified fear of restrictive side-effects imposed by a more > > ambitious dialect (eg. stuff you get in functional languages) on > > dynamically-typed code. I don't think the language should be modified > > in ways that only provide partial, speculative answers to certain > > problems when there's plenty of related activity going on elsewhere > > that's likely to provide more complete, proven answers to those > > problems. > > I agree. It's a wierd addition to the language. It looks like > a compromise between the "no declarations" position and the "make > the language strongly typed" position. But it's so ill-defined that > it's not helpful, and worse than either extreme. The whole > approach is antithetical to the "only one way to do it" concept. > This could lead to misery when different libraries use > incompatible type annotation systems, which is not going to be fun. > > Python made it this far without declarations, and programmers > seem to like that. We need to get Python performance up, and > the ShedSkin/Psyco restrictions seem to be enough to allow that. > Type annotations don't seem to solve any problem that really needs > to be solved. > > The main advantage of strongly typed systems is that more errors > are detected at compile time. You pay for this in additional language > baggage. PEP 3107 adds the excess baggage without providing the benefit > of compile time checks. Remember that pure CPython has no different "compile time" and runtiime. But Psyco and ShedSkin could use the annotations the way they want. Function annotations, as PEP 3107 says, just adds "arbitrary metadata annotations to Python functions" - If you follow the py-dev discutions about it, it was only accepted because it have more possible uses then just type checking. Also, there are many approches and different needs for type checking/restrictions ("safety", IDEs autocompletion hints, performance... ) So the annotations will be more a "signature documentation", so different libraries can do whatever it want of it - I problably will use only as documentation, like in: def compile(source: "something compilable", filename: "where the compilable thing comes from", mode: "is this a single statement or a suite?"): -- EduardoOPadoan (eopadoan->altavix::com) Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list