Re: Basic python help
(Please don't top-post -- fixed) Kevin Feng wrote: On 3/14/06 2:12 AM, in article [EMAIL PROTECTED], Gregor Horvath [EMAIL PROTECTED] wrote: Kevin Feng schrieb: More information about this error may be available in the server error log. Any suggestions? Much thanks. What does the error log of the webserver say? -- Greg No idea, I do not have permission to access the error log. In your cgi script, try putting import cgitb; cgitb.enable() on the next line right after import cgi. Also try changing your POST to GET. ---John -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for documentation generation?
Michael Ekstrand wrote: Doxygen has recently added support for Python, [snip] Didn't know that. Thanks for the heads-up. :) -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Write a GUI for a python script?
Glurt Wuntal wrote: I am a newbie with Python. It's a great language, but I would like to be able to present a simple gui menu for some of my scripts; something better than using 'raw_input' prompts. Any recommendations for a program that will allow me to create the gui screens? Something useable in Linux. thanks. There are Python bindings to most GUI toolkits (GTK+, Qt, fltk, wxWindows, and Tk come to mind). You could use any of them. They're all usable in GNU/Linux. -- Tk is a mature, small, and simple toolkit. The Python binding to Tk is called Tkinter. -- GTK+ is what most Gnome apps use. The Python binding is PyGTK. http://www.pygtk.org/ -- Qt is what most KDE apps use. The Python binding is called PyQt. -- wxWindows is a lot like MS Windows MFC if I recall correctly. The Python binding to wxWindows is called wxPython. http://www.wxpython.org/ -- For a terminal-based text-mode character-cell display program, you could use ncurses. http://www.amk.ca/python/howto/curses/ http://gnosis.cx/publish/programming/charming_python_6.html ---John -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Write a GUI for a python script?
John M. Gabriele wrote: There are Python bindings to most GUI toolkits (GTK+, Qt, fltk, wxWindows, and Tk come to mind). Whoops. Forgot fltk with the pyFLTK Python binding. fltk is a fast, light, toolkit that's written in C++ but (again, IIRC) feels more like C-with-classes (which isn't a bad thing). ---John -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for documentation generation?
kpd wrote: Hello, I have written a C++ library that I've then wrapped with Pyrex. Any suggestions to the best-in-class tool to create documentation for the libraries? I would love to document things in one spot (could be the code) and generate html and PDF from there. Doxygen (www.doxygen.org) looks to be about the best so far. Thanks, I've heard that some folks use pythondoc: http://starship.python.net/crew/danilo/pythondoc/ http://effbot.org/zone/pythondoc.htm There's also HappyDoc http://happydoc.sourceforge.net/ and EpyDoc http://epydoc.sourceforge.net/ . -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Indentation Problems
Renato wrote: If you use vi (vim, I hope), then place something like this in your .vimrc set ts=4 set sw=4 set expandtab set ai Or, more verbose: set tabstop=4 set shiftwidth=4 set autoindent There are a lot more tricks for python in vim (and plugins, and helpers, and so on), but this is the starting point: tabstops of 4 places, autoconverted in spaces. Also, when shifting text with or it moves 4 spaces. Also possibly useful: set shiftround ---John -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ OpenGL rendering, wxPython GUI?
[EMAIL PROTECTED] wrote: [snip] Now I'm looking to build a GUI in python with the rendering engine as an integrated window. I will most likely use wxPython for the GUI and I know it has support for adding an OpenGL canvas. You might look into PyFLTK (which I think was just recently mentioned on the announce list): http://pyfltk.sourceforge.net/ I haven't used it. Just something to maybe look into. I think fltk does indeed have support for OpenGL. And I hear it's a fast and light toolkit. ;) ---John -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: automatic html generation for documentation?
Lonnie Princehouse wrote: I plan on writing some documentation that will consist of blocks of commentary with interspersed snippets of syntax-colored Python code and the occaisional image. Does anyone know of a package that will take a high level description of what I just described and auto-generate clean-looking web pages, including syntax coloring? I'm already using epydoc for API reference generation; what I'm looking for here is just something to help out with the narrative so I don't have to spend lots of time fiddling with HTML. The Python wiki http://wiki.python.org/moin/FrontPage uses moinmoin and their pages contain syntax highlighted (highlit? ;) ) Python code. Of course, there's always source-highlight http://www.gnu.org/software/src-highlite/source-highlight.html which you may be able to work into your current solution with a little glue. In fact, come to think of it, if your editor is up to snuff, you could simply paste the code into your html doc, select that code in the editor, then filter it through source-highlight in-place. I use NEdit and I think that could do it easily. ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for a simpe plotting module
Henrique Ferreiro wrote: O Sáb, 25-02-2006 ás 15:01 -0800, MARK LEEDS escribiu: i'm pretty much a python beginner so can anyone recommend a plooting package in python ( simple foating numbers that makes lines or dots with a yaxis and an an xaxis. i don't need fancy drawings ) that is a built in module in python ? i am using python 2.4 in linux if that matters. thanks. -- http://mail.python.org/mailman/listinfo/python-list matplotlib is an excellent library which uses the syntax of matlab plots. http://matplotlib.sourceforge.net You might also have a look at PyChart: http://wiki.python.org/moin/PyChart -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: editor for Python on Linux
Mladen Adamovic wrote: Hi! I wonder which editor or IDE you can recommend me for writing Python programs. I tried with jEdit but it isn't perfect. NEdit -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: new wooden door step - fixing and finishing
Jeffrey Schwab wrote: jkn wrote: I was wondering about treating it wilth liberal amounts of Teak Oil or similar... Some people, when confronted with a problem, think I know, I’ll use Teak Oil. Now they have two problems. Quit it! You're making me laugh too much and it's gonna wake up the kids! :D -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: pyFltk-1.1
{fixed top-posting} george williams wrote: This is to announce the first official release of pyFltk-1.1, the Python bindings for the cross platform GUI toolkit fltk-1.1 By god this sounds interesting I wish I knew what you are talking about fltk (pronounced full-tick as in Cap'n, we're doing warp 9 and the engines are going full tick! but not as in, boy, I just checked the dog found one very full tick) is a C++ GUI toolkit. You would use fltk for writing a GUI desktop application. It's like GTK+ or Qt, but much smaller and lighter. pyFltk is a Python binding to fltk. That is, so you can use fltk from Python instead of from C++. ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: fairly large webapp: from Java to Python. experiences?
Shalabh Chaturvedi wrote: [EMAIL PROTECTED] wrote: A class-to-class and method-to-method rewrite will give some but likely not the full benefit of moving to Python. A redesign might be necessary - making it more 'Pythonic' in the process. In my experience, many cruft classes that exist in a Java design simply disappear when ported to Python. See also http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Shalabh Great link Shalabh. Thanks. :) Googling around, I'd also come across that one. ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: fairly large webapp: from Java to Python. experiences?
[EMAIL PROTECTED] wrote: To replace a large framework you will probably need a framework. Well, I'm sure not all web frameworks are created equal, however, CherryPy does bill itself as a web framework. Take a look at http://www.djangoproject.com or http://www.turbogears.org. They both use some of the tools you mention but operate on a higher level. Django looks interesting to me. Would like to try out mod_python. Taking a look... I find Python fairly easy to maintain. Unfortunatly, I do not find it easy to take a bunch of Java code and move it to Python. Well, I figured it might be better to use the previous webapp as a *model* to learn from, rather than to directly translate code from Java to Python. But once it is there, Python is a good choice for web apps. Java is slow Slow? They're both dynamic languages, but Java is statically typed (with less work to do at runtime). For long-running processes, I'd guess that Java bytecode executes faster than Python bytecode. and has a big footprint. Yes. Python is reasonably nimble and good design choices pay off. Plus, you must write many more lines of Java to do what you can in Python. Yup. The main issue with the current Java webapp seems to be that it takes a long time to make changes/additions. I do not know the code you are not working with, but a lot of large Java apps can be poorly written. I've found that good documentation is *most* critical. At least if the docs are good, but the code needs work, you have some direction as to how to fix the code. If there's no docs, you spend hours wondering why things are done the way they're done. Currently having a look at the Django docs. :) Thanks Brian! ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: cannot install scipy
nitro wrote: Hi, I am using a Debian system. I installed NumPy and everything works well. When I try to install SciPy, I get the following error. Any help would be appreciated. === [EMAIL PROTECTED]:~/scipy/scipy-0.4.4$ python setup.py install import core - failed: /usr/lib/python2.3/site-packages/numpy/core/multiarray.so: undefined symbol: PyOS_ascii_strtod import random - failed: 'module' object has no attribute 'dtype' import lib - failed: /usr/lib/python2.3/site-packages/numpy/core/multiarray.so: undefined symbol: PyOS_ascii_strtod Fatal Python error: can't initialize module lapack_lite Aborted [EMAIL PROTECTED]:~/scipy/scipy-0.4.4$ === nitro Why not just apt-get install python-scipy? That's one of the best parts of running Debian. :) ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: python's library support
Sean wrote: I am a newbie in python, and I have a feeling that python provides less library support than perl www.cpan.org This seems a big discussion topic. I want to know if there is extensive algorithm library support in python. I know there is a pretty neat module in perl to implement graph theory. Is there a graph theory module in python? Thanks, You might have a look around at the cheese shop: http://cheeseshop.python.org/pypi ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: Server side newbie
swisscheese wrote: I have a simple python desktop app with several edit controls and a couple of buttons. It just does some math. What's the simplest way to make it a server-side app so visitors to my site can run the app via their browser? The *simplest* way is to make it into a CGI script. What you'll probably want is to make the CGI script produce some html with a form in it. The form action is the CGI script itself. This way, after you hit the submit button, you get the same page back again (with your math answer written in the page somewhere), with the same fields and submit button waiting for you to use the script again. Use the cgi module to access the data that gets submitted by the form. To run your script, you'll need to install a web server. On Debian it's: apt-get install apache2 Then you put your CGI script into /usr/lib/cgi-bin/foo.py and point your browser to http://localhost/cgi-bin/foo.py ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: VB to Python migration
Josh wrote: We have a program written in VB6 (over 100,000 lines of code and 230 UI screens) that we want to get out of VB and into a better language. The program is over 10 years old and has already been ported from VB3 to VB6, a job which took over two years. We would like to port it to Python, but we need to continue to offer upgrades and fixes to the current VB6 version. Does anybody know of ways we could go about rewriting this, one screen at a time, in Python, and calling the screens from the existing program? Dunno what you mean by calling the screens from the existing program. (?) Is your VB6 progam object-based? If so, it sounds like you might have your work cut out for you in duplicating the classes in Python (I've never used VB6 and don't even know if it's an OO language.). I'd look into how you can start with unit tests + your classes right from the start. And, it goes without saying to use version control from the start (svn or, if you're adventurous, maybe bzr (i.e. Bazaar-NG)). We are also looking for a graphics toolkit to use. You might take a peek at Python + PyGTK + Glade: http://pygtk.org/ . Dunno the state of GTK on Windows, but I've heard it's workable. No idea about Glade on Windows. Here's an article from 2001: http://www.linuxjournal.com/article/4702 but if you look around there should be some newer tutorials around. [snip] Any answers/suggestions/pointers are greatly appreciated. As Steven suggested, I'd examine whether or not your app might work as a web app. That completely frees you from Windows altogether. Just make sure it runs alright with Firefox/Opera/ Safari. :) ---J Thanks, Josh Isted -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate graphics dynamically on the web using Python CGI script?
Luiz Geron wrote: I don't have experience on this, but I think that you can make the script return the image contents directly to the img tag, without passing it to a img file, so you can use something like this: img src=script_that_return_image_contents wich saves some processing and I/O. I like this method. You have 2 cgi scripts: one that creates your html with that img tag in it, and a 2nd one to generate the image file on the fly when the browser asks for it. For generating the plot, I tried pychart http://home.gna.org/pychart/ and it was pretty nice. If using pychart, your script that emits image contents might look like this: code #!/usr/bin/python # Not using cgi module at this point, since this script # isn't very smart yet. :) import sys sys.argv.append( '--format=png' ) print Content-type: image/png print from pychart import * theme.get_options() theme.scale_factor = 3 theme.reinitialize() import random data = [] for i in range(10): data.append( (i, random.random()* 3.0) ) xaxis = axis.X( format=/hL%d, label=time ) yaxis = axis.Y( label=synaptic activity ) ar = area.T( x_axis=xaxis, y_axis=yaxis, y_range=(0,None), size=(120,110) ) plot = line_plot.T( label=cortex data, data=data, ycol=1, tick_mark=tick_mark.star ) ar.add_plot( plot ) ar.draw() - /code Try the script out -- it'll work as-is once you've installed pychart. You can add logic to it to generate your plot depending on what you pass in, encoded in the URL request. Just import the cgi module for getting those parameters. ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: web crawling.
Alex Martelli wrote: S Borg [EMAIL PROTECTED] wrote: Hello, I have been writing very simple Python programs that parse HTML and such, mainly just to get a better feel for the language. Here is my question: If I parsed an HTML page into all of the image files listed on that page, how could I request all of those images and download them into some specified folder? I am sure this is quite easy, but I am stuck. There's a good crawler in the Demo directory of the Python source distribution, so download and unpack said sources and look there. Alex Hm. Looks like that's: Python-2.4.2/Tools/webchecker See 'pydoc ./webchecker.py' for more info. ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
instance attributes not inherited?
The following short program fails: --- code #!/usr/bin/python class Parent( object ): def __init__( self ): self.x = 9 print Inside Parent.__init__() class Child( Parent ): def __init__( self ): print Inside Child.__init__() p1 = Parent() p2 = Parent() c1 = Child() foo = [p1,p2,c1] for i in foo: print x =, i.x - /code -- yielding the following output: output -- Inside Parent.__init__() Inside Parent.__init__() Inside Child.__init__() x = 9 x = 9 x = Traceback (most recent call last): File ./foo.py, line 21, in ? print x =, i.x AttributeError: 'Child' object has no attribute 'x' /output - Why isn't the instance attribute x getting inherited? My experience with OOP has been with C++ and (more recently) Java. If I create an instance of a Child object, I expect it to *be* a Parent object (just as, if I subclass a Car class to create a VW class, I expect all VW's to *be* Cars). That is to say, if there's something a Parent can do, shouldn't the Child be able to do it too? Consider a similar program: --- code #!/usr/bin/python class Parent( object ): def __init__( self ): self.x = 9 print Inside Parent.__init__() def wash_dishes( self ): print Just washed, self.x, dishes. class Child( Parent ): def __init__( self ): print Inside Child.__init__() p1 = Parent() p2 = Parent() c1 = Child() foo = [p1,p2,c1] for i in foo: i.wash_dishes() --- /code --- But that fails with: --- output -- Inside Parent.__init__() Inside Parent.__init__() Inside Child.__init__() Just washed 9 dishes. Just washed 9 dishes. Just washed Traceback (most recent call last): File ./foo.py, line 24, in ? i.wash_dishes() File ./foo.py, line 10, in wash_dishes print Just washed, self.x, dishes. AttributeError: 'Child' object has no attribute 'x' --- /output - Why isn't this inherited method call working right? Is this a problem with Python's notion of how OO works? Thanks, ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: instance attributes not inherited?
David Hirschfield wrote: Nothing's wrong with python's oop inheritance, you just need to know that the parent class' __init__ is not automatically called from a subclass' __init__. Just change your code to do that step, and you'll be fine: class Parent( object ): def __init__( self ): self.x = 9 class Child( Parent ): def __init__( self ): super(Child,self).__init__() print Inside Child.__init__() -David How does it help that Parent.__init__ gets called? That call simply would create a temporary Parent object, right? I don't see how it should help (even though it *does* indeed work). Why do we need to pass self along in that call to super()? Shouldn't the class name be enough for super() to find the right superclass object? -- http://mail.python.org/mailman/listinfo/python-list
Re: instance attributes not inherited?
John M. Gabriele wrote: David Hirschfield wrote: Nothing's wrong with python's oop inheritance, you just need to know that the parent class' __init__ is not automatically called from a subclass' __init__. Just change your code to do that step, and you'll be fine: class Parent( object ): def __init__( self ): self.x = 9 class Child( Parent ): def __init__( self ): super(Child,self).__init__() print Inside Child.__init__() -David How does it help that Parent.__init__ gets called? That call simply would create a temporary Parent object, right? I don't see how it should help (even though it *does* indeed work). Sorry -- that question I wrote looks a little incomplete: what I meant to ask was, how does it help this code to work: code #!/usr/bin/python class Parent( object ): def __init__( self ): self.x = 9 print Inside Parent.__init__() def wash_dishes( self ): print Inside Parent.wash_dishes(), washing, self.x, dishes. class Child( Parent ): def __init__( self ): super( Child, self ).__init__() print Inside Child.__init__() c = Child() c.wash_dishes() /code since the x instance attribute created during the super( Child, self ).__init__() call is just part of what looks to be a temporary Parent instance. -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: instance attributes not inherited?
Dan Sommers wrote: [snip] How does it help that Parent.__init__ gets called? That call simply would create a temporary Parent object, right? I don't see how it should help (even though it *does* indeed work). The __init__ method is an *initializer*, *not* a constructor. By the time __init__ runs, the object has already been constructed; __init__ just does extra initialization. Regards, Dan Right. Thanks for the clarification. :) -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: instance attributes not inherited?
Dennis Lee Bieber wrote: On Sun, 15 Jan 2006 20:50:59 -0500, John M. Gabriele [EMAIL PROTECTED] declaimed the following in comp.lang.python: Sorry -- that question I wrote looks a little incomplete: what I meant to ask was, how does it help this code to work: code #!/usr/bin/python class Parent( object ): def __init__( self ): self.x = 9 print Inside Parent.__init__() def wash_dishes( self ): print Inside Parent.wash_dishes(), washing, self.x, dishes. class Child( Parent ): def __init__( self ): super( Child, self ).__init__() print Inside Child.__init__() c = Child() c.wash_dishes() /code since the x instance attribute created during the super( Child, self ).__init__() call is just part of what looks to be a temporary Parent instance. (Whoops. I see now thanks to Dan Sommers' comment that there's no temp Parent instance, unless the call to super() is creating one...) Because you passed the CHILD INSTANCE (self) to the method of the super... so self.x is child-instance.x Huh? But it sounds by the name of it that super() is supposed to return something like the superclass (i.e. Parent). You mean, that super( Child, self ).__init__() call inside Child.__init__() leads to Parent.__init__() getting called but with the 'self' reference inside there referring to the Child object we named 'c' instead of some Parent {confused} Wait a second. I can replace that super() call with simply Parent.__init__( self ) and everything still works... and it looks to me that, indeed, I'm passing self in (which refers to the Child object), and that self gets used in that __init__() method of Parent's... Wow. I'd never seen/understood that before! We're using superclass initializers on subclasses that weren't around when the superclass was written! I'm having a hard time finding the documentation to the super() function. I checked the language reference ( http://docs.python.org/ref/ref.html ) but didn't find it. Can someone please point me to the relevant docs on super? help( super ) doesn't give much info at all, except that super is actually a class, and calling it the way we are here returns a bound super object, but I don't yet see what that means (though I know what bound methods are). Thanks, ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
OOP: method overriding works in mysterious ways?
Consider the following: #!/usr/bin/python #- class Grand_parent( object ): def speak( self ): print 'Grand_parent.speak()' self.advise() def advise( self ): print 'Grand_parent.advise()' self.critique() def critique( self ): print 'Grand_parent.critique()' #- class Parent( Grand_parent ): def speak( self ): print '\tParent.speak()' self.advise() def advise( self ): print '\tParent.advise()' self.critique() # ATM, the Parent is at a loss for words, and has no critique. #- class Child( Parent ): def speak( self ): print '\t\tChild.speak()' self.advise() # Currently, the Child has no really useful advice to give. def critique( self ): print '\t\tChild.critique()' #- print 'speak() calls advise(), then advise() calls critique().' print people = [ Grand_parent(), Parent(), Child() ] for person in people: person.speak() print The output is: speak() calls advise(), then advise() calls critique(). Grand_parent.speak() Grand_parent.advise() Grand_parent.critique() Parent.speak() Parent.advise() Grand_parent.critique() Child.speak() Parent.advise() Child.critique() What's going on here with that last Child.critique()? The Parent called self.critique(), and since it *had* no critique() method, it should've deferred to it's parent's critique() method, right? But instead, somehow Child.critique() got called. Why? ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP: method overriding works in mysterious ways?
Scott David Daniels wrote: Dustan wrote: From my experience, the methods are passed down, not referred to from the parent. That is, Parent does have its own critique method, not a reference to Grand_parent.critique(). This is typical of static binding as (for example) seen in C++. If you think of dynamically bound systems like Smalltalk, Ruby, and Python, the more unusual case is wanting to go up the hierarchy (where you use super to get the behavior you are apparently expecting). Think of Python's method dispatch as always being virtual. Ah. Not only that, but the other ingredient (I think) is to keep in mind that you're always calling instance methods via the self object -- and that self object is always the same object regardless of how far up the inheritance tree you go with those method calls, right? --Scott David Daniels [EMAIL PROTECTED] ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP: method overriding works in mysterious ways?
Dustan wrote: [snip] That is, Parent does have its own critique method, not a reference to Grand_parent.critique(). Interesting. It has its own critique method? Hm. Not quite sure what that means exactly... Anyhow, I wasn't suggesting that Parent had a reference to Grand_parent.critique(), only that Python would search *up* the tree looking for the method it's looking to call. Thanks! So when Child calls self.advise, it is calling its inherrited copy. Then, since the inherited Child.advise() from Parent.advise() calls self.critique, it calls it's own overriden critique method. I hope this makes sense. -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP: method overriding works in mysterious ways?
André wrote: John M. Gabriele wrote: Since Child has no advice() method, it inherits the one for Parent. Thus, Child can be thought of as being defined as follows: . class Child( Parent ): . . def speak( self ): . print '\t\tChild.speak()' . self.advise() . . def advise( self ): # inherited from Parent . print '\tParent.advise()' . self.critique() . . def critique( self ): . print '\t\tChild.critique()' . That's a very interesting way to look at it... But I thought that the Python interpreter takes care of walking up the inheritance tree looking for the instance methods, rather than what you've written above... Note that self refer to the *instance* created, not the *class*. Thanks. Right -- the self object always refers to the object that you originally used to call the instance method (here, speak()). Now, does the output make sense? André Bearing in mind what self is referring to, then yes, the output does make sense. Thanks. :) ---J -- (remove zeez if demunging email address) -- http://mail.python.org/mailman/listinfo/python-list
cgi, reusing html. common problem?
I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common (and static) html, however, they'll also have dynamic aspects. I'm guessing that the common way to build sites like this is to have every page (which contains active content) be generated by a cgi script, but also have some text files hanging around containing incomplete html fragments which you read and paste-in as-needed (I'm thinking: header.html.txt, footer.html.txt, and so on). Is that how it's usually done? If not, what *is* the usual way of handling this? Thanks, ---John -- --- if contacting via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi, reusing html. common problem?
On Thu, 01 Sep 2005 09:20:51 +0200, Diez B. Roggisch wrote: John M. Gabriele wrote: I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common (and static) html, however, they'll also have dynamic aspects. I'm guessing that the common way to build sites like this is to have every page (which contains active content) be generated by a cgi script, but also have some text files hanging around containing incomplete html fragments which you read and paste-in as-needed (I'm thinking: header.html.txt, footer.html.txt, and so on). Is that how it's usually done? If not, what *is* the usual way of handling this? The basic idea is correct - but there are sooo many other people that had the same problem, and thus they creted web-framworks like e.g. CherryPy or Django or... and then there is ZOPE. Search this group for webframeworks, and you might get more answers than you wanted :) Diez Thanks Diez. Glad to hear I'm on the right track. :) From poking around, it looks to me like these Python web frameworks are to Python as JSP is to Java. I really don't want to use a templating language (a la JSP) -- I was hoping to just stick with straight Python and then also html + css. Though I've heard good things about CherryPy. Looks like mod_python also comes with it's own solution too: http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html -- --- if contacting via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi, reusing html. common problem?
On Thu, 01 Sep 2005 13:12:14 +0100, Fuzzyman wrote: On Thu, 01 Sep 2005 03:10:07 -0400, John M. Gabriele [EMAIL PROTECTED] wrote: I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common (and static) html, however, they'll also have dynamic aspects. I'm guessing that the common way to build sites like this is to have every page (which contains active content) be generated by a cgi script, but also have some text files hanging around containing incomplete html fragments which you read and paste-in as-needed (I'm thinking: header.html.txt, footer.html.txt, and so on). Is that how it's usually done? If not, what *is* the usual way of handling this? Having a template and inserting dynamic values into it is very common. You'll have more luck looking for 'python templating systems'. I use a module called 'embedded code' - which is part of firedrop by Hans Nowak. See http://www.voidspace.org.uk/python/firedrop2/ Popular templating engines include Cheetah and TAL. You can also roll your own basic one using the string method ``replace``. Thanks for the reply Fuzzy. I'm going to try rolling my own. I found this *great* article: http://www.devshed.com/index2.php?option=contenttask=viewid=198pop=1page=0hide_js=1 and it shows pretty much exactly what I think I want: separate html files containing fragments of a complete page, then some python code to read in the html fragment, and replace your generated code with some placeholder. I'm pretty sure their is an entry on the Python.org WIKI about templating. Whoops. I ended up hitting this page first: http://wiki.python.org/moin/CgiScripts and now I'm sticking with it. :) I like CGI. I want to keep things as simple as possible. :) ---John All the best, Fuzzy http://www.voidspace.org.uk/python Thanks, ---John -- --- if contacting via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi, reusing html. common problem?
On Thu, 01 Sep 2005 19:10:14 +0200, Walter Dörwald wrote: John M. Gabriele wrote: I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common (and static) html, however, they'll also have dynamic aspects. I'm guessing that the common way to build sites like this is to have every page (which contains active content) be generated by a cgi script, but also have some text files hanging around containing incomplete html fragments which you read and paste-in as-needed (I'm thinking: header.html.txt, footer.html.txt, and so on). Is that how it's usually done? If not, what *is* the usual way of handling this? I don't know if it's the *usual* way, but you could give XIST a try (http://www.livinglogic.de/Python/xist). It was developed for exactly this purpose: You implement reusable HTML fragments in Python and you can use any kind of embedded dynamic language (PHP and JSP are supported out of the box). Bye, Walter Dörwald Thanks Walt. :) Though, it seems simpler to me to just stick with some plain vanilla static html, and pull that in to my cgi scripts as necessary. ---John -- --- if contacting via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi, reusing html. common problem?
On Thu, 01 Sep 2005 20:57:56 -0500, Steve Holden wrote: John M. Gabriele wrote: [snip] Is that how it's usually done? If not, what *is* the usual way of handling this? There are a million ways to solve this particular problem, despite Python's TSBOAPOOOWTDI (see import this) philosophy (because the philosophy is addressing primitive programming rather than application frameworks). Yes. :) You could do something as simple as writing a module webPage that defines a function page(path, content) that does something along the lines of: def page(path, content): return \ html titleIf you want titles, add another argument/title /head body this would be code to build a nav bar, omitting a hypertext link for the path given as an argument - I'm just ignoring it in this example %s /body /html % content Ah yes, I see. If the content is completely static, you can use a text file (html fragment) and just read it and paste it in, but for fragments that are *mostly* static, I really like that idea to use a module as you suggest. [snip] Hope this gives you a few ideas. This problem has been considered by many people, but clearly no outstanding solution has yet been devised, otherwise we'd all be using it. regards Steve Thanks Steve! ---John -- --- if contacting via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Like overloading __init__(), but how?
I know that Python doesn't do method overloading like C++ and Java do, but how am I supposed to do something like this: - incorrect #!/usr/bin/python class Point3d: pass class Vector3d: A vector in three-dimensional cartesian space. def __init__( self ): Create a Vector3d with some reasonable default value. x, y, z = 0.0, 0.0, 0.0 def __init__( self, x_from, y_from, z_from, x_to, y_to, z_to ): Create a Vector3d from x-y-z coords. # ... pass def __init__( self, point_from, point_to ): Create a Vector3d from two Point3d objects. # ... pass def __init__( self, same_as_this_vec ): Create a Vector3d from a copy of another one. # ... pass p = Point3d() p2 = Point3d() # v = Vector3d( p2, p ) -- Nope. Only the last __init__() counts. -- /incorrect --- Thanks. -- --- if replying via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Like overloading __init__(), but how?
On Wed, 23 Feb 2005 21:32:52 -0700, Steven Bethard wrote: [snip] Another possibility is to play around with *args: class Vector3d(object): def __init__(self, *args): if not args: # constructor with no arguments elif len(args) == 6: # constructor with xyz coords elif len(args) == 2: # constructor with points elif len(args) == 1: # copy constructor else: raise TypeError('expected 0, 1, 2 or 6 args, got %i' % len(args)) But this can get really ugly really quick. HTH, STeVe Thanks STeVe. I think, for now, I'll probably stick with the easier but less elegant way of checking *args. I guess I could compare args[0].__class__.__name__ against 'Point3d', 'Vector3d', or just 'float'. Didn't realize this topic came up recently. Sorry for the duplication. ---J -- --- if replying via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
difference between class methods and instance methods
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call them with MyClass.foo() or instead: bar = MyClass() bar.foo() ? 3. Is bound method a synonym for instance method? 4. Is unbound method a synonym for class method? And if anyone's *really* daring: Where do the so-called static methods fit into all this? By the name of them, it sounds like the same thing as class methods... Much thanks, ---J -- --- if replying via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python as capable as Perl for sysadmin work?
Aahz wrote: [snip] Anyway. Have you ever noticed how shell scripts keep getting longer? Yup. Ever notice how it gets harder to figure out what the heck any given script's doing? Yup. Well, that's where Python helps you out compared to Perl. Python can be a bit clumsier than Perl for dirt-simple tasks, but you'll find that Python scales much better than Perl. Check. Thanks Aahz. :) -- -- remove zees if contacting via email -- -- http://mail.python.org/mailman/listinfo/python-list
Is Python as capable as Perl for sysadmin work?
I recently posted this sort of question to the c.l.p.m but didn't get much of a response. I know a little Perl and a little Python, but master neither at the moment. I see that Python is a general purpose OO programming language that finds use among some system administrators, but my guess is that Perl is still more common in that area than Python. For sysadmin-related tasks, is Python as useful as Perl, or does it get clumsy when often dealing with the stuff admins deal with on a regular basis? At some point during some dingy job in the back boiler room of Unix, would you find yourself saying, geez, I'd wish I started this with Perl -- Python just isn't cutting it. ? Thanks, ---J -- --- if replying via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Python as capable as Perl for sysadmin work?
On Mon, 07 Feb 2005 20:13:30 -0800, beliavsky wrote: [snip] I'm a Windows user, not a Unix sysadmin, but I've noticed that Cameron Laird has written several articles on Python for system administration in Unix Review and Sys Admin magazine, for example http://www.unixreview.com/documents/s=9083/sam0401d/ . Reading his articles may help you decide if Python is a good fit for your work. Great series of articles. Thanks for the link. :) -- --- if replying via email, remove zees --- -- http://mail.python.org/mailman/listinfo/python-list