ANN: pdfposter 0.4
I'm pleased to announce pdfposter 0.4, a tool to scale and tile PDF images/pages to print on multiple pages. http://pdfposter.origo.ethz.ch/download/ Download --- :Quick Installation: easy_install -U pdfposter :Tarballs: http://pdfposter.origo.ethz.ch/download/ What is pdfposter? Scale and tile PDF images/pages to print on multiple pages. ``Pdfposter`` can be used to create a large poster by building it from multple pages and/or printing it on large media. It expects as input a PDF file, normally printing on a single page. The output is again a PDF file, maybe containing multiple pages together building the poster. The input page will be scaled to obtain the desired size. This is much like ``poster`` does for Postscript files, but working with PDF. Since sometimes poster does not like your files converted from PDF. :-) Indeed ``pdfposter`` was inspired by ``poster``. For more information please refere to the manpage or visit the `project homepage http://pdfposter.origo.ethz.ch/`_. :Author:Hartmut Goebel [EMAIL PROTECTED] :Copyright: GNU Public Licence v3 (GPLv3) :Homepage: http://pdfposter.origo.ethz.ch/ -- Schönen Gruß - Regards Hartmut Goebel Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: MDP 2.3 released!
Dear Pythonistas, we are proud to announce release 2.3 of the Modular toolkit for Data Processing (MDP): a Python data processing framework. The base of readily available algorithms includes Principal Component Analysis (PCA and NIPALS), four flavors of Independent Component Analysis (CuBICA, FastICA, TDSEP, and JADE), Slow Feature Analysis, Independent Slow Feature Analysis, Gaussian Classifiers, Growing Neural Gas, Fisher Discriminant Analysis, Factor Analysis, Restricted Boltzmann Machine, and many more. What's new in version 2.3? -- - Enhanced PCA nodes (with SVD, automatic dimensionality reduction, and iterative algorithms). - A complete implementation of the FastICA algorithm. - JADE and TDSEP nodes for more fun with ICA. - Restricted Boltzmann Machine nodes. - The new subpackage hinet allows combining nodes in arbitrary feed-forward network architectures with a HTML visualization tool. - The tutorial has been updated with a section on hierarchical networks. - MDP integrated into the official Debian repository as python-mdp. - A bunch of bug-fixes. Resources - Download: http://sourceforge.net/project/showfiles.php?group_id=116959 Homepage: http://mdp-toolkit.sourceforge.net Mailing list: http://sourceforge.net/mail/?group_id=116959 -- Pietro Berkes Gatsby Computational Neuroscience Unit UCL London, United Kingdom Niko Wilbert Institute for Theoretical Biology Humboldt-University Berlin, Germany Tiziano Zito Bernstein Center for Computational Neuroscience Humboldt-University Berlin, Germany -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: managing properties/configurations
Or a better example would be: I have the params in a config file and import this module: myconfig.py a=10 b=30 c=31 d=40 import myconfig def checkCutoff(self,up,down): .do some processing if (a = score = b): result=Bad elif (c = score = d): result=Good .do some processing return result Now when i 'manually' make some changes to the value of a,b,c,d then the the checkCutoff func should refer to the new values. -Venkat -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
On May 15, 5:13 pm, Mike Driscoll [EMAIL PROTECTED] wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. Mike Don't set arguments in the path. shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.TargetPath = r'Program Files\Mozilla Firefox\firefox.exe' shortcut.Arguments = r'https:\www.myCompanyWebsite.com\auth \preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() -- http://mail.python.org/mailman/listinfo/python-list
how to set python hosting !
Hi, i do have some basic python know-how. i want to tryout by actually implementing some python generated dynamic page etc. i am having websetup which runs with mysql on linux, and pythong is installed on it. so is there any ref. from where i can know how to configure my webserver for python. -Raxit -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree and DTDs
Or is there another library that would handle DTDs correctly, performing entity replacements? Thanks. On May 16, 12:20 am, J. Pablo Fernández [EMAIL PROTECTED] wrote: Hello, Is ElementTree supposed to load DTDs? I have some xmls heavy on entities and it fails this way: Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type help, copyright, credits or license for more information. filename = revo/xml/a.xml import xml.etree.ElementTree as ET ET.parse(filename) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/xml/etree/ElementTree.py, line 862, in parse tree.parse(source, parser) File /usr/lib/python2.5/xml/etree/ElementTree.py, line 586, in parse parser.feed(data) File /usr/lib/python2.5/xml/etree/ElementTree.py, line 1245, in feed self._parser.Parse(data, 0) File /usr/lib/python2.5/xml/etree/ElementTree.py, line 1201, in _default self._parser.ErrorColumnNumber) xml.parsers.expat.ExpatError: undefined entity jcirc;: line 13, column 10 import xml.etree.cElementTree as ET ET.parse(filename) Traceback (most recent call last): File stdin, line 1, in module File string, line 45, in parse File string, line 32, in parse SyntaxError: undefined entity c_j;: line 46, column 17 Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: managing properties/configurations
On 2008-05-16, Venkatraman.S. [EMAIL PROTECTED] wrote: Or a better example would be: Indeed, this is concrete enough to make some suggestions. I have the params in a config file and import this module: myconfig.py a=10 b=30 c=31 d=40 The big problem imho with coding such stuff directly in Python is that you have no way to extract the data from the code to display it to your users without exposing them to Python code. Why not instead throw this in a ConfigParser file like below, and load the data values from it (each time they have changed?) [score] a=10 b=30 c=31 d=40 By picking better names, the config gets much more readable. The big advantage here is that a config file is something readable and editable without appearing it to be Python. If this is too low level for your users, you can use it as a data exchange format between the processing application and the frontend application where users can change the values. import myconfig def checkCutoff(self,up,down): .do some processing if (a = score = b): result=Bad elif (c = score = d): result=Good .do some processing return result Now when i 'manually' make some changes to the value of a,b,c,d then the the checkCutoff func should refer to the new values. Maybe reload the file each time you run the program? Sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
default object comparison considered harmful?
Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
A.T.Hofkamp a écrit : Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Other than implementing a custom __cmp__ function ? Not AFAIK. FWIW, you don't necessarily need to fiddle with inheritance - you can also monkeypatch your classes (nb : for new-style objects, you cannot monkeypatch __magic__ methods on a per-object basis). Also, IIRC, this behaviour has changed in Python 3. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dbase / foxpro files
look at http://pypi.python.org/pypi?%3Aaction=searchterm=dbfsubmit=search i use dbfpy -- http://mail.python.org/mailman/listinfo/python-list
Re: send yield
castironpi wrote: On May 15, 7:16 pm, castironpi [EMAIL PROTECTED] wrote: On May 15, 6:43 pm, castironpi [EMAIL PROTECTED] wrote: On May 15, 6:16 pm, castironpi [EMAIL PROTECTED] wrote: On May 15, 4:28 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On 15 mai, 16:40, castironpi [EMAIL PROTECTED] wrote: On May 15, 9:26 am, Dan Upton [EMAIL PROTECTED] wrote: On Thu, May 15, 2008 at 9:32 AM, castironpi [EMAIL PROTECTED] wrote: Why can't I write this? -- Because your antecedent is undefined? Of the two ways to play, just to say #define this per se would be a bad move, but that's one that comes from the wrong group. #define is a big scary macro, that python hasn't been using; it's the one-line typo. Instance: #define life1 Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 ) Use it to render planes in solids. Back about 'this', I honestly hadn't remembered 'til this time, when I got a chance to reread the subject. Plus I keep ditching my radio. Jesus H. Christ. This really sounds like my mother in law. Scary, definitively.- Hide quoted text - - Show quoted text - Definitely. But, due, I forgot to complete an example. #define life1 Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 ) in C. Python: life1= 'Tron( drive.SIZE[ 0 ]/ 2, drive.SIZE[ 1 ]/ 2 )' exec( life1 ) Where does it go?- Hide quoted text - - Show quoted text - I'm supposed to talk about an entropy pool game. You can tunnel.- Hide quoted text - - Show quoted text - If I had a send-parachute, would all you need be yield? Let's drop graphics.- Hide quoted text - - Show quoted text - My character is studying chord progressions. I have right angles. I'm on a laptop, and talking in the car is fine. -- http://mail.python.org/mailman/listinfo/python-list My olive grove gave birth to many world war I biplanes I think I need more salt. This thread gave me hope... -- The three things to remember about Llamas: 1) They are harmless 2) They are deadly 3) They are made of lava, and thus nice to cuddle. -- http://mail.python.org/mailman/listinfo/python-list
Re: datamining .txt-files, library?
look at module re (rgular expression) or pyparser see http://nedbatchelder.com/text/python-parsers.html -- http://mail.python.org/mailman/listinfo/python-list
Re: how to set python hosting !
On May 16, 9:16 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, i do have some basic python know-how. i want to tryout by actually implementing some python generated dynamic page etc. i am having websetup which runs with mysql on linux, and pythong is installed on it. so is there any ref. from where i can know how to configure my webserver for python. -Raxit Hi, see http://www.wsgi.org/wsgi hth -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
A.T.Hofkamp wrote: Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) As Bruno says, this will change in 3.0: # 3.0 class A: pass ... min(1.0, A()) Traceback (most recent call last): File stdin, line 1, in module TypeError: unorderable types: A() float() For 2.5 and above you can provide a key function as a workaround: # 2.5 class A(object): pass ... min(1, A(), key=float) Traceback (most recent call last): File stdin, line 1, in module TypeError: float() argument must be a string or a number Peter -- http://mail.python.org/mailman/listinfo/python-list
Instance of class object
Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK Does this strange behavior break the LSP (Liskov substitution principle)? Regards, -- ShenLei -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
甜瓜 [EMAIL PROTECTED] writes: Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... Because the default object class doesn't have a dict or other indication of state. It's a pure Python object whose only visible properties are its type and its identity. (On the implementation level it also has a refcount.) This is necessary because all other Python objects (both new-style classes and C extensions) inherit from 'object', on the C level. Having state in 'object' would mean having that same in *all* other Python objects. The current design, on the other hand, allows creation of very lightweight python objects that don't even have a dict. Subclassing object instructs Python as to what kind of state you want your class to have. The default is to have a dict to store properties: # a class with dict -- any property goes through dict, and creating a # Foo object actually creates two objects, one Foo and one dict class Foo(object): pass But you can also specify: # an efficient 'Pair' class holding two objects class Pair(object): __slots__ = 'first', 'second' Instances of Pair take up even less room that 2-element tuples because they don't carry the size information in the object. Now, if the object class carried a dict with it, it would be impossible to create a class like 'Pair'. To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK Does this strange behavior break the LSP (Liskov substitution principle)? It follows from LSP that what the subclass may not introduce new preconditions. In this case the subclass accepts a case that the original class didn't, so it doesn't introduce a new precondition, it simply weakens (removes) an existing one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
甜瓜 [EMAIL PROTECTED] writes: Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK It's annoyingly difficult to search for information on this; python class object type inherit bind attribute aren't sufficiently distinguishing to know that we're talking about the built-in 'object' type, and inheriting from it. I'm interested to know the answer to your question; thanks for asking it. -- \ Don't be afraid of missing opportunities. Behind every failure | `\ is an opportunity somebody wishes they had missed. -- Jane | _o__) Wagner, via Lily Tomlin | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree and DTDs
J. Pablo Fernández wrote: Is ElementTree supposed to load DTDs? AFAIR, you have to provide entities by hand. Or is there another library that would handle DTDs correctly, performing entity replacements? http://codespeak.net/lxml http://codespeak.net/lxml/parsing.html#parser-options Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Using file objects with elementtree
castironpi wrote: [...], and making up words. Blah? Blah is not made up. Try again. Stefan PS: this might be getting slightly off-topic... -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
2008/5/16 Hrvoje Niksic [EMAIL PROTECTED]: 甜瓜 [EMAIL PROTECTED] writes: Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... Because the default object class doesn't have a dict or other indication of state. It's a pure Python object whose only visible properties are its type and its identity. (On the implementation level it also has a refcount.) This is necessary because all other Python objects (both new-style classes and C extensions) inherit from 'object', on the C level. Having state in 'object' would mean having that same in *all* other Python objects. The current design, on the other hand, allows creation of very lightweight python objects that don't even have a dict. Subclassing object instructs Python as to what kind of state you want your class to have. The default is to have a dict to store properties: # a class with dict -- any property goes through dict, and creating a # Foo object actually creates two objects, one Foo and one dict class Foo(object): pass But you can also specify: # an efficient 'Pair' class holding two objects class Pair(object): __slots__ = 'first', 'second' Instances of Pair take up even less room that 2-element tuples because they don't carry the size information in the object. Now, if the object class carried a dict with it, it would be impossible to create a class like 'Pair'. Really interesting. When the tuple ('first', 'second') is assigning to __slot__, a special operation is done which makes __slot__ pointing to a magic structure rather than a normal tuple. Am I right? To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK Does this strange behavior break the LSP (Liskov substitution principle)? It follows from LSP that what the subclass may not introduce new preconditions. In this case the subclass accepts a case that the original class didn't, so it doesn't introduce a new precondition, it simply weakens (removes) an existing one. Indeed. Thank you very much. -- ShenLei -- http://mail.python.org/mailman/listinfo/python-list
TPCServer and xdrlib
Hi All, I'm trying to write a multi threaded TPC server. I have used xmlrpc before for many purposes, but in this case this would not be efficient: - I have to send larger amounts of data, the overhead of converting to XML and parsing XML back would be too much pain - I have no clue how to do keep-alive with simplexmlrpcserver and it is slow to open a new connection for each RPC - I would like to do session management (authentication, then store session info on server site) which is also hard with xmlrpc. I have looked at various solutions including: - PyOrbit - too heavy weight - Pyro - uses pickle, I do not trust it BTW I do not care about the clients - they must trust the server side. In contrast, the server should not receive anything from the clients that is dangerous. I would like to use something that is fast, and can only transfer data, not code. For this reason I think I cannot use the marshal module because it is able to marshal code objects. I think I'm going to implement my own pickler over xdrlib, that will only pack/unpack data, NOT code. (It would also have the advantage that others could write clients in different languages.) Before I start re-inventing the wheel: - Is there another (already existing) higher level framework that I can try? It should be safe and fast, that is the only restriction. - Do you think that it is a good idea to use xdrlib? I haven't seen projects using it directly. For me it is like the rotor module was - it was there but almost nobody used it. There might be a better lower level library which I don't know of. Thank you, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Mike Driscoll wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. I see four problems: 1) you should not hardcode the backslashes ('\'), instead use os.sep for it. 2) In URIs there are no backslashes, only forward slashes. You coded https:\... which is _WRONG_. URIs are protocoll://host/resource, where for some protocolls host is empty (file protocoll e.g.). 3) You assume, that Firefox is always installed at C:\Program Files\Mozilla Firefox\firefox.exe However the path largely differs from system to system. On *nix systems you normally have all programs in $PATH, so a non full qualified path would be sufficient. On Windows this works, too, _IF_ the installation directory of the to be used application get's added to the PATH environment variable. Wolfgang Draxinger -- E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867 -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Wolfgang Draxinger wrote: 1) you should not hardcode the backslashes ('\'), instead use os.sep for it. With respect, the OP is creating a Windows desktop shortcut. Unless Microsoft suddenly decide to change their use of the backslash, I suggest that this is a needless generalisation. 3) You assume, that Firefox is always installed at C:\Program Files\Mozilla Firefox\firefox.exe However the path largely differs from system to system. This is broadly true. However, it's fairly clear from the phrase the user's desktop that the OP is working in some kind of corporate environment where he can be fairly sure where Firefox is installed by policy. In addition, it's not so easy to find its path if it's not in the default place since apps very rarely add their location to the system PATH these days (and Firefox certainly doesn't). You could scan the registry for its App Paths entry in the registry but I don't know if any other way if it's not the default browser (which it's clear from the original post it may not be). Sorry to sound a bit negative, but I felt that a couple of your points, while valid, were not altogether helpful to the situation the OP was in. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Wolfgang Draxinger wrote: 1) you should not hardcode the backslashes ('\'), instead use os.sep for it. With respect, the OP is creating a Windows desktop shortcut. Unless Microsoft suddenly decide to change their use of the backslash, I suggest that this is a needless generalisation. 3) You assume, that Firefox is always installed at C:\Program Files\Mozilla Firefox\firefox.exe However the path largely differs from system to system. This is broadly true. However, it's fairly clear from the phrase the user's desktop that the OP is working in some kind of corporate environment where he can be fairly sure where Firefox is installed by policy. In addition, it's not so easy to find its path if it's not in the default place since apps very rarely add their location to the system PATH these days (and Firefox certainly doesn't). You could scan the registry for its App Paths entry in the registry but I don't know if any other way if it's not the default browser (which it's clear from the original post it may not be). Sorry to sound a bit negative, but I felt that a couple of your points, while valid, were not altogether helpful to the situation the OP was in. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: usage of python
On May 14, 9:13 pm, Rajarshi [EMAIL PROTECTED] wrote: Thanks to the all posters. This will be very useful! No Problem :). Let me know if you need any code snippets. P.S. I wouldn't mind working with you to prepare introductory material and examples for beginners if it becomes public property. -- http://mail.python.org/mailman/listinfo/python-list
Re: managing properties/configurations
On May 16, 7:45 am, A.T.Hofkamp [EMAIL PROTECTED] wrote: Thanks By picking better names, the config gets much more readable. The big advantage here is that a config file is something readable and editable without appearing it to be Python. If this is too low level for your users, you can use it as a data exchange format between the processing application and the frontend application where users can change the values. The problem being, if i change the config file, then the configobj has to reload this file again. I do not want to 'refresh' the config obj per transaction but only when the config params change. Now when i 'manually' make some changes to the value of a,b,c,d then the the checkCutoff func should refer to the new values. Maybe reload the file each time you run the program? The program is never-ending and do not think in terms of websites here - probably something like a server/middleware which can never be brought down. I was thinking along the terms of an Interrupt driven program, which when getting a custom interrupts reloads the file - any potential loopholes/falls that anyone can anticipate? Regards, Venkat -- http://mail.python.org/mailman/listinfo/python-list
ply yacc lineno not working?
This is a fragment from my yacc file: import ply.yacc as yacc from lex import tokens from ast import * def p_msd(p): rmsd : SCHEMA WORD LBRACE defs RBRACE p[0] = MSDSchema(p[2]) print p.lineno(5) # Line number of the right brace p[0].items = p[4] Here is a test input: schema TestSchema { field name : varchar { required; size 100; } } My program prints out 1. No matter what I do, YaccProduction.lineno(n) returns 1 for every possible n between 0 and 5. What am I doing wrong? Can it be a problem if I use this in my lexer: # Whitespace is mostly ignored, except inside quoted words. def t_ws(t): r'[\n\r\t ]+' # We do not return anything so this will be ignored. If so, how can I easily ignore newlines while preserving the line number for yacc.parse ? Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
class problem, NoneType obj has no attribute
wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: def __init__(self, ID, movies): self.ID = ID self.movies = movies def getID(): return self.ID def getMovies(): return self.movies import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) print cust1.getID() -- http://mail.python.org/mailman/listinfo/python-list
Re: ply yacc lineno not working?
I'm sorry for the dumb question. I had to add these to the lexer: def t_comment(t): r\#[^\n]*\n t.lexer.lineno += 1 # We do not return anything - comments are ignored. # Define a rule so we can track line numbers def t_newline(t): r'\n+' t.lexer.lineno += len(t.value) Well, it is not very straightforward. From the docs, it was not clear that I HAVE TO increment t.lexer.lineno in my lexer if you want yacc to parse line numbers. But it is logical. I believe this could be done automatically, since line number ALWAYS means \n, there is nothing to be configured here. (Am I wrong? There can be parsers to parse files where new lines are chr(255) or something?) Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev schrieb: cust1 = customer.__init__('12',['1','435','2332']) cust1 = customer('12',['1','435','2332']) Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: no inputstream?
On May 15, 10:31 pm, castironpi [EMAIL PROTECTED] wrote: On May 15, 6:49 pm, castironpi [EMAIL PROTECTED] wrote: On May 15, 6:42 pm, John Krukoff [EMAIL PROTECTED] wrote: On Thu, 2008-05-15 at 17:32 -0600, John Krukoff wrote: On Thu, 2008-05-15 at 17:11 -0600, John Krukoff wrote: On Thu, 2008-05-15 at 15:35 -0700, max wrote: On May 15, 6:18 pm, MRAB [EMAIL PROTECTED] wrote: On May 15, 9:00 pm, max [EMAIL PROTECTED] wrote: you're right, my java implementation does indeed parse for Id3v2 (sorry for the confusion). i'm using the getrawid3v2() method of this bitstream class (http://www.javazoom.net/javalayer/docs/docs0.4/ javazoom/jl/decoder/Bitstream.html) to return an inputstream that then i buffer and parse. apologies if i misrepresented my code! back to python, i wonder if i'm misusing the mutagen id3 module. this brief tutorial (http://www.sacredchao.net/quodlibet/wiki/Development/ Mutagen/Tutorial) leads me to believe that something like this might work: from mutagen.mp3 import MP3 id3tags = MP3(urllib2.urlopen(URL)) but this gives me the following TypeError: coercing to Unicode: need string or buffer, instance found. does this mean i need to convert the file-like object that is returned by urlopen() into a unicode object? if so, do i just decode() with 'utf-8', or is this more complex? as of now, doing so gives me mostly No such file or directory errors, with a few HTTP 404s. [snip] I think it's expecting the path of the MP3 but you're giving it the contents. cool, so how do i give it the path, if not in the form of a URL string? maybe this is obvious... -- http://mail.python.org/mailman/listinfo/python-list It doesn't look like you can, with mutagen. So, time to find a different library that supports arbitrary file objects instead of only file paths. I'd suggest starting here: http://pypi.python.org/pypi?%3Aaction=searchterm=id3submit=search Possibly one with actual documentation, since that would also be a step up from mutagen. After a bit of time looking around, looks like nearly all the python id3 modules expect to work with filenames, instead of file objects. I can't vouch for it, and the documentation still looks sparse, but this module at least looks capable of accepting a file object: http://pypi.python.org/pypi/tagpy Looks like it'd be a challenge to build if you're on windows, since it depends on an external library. Alternately, you could probably create a subclass of the mutagen stuff that used an existing file object instead of opening a new one. No idea what that might break, but seems like it would be worth a try. As last ditch option, could write the first few kb of the file out to a temp file and see if mutagen will load the partial file. Okay, now I'm officially spending too much time looking through this stuff. However, looks like the load method of the MP3 class is what you'd want to override to change mutagen's file loading behavior. Probably pass the URL as the filename, and take a cut paste version of the default load method from ID3FileType and change it to use urllib2 to open it instead of a local file open. Might work. Might not. No warranty express or implied. -- John Krukoff [EMAIL PROTECTED] Land Title Guarantee Company- Hide quoted text - - Show quoted text - I'm supposed to question time.toomuch.spend. NAMERS!- Hide quoted text - - Show quoted text - Is there a way 'time.toomuch.spend' can be scanned for in code? If not, let's play! really, really appreciate your help, john. gonna have to ponder my next move here... -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
Christian Heimes wrote: globalrev schrieb: cust1 = customer.__init__('12',['1','435','2332']) cust1 = customer('12',['1','435','2332']) ... and before that from customer import customer Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: managing properties/configurations
On 2008-05-16, Venkatraman.S. [EMAIL PROTECTED] wrote: The problem being, if i change the config file, then the configobj has to reload this file again. I do not want to 'refresh' the config obj per transaction but only when the config params change. If you have trustable time stamps at your file system, you could check the time stamp before loading. I was thinking along the terms of an Interrupt driven program, which when getting a custom interrupts reloads the file - any potential loopholes/falls that anyone can anticipate? Many unix deamons use SIGHUP signal to reload configs. Maybe that would be an option? Sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Pyparsing Question
Hi all, I have a question on PyParsing. I am trying to create a parser for a hierarchical todo list format, but have hit a stumbling block. I have parsers for the header of the list (title and description), and the body (recursive descent on todo items). Individually they are working fine, combined they throw an exception. The code follows: #!/usr/bin/python # parser.py import pyparsing as pp def grammar(): underline = pp.Word(=).suppress() dotnum = pp.Combine(pp.Word(pp.nums) + .) textline = pp.Combine(pp.Group(pp.Word(pp.alphas, pp.printables) + pp.restOfLine)) number = pp.Group(pp.OneOrMore(dotnum)) headtitle = textline headdescription = pp.ZeroOrMore(textline) head = pp.Group(headtitle + underline + headdescription) taskname = pp.OneOrMore(dotnum) + textline task = pp.Forward() subtask = pp.Group(dotnum + task) task (taskname + pp.ZeroOrMore(subtask)) maintask = pp.Group(pp.LineStart() + task) parser = pp.OneOrMore(maintask) return head, parser text = My Title Text on a longer line of several words. More test and more. text2 = 1. Task 1 1.1. Subtask 1.1.1. More tasks. 1.2. Another subtask 2. Task 2 2.1. Subtask again head, parser = grammar() print head.parseString(text) print parser.parseString(text2) comb = head + pp.OneOrMore(pp.LineStart() + pp.restOfLine) + parser print comb.parseString(text + text2) #=== Now the first two print statements output the parse tree as I would expect, but the combined parser fails with an exception: Traceback (most recent call last): File parser.py, line 50, in ? print comb.parseString(text + text2) . . [Stacktrace snipped] . raise exc pyparsing.ParseException: Expected start of line (at char 81), (line:9, col:1) Any help appreciated! Cheers, -- Ant. -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Sincerely, Albert Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev a écrit : wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: 1/ naming convention : class names should be CamelCased 2/ unless you need compatibility with years old Python versions, use newstyle classes class Customer(object): def __init__(self, ID, movies): self.ID = ID self.movies = movies 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants def __init__(self, id, movies): self.id = id self.movies = movies def getID(): return self.ID def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. cust1 = Customer('12', ['1', '435', '2332']) print cust1.getID() print cust1.id -- http://mail.python.org/mailman/listinfo/python-list
Re: TPCServer and xdrlib
On May 16, 7:16 am, Laszlo Nagy [EMAIL PROTECTED] wrote: Hi All, Hello, :-) I'm trying to write a multi threaded TPC server. I have used xmlrpc How exactly did you come to the conclusion that your server must be multi threaded ? - I have to send larger amounts of data, the overhead of converting to XML and parsing XML back would be too much pain - What's the expected amount of data you have to transfer ? - What's the expected network bandwidth ? - What's the expected acceptable transfer time ? - How many users are expected to be transfering data at the same time ? I have looked at various solutions including: - PyOrbit - too heavy weight - Pyro - uses pickle, I do not trust it Did you consider gzipping your XML (or YAML) packets ? Would the transfer time be acceptable in this case ? BTW I do not care about the clients - they must trust the server side. Oh, he said he _doesn't care about the clients_ ! ;-) In contrast, the server should not receive anything from the clients that is dangerous. I would like to use something that is fast, and can only transfer data, not code. For this reason I think I cannot use the marshal module because it is able to marshal code objects. I think I'm going to implement my own pickler over xdrlib, that will only pack/unpack data, NOT code. (It would also have the advantage that others could write clients in different languages.) In general I would avoid that. Try to better estimate the speed requirements, to see if you really need do to this. Before I start re-inventing the wheel: - Is there another (already existing) higher level framework that I can try? It should be safe and fast, that is the only restriction. There's Twisted. http://twistedmatrix.com/projects/core/documentation/howto/servers.html - Do you think that it is a good idea to use xdrlib? I haven't seen projects using it directly. For me it is like the rotor module was - it It's probably the best way to send binary stuff over the network. But, again, I would avoid doing so. was there but almost nobody used it. There might be a better lower level library which I don't know of. Thank you, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A() -- http://mail.python.org/mailman/listinfo/python-list
Re: TPCServer and xdrlib
Did you consider gzipping your XML (or YAML) packets ? Would the transfer time be acceptable in this case ? That would add even more to the overhead of transcoding the transportlayer. Switching from XMLRPC to a json-based protocol reduced in a project of mine reduced the overhead 10-20fold - mainly because of reduced size and parsing efforts. Diez -- http://mail.python.org/mailman/listinfo/python-list
free dictionary english - spanish?
i want to write a translationprogram, i have the webapp done already. i need a big free dictionary though. english-spanish/spanish-english seems like the best i know some spanish and thats what also is needed the most i think together with chinese. anywhere you can download one? preferrably easy to parse... -- http://mail.python.org/mailman/listinfo/python-list
morning in Python
I want to talk to the newsgroup. As I have found that its readers will be non-trivially attentive, I esteem it a worthwhile production, for finely divided values of worth while. (Disclaimer: Don't call me millionaire; life money...). It is not clear that I will be posting code first thing, for a range of values of I. (Yes I have tackled decentralization and contribution in identity before.) It's possible that I just like to write, in which case, fol. the foregoing, I might just like to write messages, plainly ignorant of who replies. My name still works as castironpi, since I just don't have e-mail. For the plot, though, I do not know who's reading by name. If that makes me a villian, that's ok, mysteries are good. I've evaluated *my* character, ladies gentlemen, before. I just know the trick, which may originate in the older stories of night and day. First things first, I try to represent story lines, which involves some non-trivial automation of computer-modeled intelligence. It involves live people too. You might be reading. I'm not. From what plans I come with, it takes a second to infer that I'm on the newsgroup, which generates some purified roles. This has some consequences for my character upon entrance. It also complicates the matter of getting to Python, connecting me with a larger fraction of the community. I am on a computer and have made games. I've tried Pygame. I have a proposition to ask you all: Python emphasizes state. Is it true? -- http://mail.python.org/mailman/listinfo/python-list
Re: datamining .txt-files, library?
On May 16, 3:22 am, [EMAIL PROTECTED] wrote: look at module re (rgular expression) or pyparser seehttp://nedbatchelder.com/text/python-parsers.html This ties in to 'call tree tool?' from yesterday. Do we have any visualization modules? My two examples were 're' and 'call trees' -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
On 16 Maj, 13:54, Peter Otten [EMAIL PROTECTED] wrote: Christian Heimes wrote: globalrev schrieb: cust1 = customer.__init__('12',['1','435','2332']) cust1 = customer('12',['1','435','2332']) ... and before that from customer import customer Peter why do i have to write that? if i do import customer im importing everything no? but youre right it doesnt work unless i do, i just dont get why. -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: 1/ naming convention : class names should be CamelCased 2/ unless you need compatibility with years old Python versions, use newstyle classes class Customer(object): def __init__(self, ID, movies): self.ID = ID self.movies = movies 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants def __init__(self, id, movies): self.id = id self.movies = movies def getID(): return self.ID def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. cust1 = Customer('12', ['1', '435', '2332']) print cust1.getID() print cust1.id what should init return normally? a customer-object? class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies return self ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Mike Driscoll wrote: On May 15, 2:03 pm, Larry Bates [EMAIL PROTECTED] wrote: Mike Driscoll wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. Mike Either you copied wrong or the problem is: C:\C:\Program Files... Note the C:\ is specified twice in the string. I think it should read: C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php -Larry Yeah, I know that it's in there twice and that that is the problem. But I'm not causing that extra C:\. I run it exactly as above and that is what I get for the output. I think it's the COM object. Maybe I better just re-post this to the PyWin32 list... Thanks, Mike I use Inno Setup on most of my applications and use it to create my desktop, quicklaunch and Start shortcuts. Would that be an option for you? -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
On May 16, 5:44 am, Wolfgang Draxinger [EMAIL PROTECTED] wrote: Mike Driscoll wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. I see four problems: 1) you should not hardcode the backslashes ('\'), instead use os.sep for it. 2) In URIs there are no backslashes, only forward slashes. You coded https:\... which is _WRONG_. URIs are protocoll://host/resource, where for some protocolls host is empty (file protocoll e.g.). That was an accident...my original code was correct, but I stupidly decided to generalize my website's name and put the wrong slashes in. 3) You assume, that Firefox is always installed at C:\Program Files\Mozilla Firefox\firefox.exe However the path largely differs from system to system. On *nix systems you normally have all programs in $PATH, so a non full qualified path would be sufficient. On Windows this works, too, _IF_ the installation directory of the to be used application get's added to the PATH environment variable. I don't assume it at all. At my place of business, that's where Firefox is. If it's not installed there when the user logs in, one of my scripts installs it automatically. Wolfgang Draxinger -- E-Mail address works, Jabber: [EMAIL PROTECTED], ICQ: 134682867 -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: 1/ naming convention : class names should be CamelCased 2/ unless you need compatibility with years old Python versions, use newstyle classes class Customer(object): def __init__(self, ID, movies): self.ID = ID self.movies = movies 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants def __init__(self, id, movies): self.id = id self.movies = movies def getID(): return self.ID def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. cust1 = Customer('12', ['1', '435', '2332']) print cust1.getID() print cust1.id print cust, cust1.idnbr, cust1.movies() Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 24, in module print cust, cust1.idnbr, cust1.movies() TypeError: 'list' object is not callable when class = class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies print cust, cust1.idnbr, cust1.movies() Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 24, in module print cust, cust1.idnbr, cust1.movies() TypeError: 'list' object is not callable when class = class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies -- http://mail.python.org/mailman/listinfo/python-list
Re: Dbase / foxpro files
[EMAIL PROTECTED] wrote: look at http://pypi.python.org/pypi?%3Aaction=searchterm=dbfsubmit=search i use dbfpy That's another option. The caveat is that dbfpy specifically states that it only works on simple files. I'm pretty sure ODBC is universal. The nice thing about using ODBC is that: 1) Nothing to install, every Windows machine has ODBC 2) If you upgrade to some other ODBC compliant database you have little or no changes that are required to your application. Just my 2 cents. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
On May 16, 1:51 am, Chris [EMAIL PROTECTED] wrote: On May 15, 5:13 pm, Mike Driscoll [EMAIL PROTECTED] wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. Mike Don't set arguments in the path. shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.TargetPath = r'Program Files\Mozilla Firefox\firefox.exe' shortcut.Arguments = r'https:\www.myCompanyWebsite.com\auth \preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() Ah. I was unaware of the Arguments parameter. That works quite well. Where does one find this information anyway? I think I found mine from bits and pieces scattered in various tutorials. Thanks a lot. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
On May 15, 8:24 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Thu, 15 May 2008 12:13:56 -0300, Mike Driscoll [EMAIL PROTECTED] escribió: I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: Try this different approach, using the IShellLink interface:http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32/win32c... -- Gabriel Genellina Thanks Gabriel...it looks a little overwhelming, but I'll file it away for future reference. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Pydev Console use vs. stdout/stderr
On May 15, 5:26 pm, [EMAIL PROTECTED] wrote: On May 15, 3:12 pm, RossGK [EMAIL PROTECTED] wrote: Just getting used to the PyDev environment in eclipse by playing with a few simple programs. I'm also using wxPython GUI stuff. I've noticed though that simple print commands in my code cause a wxPython:stdout/stderr popup window to display any print's I might be dumping out, rather than going to the console in Eclipse. Any suggestions of why this is? Another code example I was looking at (which does not include any wx GUI stuff) has print commands whose result ends up in the Eclipse console, just to further confuse me. Is this something that wxPython is imposing on the environment? Yes, it's wxPython, it does that by default. Pass the keyword argument redirect set to False to your wx.App object constructor: app = wx.App(redirect=False) Or to whatever class you derived from wx.App: app = ClassDerivingFromWxApp(redirect=False) Thank you! That was very helpful, and works fine. -Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On May 16, 7:23 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A()- Hide quoted text - - Show quoted text - I question the real-world examples of coercion, casting, and upcasting. C insists that defining by operator, which may or may not relate to system, is the only legal move. I doubt operator+ is well- defined on non-ideal structures. Rationals are not floats, but system got checked. Define concurrency. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
On May 16, 8:09 am, Larry Bates [EMAIL PROTECTED] wrote: Mike Driscoll wrote: On May 15, 2:03 pm, Larry Bates [EMAIL PROTECTED] wrote: Mike Driscoll wrote: Hi, I've had this niggling issue from time to time. I want to create a shortcut on the user's desktop to a website that specifically loads Firefox even if Firefox is not the default browser. I usually use COM as it allows very specific settings of the shortcut, such as the Working Directory and the Target Path. However, the following will not work for some reason: code import win32com.client import winshell shell = win32com.client.Dispatch('WScript.Shell') userDesktop = winshell.desktop() shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk') shortcut.Targetpath = r'C:\Program Files\Mozilla Firefox\firefox.exe https:\www.myCompanyWebsite.com\auth\preauth.php' shortcut.WorkingDirectory = r'C:\Program Files\Mozilla Firefox' shortcut.save() /code This creates the following target path (which doesn't work): C:\C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php If I leave the website off, it works. If I leave the path to Firefox out, it works too. Is there another method I can use other than creating the shortcut by hand and using the shutil module? Thank you for any ideas. Mike Either you copied wrong or the problem is: C:\C:\Program Files... Note the C:\ is specified twice in the string. I think it should read: C:\Program Files\Mozilla Firefox\firefox.exe https: \www.myCompanyWebsite.com\auth\preauth.php -Larry Yeah, I know that it's in there twice and that that is the problem. But I'm not causing that extra C:\. I run it exactly as above and that is what I get for the output. I think it's the COM object. Maybe I better just re-post this to the PyWin32 list... Thanks, Mike I use Inno Setup on most of my applications and use it to create my desktop, quicklaunch and Start shortcuts. Would that be an option for you? -Larry I use Inno too for my applications. However, in this case, I have to create the shortcut as part of the login process based on what group the user is in. Chris's solution worked for my needs and I think Gabriel's will work too, if I figure it out. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev wrote: On 16 Maj, 13:54, Peter Otten [EMAIL PROTECTED] wrote: Christian Heimes wrote: globalrev schrieb: cust1 = customer.__init__('12',['1','435','2332']) cust1 = customer('12',['1','435','2332']) ... and before that from customer import customer Peter why do i have to write that? if i do import customer im importing everything no? but youre right it doesnt work unless i do, i just dont get why. It becomes clearer if you follow the usual naming conventions and start the class name with an uppercase letter: # in file customer.py class Customer: # your code The import then becomes from customer import Customer i. e. the first customer denotes the module, the second Customer the class. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Mike Driscoll wrote: Ah. I was unaware of the Arguments parameter. That works quite well. Where does one find this information anyway? I think I found mine from bits and pieces scattered in various tutorials. The canonical place would be: http://msdn.microsoft.com/en-us/library/bb774950(VS.85).aspx TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: TPCServer and xdrlib
Laszlo Nagy [EMAIL PROTECTED] wrote: I'm trying to write a multi threaded TPC server. I have used xmlrpc before for many purposes, but in this case this would not be efficient: - I have to send larger amounts of data, the overhead of converting to XML and parsing XML back would be too much pain - I have no clue how to do keep-alive with simplexmlrpcserver and it is slow to open a new connection for each RPC - I would like to do session management (authentication, then store session info on server site) which is also hard with xmlrpc. I have looked at various solutions including: - PyOrbit - too heavy weight - Pyro - uses pickle, I do not trust it It is possible to change the serialization used by Pyro http://pyro.sourceforge.net/manual/9-security.html#pickle to the the 'gnosis' XML Pickler. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On May 16, 8:18 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 7:23 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A()- Hide quoted text - - Show quoted text - I question the real-world examples of coercion, casting, and upcasting. C insists that defining by operator, which may or may not relate to system, is the only legal move. I doubt operator+ is well- defined on non-ideal structures. Rationals are not floats, but system got checked. Define concurrency.- Hide quoted text - - Show quoted text - The computer will have to learn knowledge at a distributed real-time rate. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Tim Golden [EMAIL PROTECTED] wrote: 3) You assume, that Firefox is always installed at C:\Program Files\Mozilla Firefox\firefox.exe However the path largely differs from system to system. This is broadly true. However, it's fairly clear from the phrase the user's desktop that the OP is working in some kind of corporate environment where he can be fairly sure where Firefox is installed by policy. In addition, it's not so easy to find its path if it's not in the default place since apps very rarely add their location to the system PATH these days (and Firefox certainly doesn't). You could scan the registry for its App Paths entry in the registry but I don't know if any other way if it's not the default browser (which it's clear from the original post it may not be). It's not too hard to get the required command line from the registry: import _winreg print _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT, 'FirefoxURL\shell\open\command') and of course it throws an exception if firefox isn't installed. Then just replace %1 with the url to get the actual command you need. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On May 16, 8:18 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 7:23 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A()- Hide quoted text - - Show quoted text - I question the real-world examples of coercion, casting, and upcasting. C insists that defining by operator, which may or may not relate to system, is the only legal move. I doubt operator+ is well- defined on non-ideal structures. Rationals are not floats, but system got checked. Define concurrency.- Hide quoted text - - Show quoted text - I would be bouncing localcy and remoticy. What word's on the bar? -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev a écrit : On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : (snip) cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. what should init return normally? None. Your __init__ is fine, the problem is with the call. To instanciate a class, you call the class object itself, passing it the arguments awaited by __init__, ie: cust1 = Customer('12', ['1', '435', '2332']) -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Spirals are important. -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
On Fri, 2008-05-16 at 06:07 -0700, globalrev wrote: On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: 1/ naming convention : class names should be CamelCased 2/ unless you need compatibility with years old Python versions, use newstyle classes class Customer(object): def __init__(self, ID, movies): self.ID = ID self.movies = movies 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants def __init__(self, id, movies): self.id = id self.movies = movies def getID(): return self.ID def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. cust1 = Customer('12', ['1', '435', '2332']) print cust1.getID() print cust1.id what should init return normally? a customer-object? class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies return self ? No. __init__ should not return anything (rather, it should return None, but it'll do that on its own without you telling it to return anything). The problem is that you are trying to create an object with __init__, but that is not what it does. It *initializes* objects that already exist. when you call a class, it creates a new instance using __new__(), and then initializes it using __init__(). So if you were really inclined to muck around. You could do something like cust1 = Customer.__new__(Customer) cust1.__init__('12', ['1','435', '2332']) But that would just be silly. What you really want is this: cust1 = Customer('12', ['1','435', '2332']) which does the same thing. Don't explicitly call under-under variables unless you really have to. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 8:51 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Spirals are important. I'd be modeling streams, in par. crossing them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem creating a shorcut
Duncan Booth wrote: It's not too hard to get the required command line from the registry: import _winreg print _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT, 'FirefoxURL\shell\open\command') and of course it throws an exception if firefox isn't installed. Then just replace %1 with the url to get the actual command you need. That's neat. You learn something new... TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev wrote: On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : wassup here? 7 Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 22, in module print cust1.getID() AttributeError: 'NoneType' object has no attribute 'getID' class customer: 1/ naming convention : class names should be CamelCased 2/ unless you need compatibility with years old Python versions, use newstyle classes class Customer(object): def __init__(self, ID, movies): self.ID = ID self.movies = movies 3/ naming conventions : ALL_UPPER_NAMES denote (pseudo) constants def __init__(self, id, movies): self.id = id self.movies = movies def getID(): return self.ID def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. import os import customer import movie mv1 = open('C:\\Python25\\myPrograms\\netflix\\mv1exp2.txt', 'r+') mv1str = mv1.read() print mv1str.count(',5,') cust1 = customer.__init__('12',['1','435','2332']) __init__ is automagically called on instanciation, so you don't have to call it yourself. And FWIW, your __init__ returns None. cust1 = Customer('12', ['1', '435', '2332']) print cust1.getID() print cust1.id print cust, cust1.idnbr, cust1.movies() Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 24, in module print cust, cust1.idnbr, cust1.movies() TypeError: 'list' object is not callable when class = class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies print cust, cust1.idnbr, cust1.movies() Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 24, in module print cust, cust1.idnbr, cust1.movies() TypeError: 'list' object is not callable when class = class customer: def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies You really should back up and go through the Python tutorial. cust1.movies() tells Python to call the object pointed to by cust1.movies (note the parenthesis after .movies). Since that object (in your case) is a list, that makes no sense (which is exactly what the traceback said). print cust, cust1.idnbr, cust1.movies is what you want here. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Variable by label
Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable by label
[EMAIL PROTECTED] wrote: Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. Thank you. There are the globals() and locals() builtins. a = 42 globals()['a'] 42 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On May 16, 8:35 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:18 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 7:23 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A()- Hide quoted text - - Show quoted text - I question the real-world examples of coercion, casting, and upcasting. C insists that defining by operator, which may or may not relate to system, is the only legal move. I doubt operator+ is well- defined on non-ideal structures. Rationals are not floats, but system got checked. Define concurrency.- Hide quoted text - - Show quoted text - I would be bouncing localcy and remoticy. What word's on the bar?- Hide quoted text - - Show quoted text - Can you suffixize words? I have corner, cornercy, lunacy, emphatic, emphasize, a value of Y, orderings, say, remoticy, cross. Come do graphics. Anybody speak? For verbs, I have: say, speak, see, talk, and stack. Pretty harmless. Still here? -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
globalrev a écrit : On 16 Maj, 14:19, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: globalrev a écrit : (snip) def getMovies(): return self.movies 4/ Python has support for computed attributes, so you just don't need these getters. when class = class customer: Please, do yourself and the world a favour, follow naming conventions (not only will this make your code more readable, but also quite a lot of things in Python rely on conventions). And really, use newstyle classes unless you have a *very* compelling reason not to. class Customer(object): def __init__(self, idnbr, movies): self.idnbr = idnbr self.movies = movies print cust, cust1.idnbr, cust1.movies() Why do you want to call a list ??? Traceback (most recent call last): File C:\Python25\myPrograms\netflix\netflix.py, line 24, in module print cust, cust1.idnbr, cust1.movies() TypeError: 'list' object is not callable Indeed. cust1.movie being a list, that's just what you would expect. Hint : what do you think will happen with the following code: alist = [1, 2, 3] alist() When I say that Python has support for computed attributes, it doesn't mean it will automagically add getters/setters for your attributes, but that by default you just *don't need* getters/setters - you'll be able to transparently add them latter if there's an effective need for them - where transparently means without client code knowing it's in fact calling a getter or setter. Example: # before: class Foo(object): def __init__(self, name): # just a plain attribute assignment self.name = name f = Foo('bruno') # just a plain attribute access print f.name # after class Foo(object): def __init__(self, name): # still looks like a plain attribute assignment self.name = name # defining the setter and getter def _setname(self, name): print setting %s name to '%s' % (self, name) self._name = name def _getname(self): print retrieving %s name ('%s') % (self, self._name) return self._name.upper() # and making this a computed attribute using the getter and # setter under the hood name = property(fget=_getname, fset=_setname) f = Foo('bruno') # still looks like a plain attribute access print f.name Also, given your recent posts here, I strongly suggest you take some time doing at least the official tutorial. HTH -- http://mail.python.org/mailman/listinfo/python-list
writing python extensions in assembly
Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable by label
[EMAIL PROTECTED] wrote: Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. Thank you. vars()[foo] but if you are doing this you are almost certainly making your life harder than it needs to be. Usually you really just want to keep the values in a dict. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 4:16 am, Hrvoje Niksic [EMAIL PROTECTED] wrote: 甜瓜 [EMAIL PROTECTED] writes: Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... Because the default object class doesn't have a dict or other indication of state. It's a pure Python object whose only visible properties are its type and its identity. (On the implementation level it also has a refcount.) This is necessary because all other Python objects (both new-style classes and C extensions) inherit from 'object', on the C level. Having state in 'object' would mean having that same in *all* other Python objects. The current design, on the other hand, allows creation of very lightweight python objects that don't even have a dict. Subclassing object instructs Python as to what kind of state you want your class to have. The default is to have a dict to store properties: # a class with dict -- any property goes through dict, and creating a # Foo object actually creates two objects, one Foo and one dict class Foo(object): pass But you can also specify: # an efficient 'Pair' class holding two objects class Pair(object): __slots__ = 'first', 'second' Instances of Pair take up even less room that 2-element tuples because they don't carry the size information in the object. Now, if the object class carried a dict with it, it would be impossible to create a class like 'Pair'. To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK Does this strange behavior break the LSP (Liskov substitution principle)? It follows from LSP that what the subclass may not introduce new preconditions. In this case the subclass accepts a case that the original class didn't, so it doesn't introduce a new precondition, it simply weakens (removes) an existing one. Honor and narrow down: Having state in 'object' would mean having that same in *all* other Python objects. The current design, on the other hand, allows creation of very lightweight python objects that don't even have a dict. to: mass volume, probably isolating -same-object- and -state-. No sinking. -- http://mail.python.org/mailman/listinfo/python-list
Re: class problem, NoneType obj has no attribute
On Fri, 2008-05-16 at 06:04 -0700, globalrev wrote: On 16 Maj, 13:54, Peter Otten [EMAIL PROTECTED] wrote: Christian Heimes wrote: globalrev schrieb: cust1 = customer.__init__('12',['1','435','2332']) cust1 = customer('12',['1','435','2332']) ... and before that from customer import customer Peter why do i have to write that? if i do import customer im importing everything no? Not exactly. That's how perl and PHP tend to do it, but python's import system is much more conservative (and far superior because of it). When you import a name you get that name and nothing else. You can still call your class without doing from customer import customer, but you have to include the module in the class name like this: cust1 = customer.customer('12',['1','435','2332']) Everything stays hidden behind the name customer. That way, if customer defines a class that has the same name that you already have in your namespace, it won't get overwritten. Say you define a class Purchase in your customer module, and then in the interpreter, you write py import customer py Purchase = 4 py bread = customer.Purchase('bread') py Purchase 4 py bread customer.Purchase object at 0xabcdefab py Purchase and customer.Purchase can live happily side by side. In perl or PHP, the default behavior causes errors which are hard to debug because you can't see what names are being pulled into your namespace. but youre right it doesnt work unless i do, i just dont get why. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: ply yacc lineno not working?
I dunno but on Dos/Windows a newline is usually \r\n (although that still includes a \n..) Laszlo Nagy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm sorry for the dumb question. I had to add these to the lexer: def t_comment(t): r\#[^\n]*\n t.lexer.lineno += 1 # We do not return anything - comments are ignored. # Define a rule so we can track line numbers def t_newline(t): r'\n+' t.lexer.lineno += len(t.value) Well, it is not very straightforward. From the docs, it was not clear that I HAVE TO increment t.lexer.lineno in my lexer if you want yacc to parse line numbers. But it is logical. I believe this could be done automatically, since line number ALWAYS means \n, there is nothing to be configured here. (Am I wrong? There can be parsers to parse files where new lines are chr(255) or something?) Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
inhahe schrieb: Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)? You could write a C-extension and embed assembly. See the docs for how to write one. If you know how to implement a C-callingconvention-based shared library in assembly (being an assembler guru you sure know how that works), you could mimic a C-extension. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable by label
[EMAIL PROTECTED] pisze: Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. getattr(object, attrname, default) -- Jarek Zgoda Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101 We read Knuth so you don't have to. (Tim Peters) -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable by label
a = 1 b = eval(a) b 1 a =1 b = globals()[a] b 1 a =1 b = locals()[a] b 1 [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: free dictionary english - spanish?
if it is complete sentence translation that you intend to do, then there is a lot more than just word dictionary that you need. you need the grammer too. hope you have that covered. On 5/16/08, globalrev [EMAIL PROTECTED] wrote: i want to write a translationprogram, i have the webapp done already. i need a big free dictionary though. english-spanish/spanish-english seems like the best i know some spanish and thats what also is needed the most i think together with chinese. anywhere you can download one? preferrably easy to parse... -- http://mail.python.org/mailman/listinfo/python-list -- regards, Banibrata http://www.linkedin.com/in/bdutta http://octapod.wordpress.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 8:56 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:51 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Spirals are important. I'd be modeling streams, in par. crossing them.- Hide quoted text - - Show quoted text - Python 3.0a5 (py3k:62932M, May 9 2008 win32 Type help, copyright, credits or import parser import compiler Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named compiler Does anyone want to model mic-based soundwaves? My recent project has been color progression over time, and talking about compilers. -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
Well the problem is that I'm actually not an assembler guru, so I don't know how to implement a dll in asm or use a c calling convention, although I'm sure those instructions are available on the web. I was just afraid of trying to learn that AND making python-specific extensions at the same time. I thought of making a c extension with embedded asm, but that just seemed less than ideal. But if somebody thinks that's the Right Way to do it, that's good enough.. Diez B. Roggisch [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] inhahe schrieb: Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)? You could write a C-extension and embed assembly. See the docs for how to write one. If you know how to implement a C-callingconvention-based shared library in assembly (being an assembler guru you sure know how that works), you could mimic a C-extension. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
On Fri, 16 May 2008 10:13:04 -0400 inhahe [EMAIL PROTECTED] wrote: Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)? I am trying to imagine the requirements document for your project. - Must be error prone and hard to debug - Must take an order of magnitude longer to write - Must be unportable to other systems Really, why don't you write your etension in C? Do you really think you will improve your code by writing it in assembler? Even embedding assembler in C code make it unportable and I find it hard to imagine anything that you want to do in a Python context that can't be done at least as well in C if not pure Python. Just curious is all. -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: TPCServer and xdrlib
On May 16, 9:26 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: Did you consider gzipping your XML (or YAML) packets ? Would the transfer time be acceptable in this case ? That would add even more to the overhead of transcoding the transportlayer. Switching from XMLRPC to a json-based protocol reduced Yes, that's why I suggested YAML. in a project of mine reduced the overhead 10-20fold - mainly because of reduced size and parsing efforts. I don't think so. It probably just the reduced size (check if the json file is around 10 times smaller). I believe the server will be mostly I/O-bound, ie, most overhead will be in the data link/physical layers. The compression/parsing time (a few microseconds) should be a small fraction of the total transfer time (a few milliseconds). Even if the service is not I/O bound, (considering the Youtube example) if there's significant traffic in the server, the database access time should be the most significant. I have used compression for SOAP messages in a GPRS (~20kbps) link and got similar performance improvements (the web server was set to automatically compress the data). Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: default object comparison considered harmful?
On May 16, 9:10 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:35 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:18 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 7:23 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Kay Schluehr a écrit : On 16 Mai, 10:03, A.T.Hofkamp [EMAIL PROTECTED] wrote: Hello all, Yesterday we found the cause of a bug that has caused problems for a long time. It appeared to be the following: class A(object): pass print min(1.0, A()) which is accepted by Python even though the A() object is not numerical in nature. The cause of this behavior seems to be the compare operation of the object class. Is there a way to disable this behavior in Python (other than deriving a new 'object-like' class that doesn't do comparisons?) Are you sure you don't want to use a statically typed language that captures all type errors just by inspecting your source code? This is not necessarily a static vs dynamic typing problem. The following code will raise a TypeError for very good reasons: print 1.0 + A()- Hide quoted text - - Show quoted text - I question the real-world examples of coercion, casting, and upcasting. C insists that defining by operator, which may or may not relate to system, is the only legal move. I doubt operator+ is well- defined on non-ideal structures. Rationals are not floats, but system got checked. Define concurrency.- Hide quoted text - - Show quoted text - I would be bouncing localcy and remoticy. What word's on the bar?- Hide quoted text - - Show quoted text - Can you suffixize words? I have corner, cornercy, lunacy, emphatic, emphasize, a value of Y, orderings, say, remoticy, cross. Come do graphics. Anybody speak? For verbs, I have: say, speak, see, talk, and stack. Pretty harmless. Still here?- Hide quoted text - - Show quoted text - That's stay tuned I'M BARTENDER. Is that a space BAR ZOOP. -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 9:41 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:56 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:51 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Spirals are important. I'd be modeling streams, in par. crossing them.- Hide quoted text - - Show quoted text - Python 3.0a5 (py3k:62932M, May 9 2008 win32 Type help, copyright, credits or import parser import compiler Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named compiler Does anyone want to model mic-based soundwaves? My recent project has been color progression over time, and talking about compilers.- Hide quoted text - - Show quoted text - Can 'compiler' come back in? I want to build a compiler + exec. -- http://mail.python.org/mailman/listinfo/python-list
Cookies and CookieJar
I'm struggling with a project using mechanize and cookies to screen scape a website. The site requires a client created cookie for authentication. Below is the code I'm attempting to use with the traceback I'm getting: import Cookie c=Cookie.SimpleCookie() c[Manageopen]=cards c['Manageopen']['expires'] = 0 c['Manageopen']['path'] = / c['Manageopen']['domain'] = .domain.com c['Manageopen']['secure'] = c.output() 'Set-Cookie: Manageopen=cards; Domain=.domain.com; expires=Fri, 16-May-2008 14:06:00 GMT; Path=/' import cookielib cj=cookielib.CookieJar() cj.set_cookie(c) Traceback (most recent call last): File interactive input, line 1, in module File C:\Python25\lib\cookielib.py, line 1617, in set_cookie if cookie.domain not in c: c[cookie.domain] = {} AttributeError: 'SimpleCookie' object has no attribute 'domain' I also tried: cj.set_cookie(c[Manageopen]) Traceback (most recent call last): File interactive input, line 1, in module File C:\Python25\lib\cookielib.py, line 1617, in set_cookie if cookie.domain not in c: c[cookie.domain] = {} AttributeError: 'Morsel' object has no attribute 'domain' I've looked at everything I can find via Google and nothing seems to help. Thanks in advance. Regards, Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
You could be right, but here are my reasons. I need to make something that's very CPU-intensive and as fast as possible. The faster, the better, and if it's not fast enough it won't even work. They say that the C++ optimizer can usually optimize better than a person coding in assembler by hand can, but I just can't believe that, at least for me, because when I code in assembler, I feel like I can see the best way to do it and I just can't imagine AI would even be smart enough to do it that way... For portability, I'd simply write different asm routines for different systems. How wide a variety of systems I'd support I don't know. As a bare minimum, 32-bit x86, 64-bit x86, and one or more of their available forms of SIMD. D'Arcy J.M. Cain [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Fri, 16 May 2008 10:13:04 -0400 inhahe [EMAIL PROTECTED] wrote: Can anyone give me pointers/instructions/a template for writing a Python extension in assembly (or better, HLA)? I am trying to imagine the requirements document for your project. - Must be error prone and hard to debug - Must take an order of magnitude longer to write - Must be unportable to other systems Really, why don't you write your etension in C? Do you really think you will improve your code by writing it in assembler? Even embedding assembler in C code make it unportable and I find it hard to imagine anything that you want to do in a Python context that can't be done at least as well in C if not pure Python. Just curious is all. -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 10:21 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 9:41 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:56 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 8:51 am, castironpi [EMAIL PROTECTED] wrote: On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Spirals are important. I'd be modeling streams, in par. crossing them.- Hide quoted text - - Show quoted text - Python 3.0a5 (py3k:62932M, May 9 2008 win32 Type help, copyright, credits or import parser import compiler Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named compiler Does anyone want to model mic-based soundwaves? My recent project has been color progression over time, and talking about compilers.- Hide quoted text - - Show quoted text - Can 'compiler' come back in? I want to build a compiler + exec.- Hide quoted text - - Show quoted text - I am also talking about Mac. I have this one: def click( self, *_ ): self.degrees+= 180 Looking entirely unapproachable. Bartender? -- http://mail.python.org/mailman/listinfo/python-list
Re: TPCServer and xdrlib
Henrique Dante de Almeida schrieb: On May 16, 9:26 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: Did you consider gzipping your XML (or YAML) packets ? Would the transfer time be acceptable in this case ? That would add even more to the overhead of transcoding the transportlayer. Switching from XMLRPC to a json-based protocol reduced Yes, that's why I suggested YAML. in a project of mine reduced the overhead 10-20fold - mainly because of reduced size and parsing efforts. I don't think so. It probably just the reduced size (check if the json file is around 10 times smaller). I believe the server will be mostly I/O-bound, ie, most overhead will be in the data link/physical layers. The compression/parsing time (a few microseconds) should be a small fraction of the total transfer time (a few milliseconds). Even if the service is not I/O bound, (considering the Youtube example) if there's significant traffic in the server, the database access time should be the most significant. I have used compression for SOAP messages in a GPRS (~20kbps) link and got similar performance improvements (the web server was set to automatically compress the data). I'm sorry, yes - I forgot that the main problem was the pure message size due to some quadratic behaviour, which made things CPU-bound. Still, XML-parsing is much more expensive, and packing/unpacking will of course add to that. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
inhahe schrieb: Well the problem is that I'm actually not an assembler guru, so I don't know how to implement a dll in asm or use a c calling convention, although I'm sure those instructions are available on the web. I was just afraid of trying to learn that AND making python-specific extensions at the same time. I thought of making a c extension with embedded asm, but that just seemed less than ideal. But if somebody thinks that's the Right Way to do it, that's good enough.. I think the right thing to do if you are not as fluent in assembly is do not do anything in it at all. What do you need it for? Diez -- http://mail.python.org/mailman/listinfo/python-list
Python book question
People keep telling me I need a course in Data Structures and Algorithms. Since Python is the only language that doesn't give me headaches I thought this book might be good. Has anyone read it or can anyone recommend the author? Can anyone recommend a better Data Structures and Algorithms book? The book: http://www.fbeedle.com/053-9.html -- Matt H. -- Outside of a dog, a book is a man's best friend. Inside of a dog, it is too dark to read. -- Groucho Marx -- http://mail.python.org/mailman/listinfo/python-list
IDE for Python
Hi! I´m newbie with Python and to learn it better I want to use a good IDE to concentrate on Python power. There is any IDE like Eclipse for Java for Python? If not, what is the best Python´s IDE for you? Thanks, Jonathan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Variable by label
On May 16, 4:27 pm, inhahe [EMAIL PROTECTED] wrote: a = 1 b = eval(a) b 1 a =1 b = globals()[a] b 1 a =1 b = locals()[a] b 1[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there any function which will return a variable by passing to it the string containing the variable's name? Something like this for instance: foo = some_function(foo) or perhaps it's a dictionary. I don't know, but I would really like to find out how it can be done. I guess it is achievable. Thank you. Perfect. Thank you all for your replies. -- http://mail.python.org/mailman/listinfo/python-list
Re: Instance of class object
On May 16, 4:26 am, Peter Otten [EMAIL PROTECTED] wrote: 甜瓜 wrote: I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html Does this strange behavior break the LSP (Liskov substitution principle)? Can you expand on that? Peter Yes I can. But what is LSP? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyparsing Question
On May 16, 6:43 am, Ant [EMAIL PROTECTED] wrote: Hi all, I have a question on PyParsing. I am trying to create a parser for a hierarchical todo list format, but have hit a stumbling block. I have parsers for the header of the list (title and description), and the body (recursive descent on todo items). LineStart *really* wants to be parsed at the beginning of a line. Your textline reads up to but not including the LineEnd. Try making these changes. 1. Change textline to: textline = pp.Combine( pp.Group(pp.Word(pp.alphas, pp.printables) + pp.restOfLine)) + \ pp.LineEnd().suppress() 2. Change comb to: comb = head + parser With these changes, my version of your code runs ok. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: writing python extensions in assembly
On Fri, 16 May 2008 11:21:39 -0400 inhahe [EMAIL PROTECTED] wrote: You could be right, but here are my reasons. I need to make something that's very CPU-intensive and as fast as possible. The faster, the better, and if it's not fast enough it won't even work. They say that the C++ optimizer can usually optimize better than a person coding in assembler by hand can, but I just can't believe that, at least for me, because when I code in assembler, I feel like I can see the best way to do it and I just can't imagine AI would even be smart enough to do it that way... Perhaps. Conventional wisdom says that you shouldn't optimize until you need to though. That's one of the benefits of the way Python works. Here's how I would do it. 1. Write the code (call it a prototype) in pure Python. Make sure that everything is modularized based on functionality. Try to get it split into nice, bite size chunks. Make sure that you have unit tests for everything that you write. 2. Once the code is functioning, benchmark it and find the bottlenecks. Replace the problem methods with a C extension. Refactor (and check your unit tests again) if needed to break out the problem areas into as small a piece as possible. 3. If it is still slow, embed some assembler where it is slowing down. One advantage of this is that you always know if your optimizations are useful. You may be surprised to find that you hardly ever need to go beyond step 1 leaving you with the most portable and easily maintained code that you can have. For portability, I'd simply write different asm routines for different systems. How wide a variety of systems I'd support I don't know. As a bare minimum, 32-bit x86, 64-bit x86, and one or more of their available forms of SIMD. Even on the same processor you may have different assemblers depending on the OS. -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Thread killing - I know I know!
Hello everyone, this is my first post so hello please be gentle! Despite many peoples insistence that allowing for the arbitrary killing of threads is a cardinal sin and although I have no particular threading problem to crack right now I remain interest in the taboo that is thread killing. The real world and it's data are messy and imperfect and I can think of several scenarios where it could be useful to be able to bump off a naughty thread, especially when using/testing unstable 3rd party modules and other code that is an unknown quantity. With this in mind I am experimenting with a set of threading subclasses that would permit timeouts and the manual killing of threads. I'm trying to evaluate how robust such a scheme can be made and what the limitations would be in practice. So far I can seemingly murder/timeout pure python threads that are stuck blocking for input and stuck in infinite loops but I'm guessing there are many more awkward cases. What I'm looking for are examples of code/modules that can get stuck in dead ends or might otherwise be problematic to terminate. In particular I'd be interested to see if I could kill a non-returning c module. Of course naturally no one wants to be publishing buggy modules and the like so I am having trouble finding examples of misbehaving c code to explore further. I figure I could learn how to write c modules for python but, while it's something I'd like to know someday, I'm guessing that will be too long to fit into the immediate future :/ Consequently if anyone has detailed knowledge of what is and isn't fundamentally possible in the world of thread culling, or if you can point me to some gnarly/non-returning thread code to test with I would be forever grateful. Oh yes, I'm working primarily with 2.5 on XP however I have access to linux OSX boxen and I'd be interested to learn about problematic thread code for either of those platforms as well. Thanks for reading, Roger Heathcote - www.technicalbloke.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Making Variable Text Output More Pythonic?
afrobeard [EMAIL PROTECTED] writes: Arnaud's code wont work if self.opt1 is None, an empty list, an empty tuple, False, etc, because all these evaluate to false. They wont print the internal state of these variables. [Just an informational notice, this may be the behavior you expect] ??? My suggestion is to get rid of attributes altogether and does not test any truth values. Secondly, I'm not sure if you know the variable names from before hand in which case Casey's approach will work, or you need to know them via introspection. http://www.ibm.com/developerworks/library/l-pyint.html [Scroll down to attributes]. On May 16, 1:44 am, Arnaud Delobelle [EMAIL PROTECTED] wrote: Casey [EMAIL PROTECTED] writes: Hi, I have some classes that print variable outputs depending on their internal state, like so: def __str__(self): out = [] if self.opt1: out += ['option 1 is %s' % self.opt1'] if self.opt2: out += ['option 2 is %s' % self.opt2'] return '\n'.join(out) Is there any way to make this cleaner? Maybe. Have a dictionary of options rather than individual attributes; options not in the dictionary are not set. E.g. mask = { 'opt1': 'option 1 is %s', 'opt2': 'option 2 is %s', ... } def __str__(self): return '\n'.join(mask[o] % v for o,v in self.options.iteritems()) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyparsing Question
On May 16, 6:43 am, Ant [EMAIL PROTECTED] wrote: Hi all, I have a question on PyParsing. I am trying to create a parser for a hierarchical todo list format, but have hit a stumbling block. I have parsers for the header of the list (title and description), and the body (recursive descent on todo items). Individually they are working fine, combined they throw an exception. The code follows: #!/usr/bin/python # parser.py import pyparsing as pp def grammar(): underline = pp.Word(=).suppress() dotnum = pp.Combine(pp.Word(pp.nums) + .) textline = pp.Combine(pp.Group(pp.Word(pp.alphas, pp.printables) + pp.restOfLine)) number = pp.Group(pp.OneOrMore(dotnum)) headtitle = textline headdescription = pp.ZeroOrMore(textline) head = pp.Group(headtitle + underline + headdescription) taskname = pp.OneOrMore(dotnum) + textline task = pp.Forward() subtask = pp.Group(dotnum + task) task (taskname + pp.ZeroOrMore(subtask)) maintask = pp.Group(pp.LineStart() + task) parser = pp.OneOrMore(maintask) return head, parser text = My Title Text on a longer line of several words. More test and more. text2 = 1. Task 1 1.1. Subtask 1.1.1. More tasks. 1.2. Another subtask 2. Task 2 2.1. Subtask again head, parser = grammar() print head.parseString(text) print parser.parseString(text2) comb = head + pp.OneOrMore(pp.LineStart() + pp.restOfLine) + parser print comb.parseString(text + text2) #=== Now the first two print statements output the parse tree as I would expect, but the combined parser fails with an exception: Traceback (most recent call last): File parser.py, line 50, in ? print comb.parseString(text + text2) . . [Stacktrace snipped] . raise exc pyparsing.ParseException: Expected start of line (at char 81), (line:9, col:1) Any help appreciated! Cheers, -- Ant. I hold that the + operator should be overloaded for strings to include newlines. Python 3.0 print has parentheses around it; wouldn't it make sense to take them out? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python book question
On Fri, 16 May 2008 10:31:16 -0500 Matt Herzog [EMAIL PROTECTED] wrote: Since Python is the only language that doesn't give me headaches I thought this book might be good. Has anyone read it or can anyone recommend the author? Can anyone recommend a better Data Structures and Algorithms book? The book: http://www.fbeedle.com/053-9.html I'm not familiar with the book but I poked my head in and looked at the first example: def squareroot(n): root = n/2 for k in range(20): root = (1.0/2)*(root + (n / root)) return root Looks fine and works but I wonder about the root = n/2 line. Since the behaviour of this operation changes in 3.0, shouldn't it be specific about whether it is doing int or float division? -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list