Re: Idiom for running compiled python scripts?
Mark <[EMAIL PROTECTED]> writes: > Of course I realise the modern mantra that "premature optimisation is > the root of all evil" but I don't subscribe to it. Programmers have been > "encouraged" to not give a toss about efficiency and the outcome is all > too apparent - most software today looks and runs like a pile of crap. Many people write code that is very obviously "wrong". But that doesn't mean that labouring for hours over minor speed-ups is actually worthwile for people who don't, as a rule, do gratuitously "wrong" stuff in the first place. There is, of course, a trade-off between programmer time and run time. It's hard to know where the correct balance lies for each particular program. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to receive a FILE* from Python under MinGW?
On Mar 24, 5:37 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 23 Mar 2007 16:34:22 -0300, Gabriel Genellina > <[EMAIL PROTECTED]> escribió: > > >> What about calling mscvrt_get_osfhandle from inside the SWIG wrapper? > >> I tried this but it seemed that the function was not exported to the > >> DLL. > > > The idea is to separate both worlds - _get_osfhandle must be called from > > the C runtime used by Python, not the one linked to your extension. > > Ah, but you could import the msvcrt module and get it from there. *ONLY* > get_osfhandle. The other function, open_osfhandle, must be from the > runtime used by your extension. > > -- > Gabriel Genellina Yes, that was what I was hoping might be possible. Have not had any luck with that yet though. Cheers JP -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Mar 25, 2:46 am, Mark <[EMAIL PROTECTED]> wrote: > On Sat, 24 Mar 2007 07:21:21 -0700, irstas wrote: > > A simple implementation that "works": > > Not quite irstas BTW .. I was expecting this, hence the quotes around 'works' :P. Another known issue is that globals() dictionary is somewhat different when ran with my module. You should probably look into the runpy's source code for better environment compability (Python25/Lib/runpy.py). Although no quarantees that it'd help. > Something about the environment is not quite the same. Any ideas? What Gabriel said may be the correct fix (I actually couldn't reproduce the bug so I couldn't test), but here's another idea: You could wrap your main method in a try-finally block: def main(): try: do things finally: remove temp files The finally-block will be executed even if you call sys.exit inside the try-block. This change will also make it possible to invoke your script many times, with temp files getting deleted after each invocation, should this ever be useful to you. (well, not if you use sys.exit :P) -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension returning subclassed list type?
On Sat, 24 Mar 2007 23:43:10 -0700, bullockbefriending bard wrote: > z_list = [Z(y.var1, y.var2,..) for y in list_of_objects_of_class_Y] > > Of course this just gives me a plain list and no access to the > methodsof z_list. List comprehensions give you a list. If you want to convert that list into the type of z_list, you need to do it yourself. Since ZList sub-classes from list, probably the easiest way is just: z_list = ZList([some list comprehension here]) > I could, of course go and write a static method in > ZList which takes a plain list of Z objects and returns a ZList. Yes, that would be one such way. Another way is: z_list.extend([some list comprehension here]) If you are using a recent enough version of Python, you probably don't even need the list comprehension. Just use a generator expression: z_list.extend(Z(y.var1, y.var2,..) for y in list_of_objects_of_class_Y) That's especially useful if the list of objects is huge, because it avoids creating the list twice: once in the list comp, and once as z_list. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: functions, classes, bound, unbound?
On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > MyClass.someFunc > > Is there some other way to retrieve a user-defined function object > from a class other than using the class name or an instance? What Steven B. already said, MyClass.__dict__['someFunc'], is a different way than MyClass.someFunc that produces different results. Since the method is an attribute of a class, what other kinds of means are you expecting to be possible? You can use reflection to dig up MyClass-object from the module dictionary if referring to object or class by name in the code is something you want to get rid of. -- http://mail.python.org/mailman/listinfo/python-list
Re: List comprehension returning subclassed list type?
Thanks! I went with extend and generator expression as I *am* dealing with rather a lot of data. Now I think I'm going to go on a little hunt through my code looking for more places where I should replace list comprehensions with generator expressions - bit of a newbie here. On Mar 25, 3:57 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sat, 24 Mar 2007 23:43:10 -0700, bullockbefriending bard wrote: > > z_list = [Z(y.var1, y.var2,..) for y in list_of_objects_of_class_Y] > > > Of course this just gives me a plain list and no access to the > > methodsof z_list. > > List comprehensions give you a list. If you want to convert that list into > the type of z_list, you need to do it yourself. Since ZList sub-classes > from list, probably the easiest way is just: > > z_list = ZList([some list comprehension here]) > > > I could, of course go and write a static method in > > ZList which takes a plain list of Z objects and returns a ZList. > > Yes, that would be one such way. Another way is: > > z_list.extend([some list comprehension here]) > > If you are using a recent enough version of Python, you probably don't > even need the list comprehension. Just use a generator expression: > > z_list.extend(Z(y.var1, y.var2,..) for y in list_of_objects_of_class_Y) > > That's especially useful if the list of objects is huge, because it avoids > creating the list twice: once in the list comp, and once as z_list. > > -- > Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Sun, 25 Mar 2007 07:10:23 +, Mark wrote: > On Sun, 25 Mar 2007 13:40:33 +1000, Steven D'Aprano wrote: >> Because this is entirely a trivial saving. Who cares? Sheesh. >> ... >> Saving 18ms on a script that takes 50ms to execute *might* be >> worthwhile, ... > > I don't understand your attitude. Sure, we are talking slight savings in > machine efficiency but I am sure the python developers have laboured > many long hours on subtle optimisations of the virtual machine, many of > which probably dwarf the issue discussed here. Tell them their work is > trivial and unnecessary. Why would I do that? As you said yourself, their optimizations dwarf the trivial issue you discuss. They, unlike you, grasp that the aim of optimization is to make significant savings in meaningful places, not waste time making insignificant savings in meaningless places. > Every little bit helps. No it doesn't. Spending hours of effort to save 18 seconds a day is a waste of both time and effort. If you have a process that takes eight hours and 18 seconds to run, and you need it to run in eight hours or less, then that 18 seconds is absolutely critical. But how likely is that? Chances are nobody will care if the process takes eight hours and ten minutes or seven minutes and fifty minutes. Saving 18ms once at startup for a single script, or 18 seconds over the course of an entire day, pales into insignificance. > Why do I concern myself > with this inefficiency - because it is there. Fine fine -- except the hours you spend solving it is an inefficiency a million times bigger than the one you are concerned with. Okay, that's not fair -- it might take you hours to solve it once, but from that moment on, you can save 18ms every time you run a script. In the course of a day, you might save 18 seconds. In just 600 working days, you'll have made that time back, and every 18ms after that is pure gain! BFD. Except, of course, that each time you type that one extra character, you lose 160ms to gain 18ms. You're actually going backwards. And that's the thing that demonstrates that for all your talk of efficiency, you're not really interested in efficiency. If you were, you'd do the maths and, having discovered that it costs you 160ms to save 18ms, you're actually *less* efficient. > Of course I realise the modern mantra that "premature optimisation is > the root of all evil" but I don't subscribe to it. That's nice. > Programmers have been > "encouraged" to not give a toss about efficiency Blathering on about saving 18ms might make you feel good, but that's not efficient. Making the code run 18ms faster at the expense of the total process running 140ms slower is a pessimation, not an optimization. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Class factory functions
Here's a simple class-factory function that returns a sub-class of the
old-style class it is passed.
def verbosify_oclass(klass):
"""Returns a verbose sub-class of old-style klass."""
class VClass(klass):
def __init__(self, *args, **kwargs):
print "Calling initializer __init__ ..."
klass.__init__(self, *args, **kwargs)
return VClass
Here it is in action:
>>> class Parrot:
... def __init__(self, colour): self.colour = colour
...
>>> VParrot = verbosify_oclass(Parrot)
>>> bird = VParrot('red')
Calling initializer __init__ ...
>>> bird.colour
'red'
Here's an equivalent for new-style classes. It uses super() because I
understand that super() is preferred to calling the super-class by name.
def verbosify_nclass(klass):
"""Returns a verbose sub-class of new-style klass."""
class VClass(klass):
def __new__(cls, *args, **kwargs):
print "Calling constructor __new__ ..."
return super(klass, cls).__new__(cls, *args, **kwargs)
def __init__(self, *args, **kwargs):
print "Calling initializer __init__ ..."
super(klass, self).__init__(*args, **kwargs)
return VClass
But it doesn't work:
>>> vint = verbosify_nclass(int)
>>> vint(42)
Calling constructor __new__ ...
Traceback (most recent call last):
File "", line 1, in
File "", line 6, in __new__
TypeError: object.__new__(VClass) is not safe, use int.__new__()
What am I doing wrong?
Here's one solution: dump the call to super() and call the super-class
directly. It seems to work. Are there any problems in not using super()?
What about multiple inheritance?
def verbosify_nclass2(klass):
"""Returns a verbose sub-class of new-style klass."""
class VClass(klass):
def __new__(cls, *args, **kwargs):
print "Calling constructor __new__ ..."
return klass.__new__(klass, *args, **kwargs)
def __init__(self, *args, **kwargs):
print "Calling initializer __init__ ..."
super(klass, self).__init__(*args, **kwargs)
return VClass
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Class factory functions
Steven D'Aprano wrote:
> Here's a simple class-factory function that returns a sub-class of the
> old-style class it is passed.
>
> def verbosify_oclass(klass):
> """Returns a verbose sub-class of old-style klass."""
> class VClass(klass):
> def __init__(self, *args, **kwargs):
> print "Calling initializer __init__ ..."
> klass.__init__(self, *args, **kwargs)
> return VClass
>
>
> Here it is in action:
>
class Parrot:
> ... def __init__(self, colour): self.colour = colour
> ...
VParrot = verbosify_oclass(Parrot)
bird = VParrot('red')
> Calling initializer __init__ ...
bird.colour
> 'red'
>
>
> Here's an equivalent for new-style classes. It uses super() because I
> understand that super() is preferred to calling the super-class by name.
>
>
> def verbosify_nclass(klass):
> """Returns a verbose sub-class of new-style klass."""
> class VClass(klass):
> def __new__(cls, *args, **kwargs):
> print "Calling constructor __new__ ..."
> return super(klass, cls).__new__(cls, *args, **kwargs)
> def __init__(self, *args, **kwargs):
> print "Calling initializer __init__ ..."
> super(klass, self).__init__(*args, **kwargs)
> return VClass
>
>
>
> But it doesn't work:
>
vint = verbosify_nclass(int)
vint(42)
> Calling constructor __new__ ...
> Traceback (most recent call last):
> File "", line 1, in
> File "", line 6, in __new__
> TypeError: object.__new__(VClass) is not safe, use int.__new__()
>
>
> What am I doing wrong?
Why would you skip VClass in the super() calls? This should work:
def verbosify_nclass(klass):
"""Returns a verbose sub-class of new-style klass."""
class VClass(klass):
def __new__(cls, *args, **kwargs):
print "Calling constructor __new__ ..."
return super(VClass, cls).__new__(cls, *args, **kwargs)
def __init__(self, *args, **kwargs):
print "Calling initializer __init__ ..."
super(VClass, self).__init__(*args, **kwargs)
return VClass
Peer
--
http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
Mark <[EMAIL PROTECTED]> writes: > Of course I realise the modern mantra that "premature optimisation is > the root of all evil" but I don't subscribe to it. Note the first word - premature. It's an important distinction, and you've entirely missed it. Optimization is premature if you haven't yet ensured that your program is correct. Worry about getting it right first - and that includes selecting the appropriate algorithms. Optimization is premature if you haven't yet profiled your code to identify precisely *what* code is a bottleneck. Once you've identified your code's bottleneck(s), and verified that your algorithm(s) is (are) ideal - then it's time to optimize the implementation of the algorithm(s), if you still need to. (Most of the time you won't; in my experience, bottlenecks are the result of badly-chosen algorithms in at least nine out of ten cases.) > Programmers have been > "encouraged" to not give a toss about efficiency Nonsense. Efficiency is about making the best use of limited resources, and in most cases the most limited resource is people. Saving $x in hardware cost by spending $x*10 on programmer salary is not efficient. > and the outcome is all > too apparent - most software today looks and runs like a pile of crap. Most software today is written by comparitive amateurs who use "clever" code that tries to compensate for badly-chosen algorithms, who guess at where bottlenecks "might" be instead of profiling their code to see exactly where they *are*, and who scoff at Knuth's "mantra" because they've misunderstood what he meant by both "premature" and "optimization". In other words, premature optimization is quite often the reason why software often looks and runs like a pile of crap. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
On 24 Mar, 18:55, "7stud" <[EMAIL PROTECTED]> wrote: > I don't know if there is a framework install for 2.5. http://www.python.org/ftp/python/2.5/python-2.5-macosx.dmg has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
On 25 Mar, 06:11, "7stud" <[EMAIL PROTECTED]> wrote: > There it is. I notice there is a directory: /Python.framework/ > Versions/2.3/Mac/Tools/IDE > which has a bunch of files in it. Do Macs have some kind of pre- > installed Python IDE? There's no read me file, so I can't tell what > all the files are for. That's the source for the old MacPython IDE which is now defunct. Just ignore it. Apple don't bundle a Python IDE in OS X. However, the Python 2.5 installer (http://www.python.org/ftp/python/2.5/python-2.5-macosx.dmg) includes a copy of IDLE (not very Mac-like, unfortunately) and there are various third-party editors available if you want to search around. has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html -- http://mail.python.org/mailman/listinfo/python-list
Beginner GTK question
I have a simple page that I want to display a menu and toolbar. I
have followed the tutorials and have made some customizations to the
basic code snippet found at
http://www.pygtk.org/pygtk2tutorial/examples/uimanager.py
However my customized code does not display the menu bar. It displays
the toolbar though. The terminal output is
gui.py:79: GtkWarning: Quit: missing action
menubar = uimanager.get_widget('/MenuBar')
Line 79 is this
menubar = uimanager.get_widget('/MenuBar')
Thank you for any help in advanced.
Here is the code
#!/usr/bin/env python
#
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import pygtk
pygtk.require('2.0')
import gtk
class d3_gui:
ui = '''
'''
def __init__(self):
# Setup the window
window = gtk.Window()
# Kill the program if it's closed
window.connect("destroy", lambda w: gtk.main_quit())
# Set title and window size
window.set_title("d3vscan")
window.set_size_request(640, 480)
# setup the widget container
vbox = gtk.VBox()
window.add(vbox)
# Setup uimanager for menu and toolbar
uimanager = gtk.UIManager()
# Add accelerator group
accelgroup = uimanager.get_accel_group()
window.add_accel_group(accelgroup)
# Create an ActionGroup
actiongroup = gtk.ActionGroup('d3_gui')
self.actiongroup = actiongroup
# Create actions
actiongroup.add_actions(
[
('Quit', gtk.STOCK_QUIT, '_Quit me!', None,
'Quit the Program', self.quit_d3),
('File', None, '_File')
]
)
actiongroup.get_action('Quit').set_property('short-label',
'_Quit')
# Attach the action group
uimanager.insert_action_group(actiongroup, 0)
# Add a UI description
uimanager.add_ui_from_string(self.ui)
# make menu
menubar = uimanager.get_widget('/MenuBar')
vbox.pack_start(menubar, False)
# Create toolbar
toolbar = uimanager.get_widget('/ToolBar')
vbox.pack_start(toolbar, False)
window.show_all()
return
def quit_d3(self, b):
print 'Quitting program'
gtk.main_quit()
def main():
gtk.main()
return 0
if __name__ == "__main__":
d3 = d3_gui()
gtk.main()
--
http://mail.python.org/mailman/listinfo/python-list
Strange behavior when printing a returned closure function
Hello, when I execute the following code (python 2.5) def f(x): def g(): return x return g print f(1) print f(2) I get an output like So according to print I get the same function object returned at both calls. That's surprising, I would expect to get two distinct function objects because their func_closure attribute has to be different. And indeed, if I do print f(1) is f(2) instead, it prints False. Even more confusing, if I do g1 = f(1) g2 = f(2) print g1 print g2 I get something like ie. two distinct function objects are printed. What's happening here? Some clever optimization reusing function objects in special cases or what ...? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior when printing a returned closure function
On 25 Mar 2007 03:59:52 -0700, [EMAIL PROTECTED] wrote: >Hello, > >when I execute the following code (python 2.5) > >def f(x): >def g(): >return x >return g > >print f(1) >print f(2) > >I get an output like > > > > >So according to print I get the same function object returned at both >calls. >That's surprising, I would expect to get two distinct function objects >because their func_closure attribute has to be different. And indeed, >if I do > >print f(1) is f(2) > >instead, it prints False. Even more confusing, if I do > >g1 = f(1) >g2 = f(2) >print g1 >print g2 > >I get something like > > > > >ie. two distinct function objects are printed. > >What's happening here? >Some clever optimization reusing function objects in special cases or >what ...? They're _not_ the same function object, just like the `is' test told you. They just happen to have been allocated at the same memory address. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Using remote source code
[EMAIL PROTECTED] writes: > Is there any possible way that I can place a .py file on the internet, > and use that source code in an .py file on my computer? Besides Alex suggestion, you can also check Pyro. -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
On 24 Mar, 18:30, "Robert Hicks" <[EMAIL PROTECTED]> wrote: > I want to upgrade to 2.5 but I don't see any unistall instructions > anywhere. To repeat what others have said: don't uninstall existing Python.framework builds. Frameworks support multiple versions quite happily, and removing them is more hassle than it's worth. Just install the official framework build from python.org (http:// www.python.org/ftp/python/2.5/python-2.5-macosx.dmg), which should also update your shell profiles as necessary. HTH has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org http://appscript.sourceforge.net/objc-appscript.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python object overhead?
Facundo Batista wrote: > "not line" and "len(line) == 0" is the same as long as "line" is a > string. > > He's checking ok, 'cause a "blank line" has a lenght > 0 (because > of newline). Ah, K. Normally, I strip the read line and then test "if not line". His check /is/ okay, but IMHO it's a little bit weird. > Unless I understood it wrong, it's just an object that holds the > line inside. A Python string would technically be the same ;) > Just OO purity, not practicality... :) Regards, Björn -- BOFH excuse #378: Operators killed by year 2000 bug bite. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python object overhead?
Felipe Almeida Lessa wrote: > Could you tell me what in Python isn't an object? Difficult ;) All data structures are (CMIIW). Functions and Types are objects, too. > Are you counting old-style classes and instances as "not object"s? No, both are. Regards, Björn -- BOFH excuse #366: ATM cell has no roaming feature turned on, notebooks can't connect -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior when printing a returned closure function
On Mar 25, 1:04 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On 25 Mar 2007 03:59:52 -0700, [EMAIL PROTECTED] wrote: > > > > >Hello, > > >when I execute the following code (python 2.5) > > >def f(x): > >def g(): > >return x > >return g > > >print f(1) > >print f(2) > > >I get an output like > > > > > > > >So according to print I get the same function object returned at both > >calls. > >That's surprising, I would expect to get two distinct function objects > >because their func_closure attribute has to be different. And indeed, > >if I do > > >print f(1) is f(2) > > >instead, it prints False. Even more confusing, if I do > > >g1 = f(1) > >g2 = f(2) > >print g1 > >print g2 > > >I get something like > > > > > > > >ie. two distinct function objects are printed. > > >What's happening here? > >Some clever optimization reusing function objects in special cases or > >what ...? > > They're _not_ the same function object, just like the `is' test told you. > They just happen to have been allocated at the same memory address. > > Jean-Paul ah yes, I see, thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Toplevel geometry
Chris wrote:
> Hi,
>
> If a user resizes a Toplevel window, or I set a Toplevel's geometry
> using the geometry() method*, is there any way to have the geometry
> reset to that required for all the widgets?
>
> I think I found what I'm looking for in tk itself:
> """
> 13.3. How can I clear the geometry settings for a toplevel?
> If you want to have Tk resize your toplevel to what the toplevel
> requires (ie: the user might have resized it, or a widget was
> removed), use [wm geometry $toplevel].
> """
> [from http://tcl.sourceforge.net/faqs/tk/]
>
>
>
> * for instance, if I want to turn of Tkinter's automatic adjustment of
> the window to fit all the widgets by doing something like
> self.geometry(self.geometry()), is there any way to undo that?
>
> Thanks,
> Chris
>
Hi Chris,
I think you are on to something. The equivalent of
[wm geometry $toplevel]
in Tkinter would be
sometop.geometry()
Or, equivalently,
sometop.wm_geometry()
Or, calling the underlying tcl/tk interpreter directly
sometop.tk.call('wm', 'geometry', str(sometop))
Which is redundant, but emphasizes the point: This does not resize the
widget as expected nor does it cause the window to resize upon adding
new packing slaves--at least for the X11 based Tkinter for mac via the
fink debian based package manager.
Really wish things worked according to the docs a lot of the time or
that they weren't so poorly written. Perhaps they are implying that you
must pass parameters, however they do not explain how one might generate
said parameters to get the required size to which they allude. Terribly
disappointing.
James
--
http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior when printing a returned closure function
On Sun, 25 Mar 2007 03:59:52 -0700, dartsch wrote: > I get an output like > > > > > So according to print I get the same function object returned at both > calls. Not the same function object. The first object is printed, then deleted by the garbage collector because it goes out of scope. Then the second one is created and just happens to end up in the same memory location. That's an accident of the garbage collector implementation. > That's surprising, I would expect to get two distinct function objects > because their func_closure attribute has to be different. And indeed, > if I do [snip] > > > > ie. two distinct function objects are printed. This time the first function still exists when the second is created, so the second naturally can't be in the same memory location. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class factory functions
On Sun, 25 Mar 2007 11:58:00 +0200, Peter Otten wrote: >> But it doesn't work: >> > vint = verbosify_nclass(int) > vint(42) >> Calling constructor __new__ ... >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 6, in __new__ >> TypeError: object.__new__(VClass) is not safe, use int.__new__() >> >> >> What am I doing wrong? > > Why would you skip VClass in the super() calls? That's a good question. If I every get a good answer, I'll let you know. > This should work: [snip] As indeed it seems like it does. Thank you, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Toplevel geometry
James Stroud wrote:
> Chris wrote:
>> Hi,
>>
>> If a user resizes a Toplevel window, or I set a Toplevel's geometry
>> using the geometry() method*, is there any way to have the geometry
>> reset to that required for all the widgets?
>>
>> I think I found what I'm looking for in tk itself:
>> """
>> 13.3. How can I clear the geometry settings for a toplevel?
>> If you want to have Tk resize your toplevel to what the toplevel
>> requires (ie: the user might have resized it, or a widget was
>> removed), use [wm geometry $toplevel].
>> """
>> [from http://tcl.sourceforge.net/faqs/tk/]
>>
>>
>>
>> * for instance, if I want to turn of Tkinter's automatic adjustment of
>> the window to fit all the widgets by doing something like
>> self.geometry(self.geometry()), is there any way to undo that?
>>
>> Thanks,
>> Chris
>>
>
> Hi Chris,
>
> I think you are on to something. The equivalent of
>
>[wm geometry $toplevel]
>
> in Tkinter would be
>
>sometop.geometry()
>
> Or, equivalently,
>
>sometop.wm_geometry()
>
> Or, calling the underlying tcl/tk interpreter directly
>
>sometop.tk.call('wm', 'geometry', str(sometop))
>
> Which is redundant, but emphasizes the point: This does not resize the
> widget as expected nor does it cause the window to resize upon adding
> new packing slaves--at least for the X11 based Tkinter for mac via the
> fink debian based package manager.
>
> Really wish things worked according to the docs a lot of the time or
> that they weren't so poorly written. Perhaps they are implying that you
> must pass parameters, however they do not explain how one might generate
> said parameters to get the required size to which they allude. Terribly
> disappointing.
>
> James
After playing with this an inordinate amount of time, I found that one
does need to supply parameters, namely the null parameter of an empty
string. Try:
sometop.geometry('')
This repacks according to the widgets. Not quite clear from the
miserable docs, is it?
James
--
http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Toplevel geometry
James Stroud wrote:
> James Stroud wrote:
>> Chris wrote:
>>> Hi,
>>>
>>> If a user resizes a Toplevel window, or I set a Toplevel's geometry
>>> using the geometry() method*, is there any way to have the geometry
>>> reset to that required for all the widgets?
>>>
>>> I think I found what I'm looking for in tk itself:
>>> """
>>> 13.3. How can I clear the geometry settings for a toplevel?
>>> If you want to have Tk resize your toplevel to what the toplevel
>>> requires (ie: the user might have resized it, or a widget was
>>> removed), use [wm geometry $toplevel].
>>> """
>>> [from http://tcl.sourceforge.net/faqs/tk/]
>>>
>>>
>>>
>>> * for instance, if I want to turn of Tkinter's automatic adjustment of
>>> the window to fit all the widgets by doing something like
>>> self.geometry(self.geometry()), is there any way to undo that?
>>>
>>> Thanks,
>>> Chris
>>>
>>
>> Hi Chris,
>>
>> I think you are on to something. The equivalent of
>>
>>[wm geometry $toplevel]
>>
>> in Tkinter would be
>>
>>sometop.geometry()
>>
>> Or, equivalently,
>>
>>sometop.wm_geometry()
>>
>> Or, calling the underlying tcl/tk interpreter directly
>>
>>sometop.tk.call('wm', 'geometry', str(sometop))
>>
>> Which is redundant, but emphasizes the point: This does not resize the
>> widget as expected nor does it cause the window to resize upon adding
>> new packing slaves--at least for the X11 based Tkinter for mac via the
>> fink debian based package manager.
>>
>> Really wish things worked according to the docs a lot of the time or
>> that they weren't so poorly written. Perhaps they are implying that
>> you must pass parameters, however they do not explain how one might
>> generate said parameters to get the required size to which they
>> allude. Terribly disappointing.
>>
>> James
>
> After playing with this an inordinate amount of time, I found that one
> does need to supply parameters, namely the null parameter of an empty
> string. Try:
>
> sometop.geometry('')
>
> This repacks according to the widgets. Not quite clear from the
> miserable docs, is it?
>
> James
Now for the advanced question, how might one bind that to the
resize/maximize button of the window decorations? I'm guessing with
protocol, but its way past my bedtime.
James
--
http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Toplevel geometry
> After playing with this an inordinate amount of time, I found that one
> does need to supply parameters, namely the null parameter of an empty
> string. Try:
>
>sometop.geometry('')
>
> This repacks according to the widgets. Not quite clear from the
> miserable docs, is it?
Wow, that does work. Thank you very much for figuring it out!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Pycron for windows - please help
Shane, I figured it out... Pycron does not work with mapped drives. My script was supposed to copy files from a mapped drive to a local folder... I had set up my batch command as copy M:\foldername\*.*, where M: is a mapped drive pointing to the network share; M: is defined on the PC running the Pycron service of course. I changed it to read copy \\servername\shares\foldername\*.* and now everything works correctly. Al -- http://mail.python.org/mailman/listinfo/python-list
Re: Pattern for foo tool <-> API <-> shell|GUI
Anastasios Hatzis wrote:
> I'm working on a tool which is totally command-line based and consisting of
> multiple scripts. The user can execute a Python script in the shell, this
> script does some basic verification before delegating a call into my tool's
> package and depending on some arguments and options provided in the
> command-line, e.g.
> $python generate.py myproject --force --verbose
> the tool processes whatever necessary. There are multiple command handlers
> available in this package which are responsible for different tasks and
> depending of the script that has been executed one or more of these command
> handlers are fired to do their work ;)
Side note: you might find argparse (http://argparse.python-hosting.com/)
makes this a bit easier if you have positional arguments or sub-commands::
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('name')
>>> parser.add_argument('--force', action='store_true')
>>> parser.add_argument('--verbose', action='store_true')
>>> parser.parse_args(['my_project', '--force', '--verbose'])
Namespace(force=True, name='my_project', verbose=True)
>>> parser = argparse.ArgumentParser()
>>> subparsers = parser.add_subparsers()
>>> cmd1_parser = subparsers.add_parser('cmd1')
>>> cmd1_parser.add_argument('--foo')
>>> cmd2_parser = subparsers.add_parser('cmd2')
>>> cmd2_parser.add_argument('bar')
>>> parser.parse_args(['cmd1', '--foo', 'X'])
Namespace(foo='X')
>>> parser.parse_args(['cmd2', 'Y'])
Namespace(bar='Y')
> And I don't think that this is very trivial (at least not for my programming
> skill level). In the given example "generate.py" (above) the following
> scenario is pretty likely:
>
> (1) User works with UML tool and clicks in some dialog a "generate" button
> (2) UML tool triggers this event an calls a magic generate() method of my
> tool
> (via the API I provide for this purpose), like my generate.py script would do
> same way
> (3) Somewhen with-in this generate process my tool may need to get some
> information from the user in order to continue (it is in the nature of the
> features that I can't avoid this need of interaction in any case).
So you're imagining an API something like::
def generate(name,
force=False,
verbose=False,
handler=command_line_handler):
...
choice = handler.prompt_user(question_text, user_choices)
...
where the command-line handler might look something like::
class CommandLineHandler(object):
...
def prompt_user(self, question_text, user_choices):
while True:
choice = raw_input(question_text)
if choice in user_choices:
return choice
print 'invalid choice, choose from %s' % choices
and the GUI client would implement the equivalent thing with dialogs?
That seems basically reasonable to me, though you should be clear in the
documentation of generate() -- and any other methods that accept handler
objects -- exactly what methods the handler must provide.
You also may find that "prompt_user" is a bit too generic -- e.g. a file
chooser dialog looks a lot different from a color chooser dialog -- so
you may need to split this up into "prompt_user_file",
"prompt_user_color", etc. so that handler's don't have to introspect the
question text to know what to do...
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Other classes in a module
Hi! Can an instance of a class in a module, in any simple way find out which other classes that exists in said module ? -- Roland -- http://mail.python.org/mailman/listinfo/python-list
saving algorithm
hi i want to ask about the algorithm's steps of saving games(sudoku,battleship)? thank you - Don't pick lemons. See all the new 2007 cars at Yahoo! Autos.-- http://mail.python.org/mailman/listinfo/python-list
Re: Other classes in a module
Roland Hedberg wrote: > Can an instance of a class in a module, in any simple way find out which > other classes that exists in said module ? set(v for v in globals().values() if inspect.isclass(v) and v.__module__ == __name__) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Other classes in a module
> Can an instance of a class in a module, in any simple way find out which > other classes that exists in said module ? # module x ## class c1: pass class c2: pass ### Python 2.5 (r25:51908, Nov 1 2006, 11:42:37) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import types >>> import x >>> for i in dir(x): ... if type(getattr(x,i)) is types.ClassType: ... print "Hey, '%s' is a class!" % i ... Hey, 'c1' is a class! Hey, 'c2' is a class! >>> It might be not exactly what you want but maybe still helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pycron for windows - please help
En Sun, 25 Mar 2007 10:17:47 -0300, Al <[EMAIL PROTECTED]> escribió: >I figured it out... Pycron does not work with mapped drives. My > script was supposed to copy files from a mapped drive to a local > folder... I had set up my batch command as copy M:\foldername\*.*, > where M: is a mapped drive pointing to the network share; M: is > defined on the PC running the Pycron service of course. I changed it > to read copy \\servername\shares\foldername\*.* and now everything > works correctly. Mapped drives are per-user. Usually, services run under the LOCAL_SYSTEM account, not using the currently logged user (because they may start even before any user is logged). If you want the service to have access to your mapped drives, use the service control panel to make it run under another account. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
organizing collections of small modules
I have a bunch of small modules that I use within my application. Most of these modules are single file modules. Currently, I have them set up as stand-alone modules but because it's a royal pain to fetch five or 10 of these modules for each application and tracking whether or not they are all up to date, I'm considering putting them all into one collection (rcsoc a.k.a. random cross-section of code[1]) so it's easier to load, install, and manage. Are there better techniques for managing collections of modules in 2.4 or later? ---eric [1] derives from the expression that hamburger is "random cross-section of cow" -- http://mail.python.org/mailman/listinfo/python-list
Re: saving algorithm
En Fri, 23 Mar 2007 20:42:33 -0300, mona bin jubair <[EMAIL PROTECTED]> escribió: > i want to ask about the algorithm's steps of saving > games(sudoku,battleship)? First determine what goes into the game "state" (that is, what defines the current state of the game). Perhaps you also want some history. Then, save that game state: using pickle, or a database, or even a simple ConfigParser file. See http://docs.python.org/lib/persistence.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
How to find to HTML strings and 'save' them?
Hi All, Apologies for the newbie question but I've searched and tried all sorts for a few days and I'm pulling my hair out ;[ I have a 'reference' HTML file and a 'test' HTML file from which I need to pull 10 strings, all of which are contained within tags, e.g.: http://www.someplace.com/";>Go Someplace Once I've found the 10 I'd like to write them to another 'results' html file. Perhaps a 'reference results' and a 'test results' file. >From where I would then like to 'diff' the results to see if they match. Here's the rub: I cannot find a way to pull those 10 strings so I can save them to the results pages. Can anyone please suggest how this can be done? I've tried allsorts but I've been learning Python for 1 week and just don't know enough to mod example scripts it seems. don't even get me started on python docs.. ayaa ;] Please feel free to teach me to suck eggs because it's all new to me :) Thanks in advance, Mark. -- http://mail.python.org/mailman/listinfo/python-list
[ANN] argparse 0.7 - Command-line parsing library
Announcing argparse 0.7
---
The argparse module is an optparse-inspired command line parser that
improves on optparse by supporting:
* positional arguments
* sub-commands
* required options
* options with a variable number of args
* better usage messages
* a much simpler extension mechanism
and a number of other improvements on the optparse API.
Download argparse
=
argparse home:
http://argparse.python-hosting.com/
argparse single module download:
http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw
argparse bundled downloads at PyPI:
http://www.python.org/pypi/argparse/
About this release
==
This release adds support for single-dash long options and combining
single-dash options in a single option string.
Note that the 'outfile' type is still deprecated and will likely be
removed in the next release. Please update your code to use the new
FileType factory.
New in this release
===
* Single-dash long options (e.g. ``-foo`` or ``-foo-bar``)
* Combining single-dash options (e.g. ``-xy`` is now the same as
``-x -y`` when ``-x`` does not take an argument)
Example argparse code
=
Here's a simple program that sums its command-line arguments and
writes them to a file::
parser = argparse.ArgumentParser()
parser.add_argument('integers', nargs='+', type=int)
parser.add_argument('--log', default=sys.stdout,
type=argparse.FileType('w'))
args = parser.parse_args()
args.log.write('%s\n' % sum(args.integers))
args.log.close()
--
http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Toplevel geometry
In article <[EMAIL PROTECTED]>,
Chris <[EMAIL PROTECTED]> wrote:
>
>> After playing with this an inordinate amount of time, I found that one
>> does need to supply parameters, namely the null parameter of an empty
>> string. Try:
>>
>>sometop.geometry('')
>>
>> This repacks according to the widgets. Not quite clear from the
>> miserable docs, is it?
>
>
>Wow, that does work. Thank you very much for figuring it out!
>
A TRULY good way to show your thanks for help like this
is to write up what you learned at the Tkinter Wiki http://tkinter.unpythonic.net/wiki/ >. Note:
A. You have to log in to edit pages
on this particular Wiki. If you
decide to join us, then, you'll
first need to create an account.
Read-only visitors can be anony-
mous, of course.
B. Major thanks to Jeff Epler for
maintaining the site, and, in
particular, for fighting off
recent vandalism.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using remote source code
En Sun, 25 Mar 2007 04:06:21 -0300, Shane Geiger <[EMAIL PROTECTED]> escribió: > I see that you aren't using ihooks. Below is an example I found that > uses ihooks. I think it would be worth comparing and contrasting both > approaches (though I am not familar enough with this aspect of Python to > do so). IIRC, this code addresses some path related issues of other > import-from-file methods. ihooks is rather old and undocumented except for a comment saying that it "may become obsolete". PEP 302 sets the recomended way now, AFAIK. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Interactive session, alternating prompt. readline? curses?
Hi all,
I'm looking at building an interactive session in front of some
rdfobj instances. I've used cmd and just found code.Interactive*.
Protocol doesn't matter, I'm looking at the UI possibilities.
History is nice to have and my intention is to write output of
the session to stdin/stderr.
However, my question, can I change the "prompt" string in respond
to user input using readline? AFAIK I'll need curses to do this?
And colored prompts?
Example: the prompt, say '>>>', would change depending on wether
I type '<', '@' or ':' (and autocompletion libraries change too) .
I sometimes see some fancy shell output ('percentage loaded'-bars,
etc) and I'm wondering how to do this with python and what it does
to stdout. Any pointers?
regards, Berend
PS: please cc, I'm not on list
--
web, http://dotmpe.com ()ASCII Ribbon
email, berend:dotmpe:com/\
irc, berend/mpe at irc.oftc.net
--
http://mail.python.org/mailman/listinfo/python-list
Re: Join strings - very simple Q.
Dustan escreveu: > On Mar 24, 7:16 am, Paulo da Silva <[EMAIL PROTECTED]> wrote: >> Dustan escreveu: >> >> >> >>> On Mar 23, 1:30 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: Mike Kent escreveu: ... > New way: > l=['a','b','c'] > jl=','.join(l) I thank you all. Almost there ... I tried "".join(l,',') but no success ... :-( Paulo >>> Perhaps you're doing it wrong, despite having an example right in >>> front of you? >> Some misunderstanding here ... >> The post was just to thank. I was refering to what I tried >> before posting the question here. > > Ah. Sorry; I didn't realize that. My fault. The post could well be read the way you did. English is not my 1st language anyway. Regards. Paulo -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing collections of small modules
"Eric S. Johansson" <[EMAIL PROTECTED]> writes: > I have a bunch of small modules that I use within my application. Most of > these modules are single file modules. Currently, I have them set up as > stand-alone modules but because it's a royal pain to fetch five or 10 of these > modules for each application and tracking whether or not they are all up to > date, I'm considering putting them all into one collection (rcsoc > a.k.a. random cross-section of code[1]) so it's easier to load, install, and > manage. > > Are there better techniques for managing collections of modules in 2.4 or > later? > > ---eric > > > [1] derives from the expression that hamburger is "random cross-section of > cow" I'm using setuptools for that. If they're somehow connected -- e.g. mathematics, database, finance, etc. -- then I create one single package for them. If they aren't, then creating several packages isn't hard. If they are useful enough you can publish them on PyPI and then it is just a matter of "easy_install" them. If they aren't then you'll have to collect them somewhere to use easy_install ;-) It also supplies means to determine the minimum / maximum / exact version that is required, so this also helps with how up-to-date your library has to be to be used with some application. -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
On Mar 25, 2007, at 12:04 PM, [EMAIL PROTECTED] wrote: > don't even get me > started on python docs.. ayaa ;] ok, try getting started with this then: http://www.crummy.com/ software/BeautifulSoup/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
[EMAIL PROTECTED] writes: > Hi All, > > Apologies for the newbie question but I've searched and tried all > sorts for a few days and I'm pulling my hair out ;[ > > I have a 'reference' HTML file and a 'test' HTML file from which I > need to pull 10 strings, all of which are contained within tags, > e.g.: > http://www.someplace.com/";>Go Someplace > > Once I've found the 10 I'd like to write them to another 'results' > html file. Perhaps a 'reference results' and a 'test results' file. >>From where I would then like to 'diff' the results to see if they > match. > > Here's the rub: I cannot find a way to pull those 10 strings so I can > save them to the results pages. > Can anyone please suggest how this can be done? > > I've tried allsorts but I've been learning Python for 1 week and just > don't know enough to mod example scripts it seems. don't even get me > started on python docs.. ayaa ;] Please feel free to teach me to suck > eggs because it's all new to me :) > > Thanks in advance, > > Mark. Take a look at BeautifulSoup. It is easy to use and works well with some malformed HTML that you might find ahead. -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone know of a MICR parser algorithm written in Python?
On Mar 25, 12:30 am, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
> On Mar 24, 6:52 pm, "mkppk" <[EMAIL PROTECTED]> wrote:
>
> > Its just that I would rather not reinvent the wheel (or read old C
> > code)..
>
> Wouldn't we all!
>
> Here is the basic structure of a pyparsing solution. The parsing part
> isn't so bad - the real problem is the awful ParseONUS routine in C.
> Plus things are awkward since the C program parses right-to-left and
> then reverses all of the found fields, and the parser I wrote works
> left-to-right. Still, this grammar does most of the job. I've left
> out my port of ParseONUS since it is *so* ugly, and not really part of
> the pyparsing example.
>
> -- Paul
>
> from pyparsing import *
>
> # define values for optional fields
> NoAmountGiven = ""
> NoEPCGiven = ""
> NoAuxOnusGiven = ""
>
> # define delimiters
> DOLLAR = Suppress("$")
> T_ = Suppress("T")
> A_ = Suppress("A")
>
> # field definitions
> amt = DOLLAR + Word(nums,exact=10) + DOLLAR
> onus = Word("0123456789A- ")
> transit = T_ + Word("0123456789-") + T_
> epc = oneOf( list(nums) )
> aux_onus = A_ + Word("0123456789- ") + A_
>
> # validation parse action
> def validateTransitNumber(t):
> transit = t[0]
> flds = transit.split("-")
> if len(flds) > 2:
> raise ParseException(0, "too many dashes in transit number",
> 0)
> if len(flds) == 2:
> if len(flds[0]) not in (3,4):
> raise ParseException(0, "invalid dash position in transit
> number", 0)
> else:
> # compute checksum
> ti = map(int,transit)
> ti.reverse() # original algorithm worked with reversed data
> cksum = 3*(ti[8]+ti[5]+ti[2]) + 7*(ti[7]+ti[4]+ti[1]) +
> ti[6]+ti[3]+ti[0]
> if cksum%10 != 0:
> raise ParseException(0, "transit number failed checksum",
> 0)
> return transit
>
> # define overallMICRformat, with results names
> micrdata =
> Optional(aux_onus,default=NoAuxOnusGiven).setResultsName("aux_onus") +
> \
> Optional(epc,default=NoEPCGiven).setResultsName("epc") +\
>
> transit.setParseAction(validateTransitNumber).setResultsName("transit")
> + \
> onus.setResultsName("onus") + \
> Optional(amt,default=NoAmountGiven).setResultsName("amt")
> + \
> stringEnd
>
> import re
>
> def parseONUS(tokens):
> tokens["csn"] = ""
> tokens["tpc"] = ""
> tokens["account"] = ""
> tokens["amt"] = tokens["amt"][0]
> onus = tokens.onus
> # remainder omitted out of respect for newsreaders...
> # suffice to say that unspeakable acts are performed on
> # onus and aux_onus fields to extract account and
> # check numbers
>
> micrdata.setParseAction(parseONUS)
>
> testdata = file("checks.csv").readlines()[1:]
> tests = [(flds[1],flds) for flds in map(lambda
> l:l.split(","),testdata)]
> def verifyResults(res,csv):
> def match(x,y):
> print (x==y and "_" or "X"),x,"=",y
>
> Ex,MICR,Bank,Stat,Amt,AS,TPC,TS,CSN,CS,ACCT,AS,EPC,ES,ONUS,OS,AUX,AS,Tran,TS
> = csv
> match(res.amt,Amt)
> match(res.account,ACCT)
> match(res.csn,CSN)
> match(res.onus,ONUS)
> match(res.tpc,TPC)
> match(res.epc,EPC)
> match(res.transit,Tran)
>
> for t,data in tests:
> print t
> try:
> res = micrdata.parseString(t)
> print res.dump()
> if not(data[0] == "No"):
> print "Passed expression that should have failed"
> verifyResults(res,data)
> except ParseException,pe:
> print " %s" % pe.msg
> if not(data[0] == "Yes"):
> print "Failed expression that should have passed"
> print
Great, thanks for taking a look Paul. I had never tried to use
pyparsing before. Yea, the ONUS field is crazy, don't know why there
is no standard for it.
--
http://mail.python.org/mailman/listinfo/python-list
problem at installing phyton on windows
Hi! I'm too new on phyton.I have installed phyton.But when I write phyton command, unfortunately, i can't run.I suppose that it is bacause of setting path.But i can't solve. Can you help? Another thing is, when i double click the .py file, there are the project form and the command line.How can i provide to view only the project? Thanks... -- http://mail.python.org/mailman/listinfo/python-list
a calendar example
Hi! I want to do a calendar where pictures on.Can you have any free example like this which can help me ? Regards... -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
gslm wrote: > Hi! > I'm too new on phyton.I have installed phyton.But when I write phyton > command, unfortunately, i can't run.I suppose that it is bacause of > setting path.But i can't solve. > Can you help? It's "python" you should be typing, of course. If that doesn't work then it may be a PATH issue, yes. > Another thing is, when i double click the .py file, there are the > project form and the command line.How can i provide to view only the > project? I think you need to rename the .py file so that it ends with .pyw - this stops the command line window from opening, but it's only useful if you are running a graphical program, obviously. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing collections of small modules
En Sun, 25 Mar 2007 13:44:54 -0300, Eric S. Johansson <[EMAIL PROTECTED]> escribió: > I have a bunch of small modules that I use within my application. Most > of these modules are single file modules. Currently, I have them set up > as stand-alone modules but because it's a royal pain to fetch five or 10 > of these modules for each application and tracking whether or not they > are all up to date, I'm considering putting them all into one collection > (rcsoc a.k.a. random cross-section of code[1]) so it's easier to load, > install, and manage. > > Are there better techniques for managing collections of modules in 2.4 > or later? Take a look at "source code management" (or software configuration management). Using CVSNT by example: you keep a full history of all module changes; you can retrieve any source as it was in a given time; you can organize your code into "modules" (higher order modules than python modules) that you can combine into projects. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Join strings - very simple Q.
John Machin escreveu: > On Mar 25, 12:32 am, Paulo da Silva <[EMAIL PROTECTED]> wrote: >> John Machin escreveu: .. > What was not obvious was (1) if you have been using Python for a > while, how you managed to be unaware of str methods (2) if you are a > newbie, how you managed to find out about the string module but not > find out about str method > This is a nice argument for perhaps a politician ... I am not exactly a newbie if you talk about the time I have been using Python but I have used it very few times and sparsely in time. I have always used 'string' to do the strings stuff. When I need a method, I just search the python library manual index. Then I have a page with all string methods available. This is why I knew 'string' and didn't know str. > > [e.g. it's easy to miss the one line in the > "official" Python tutorial that refers to them] (3) why you were not > using obvious(?) methods to find out for yourself -- much faster than > posing a question on the newsgroup, and you don't have to face the > possibility of an impertinent response :-) That's the kind of answer I hate. Of course anyone could find an answer to any questions without posting them to this NG. Google, Python inumerous manuals, books, etc. So, why the NG existence? The reason we post here is because sometimes it is easier, or we wait for any further discussion on the subject or just because we want it. There are lots of people in this NG with different levels of knowledge. If you feel that it is a question that deserves the honour of your response, just do it. Write it on the stones and send them down to the common people :-) . If not, just close your eyes and let others respond. If the question does not deserve any response, then the people will judge and will leave it unanswered. ... ... > you could try: > > (1) going to the docs page on the Python website (http:// > www.python.org/doc/), click on the "Search" link about one-third down > the page, and search for "join". You would get 6 results, one of which > is "join() (string method)" This, together with the answer other people here gave, is helpful. When I posted I thought the subjec was new, do you remember? ... > (3) Use Google groups, go to comp.lang.python, type "join string" into > the search box, and click on "Search this group". First result is the > current thread; most (or maybe all) of the next six or so will give > you the syntax your were looking for. > > (4) Using Google or any other reasonable web searcher, search for the > 3 words: Python join string. Any one of the first few hits gives the > answer you were seeking. Yes, and also, as last resource, I could always consult an oracle somewhere in the ancient Greece, came back and unsubscribe this NG. :-) You could just type ",".join(L). Look at the time we are loosing! Best regards. Paulo -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
On 25 Mart, 20:16, "Paul Boddie" <[EMAIL PROTECTED]> wrote: > gslm wrote: > > Hi! > > I'm too new on phyton.I have installed phyton.But when I write phyton > > command, unfortunately, i can't run.I suppose that it is bacause of > > setting path.But i can't solve. > > Can you help? > > It's "python" you should be typing, of course. If that doesn't work > then it may be a PATH issue, yes. > > > Another thing is, when i double click the .py file, there are the > > project form and the command line.How can i provide to view only the > > project? > > I think you need to rename the .py file so that it ends with .pyw - > this stops the command line window from opening, but it's only useful > if you are running a graphical program, obviously. > > Paul First, thaks a lot. But I'm sorry.I haven't understood what i must do for ruunnig phyton command.I delete path from proportiesof my computer.Then i open command line of phyton.But when i write phyton these view below: Traceback: File ""; line 1 in NameError: name phyton is not defined Sorry may be you think i'm comic but i am not be able to correct. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
On Mar 24, 11:53 pm, "js " <[EMAIL PROTECTED]> wrote: > The only way you can do is rermove python2.4.4's files manually. > > I suggest you to use MacPorts or Fink. > > With MacPort, you can uninstall python2.4 by doing > $ port uninstall python24 > > And Installation is > $ port install python25 > I try to like MacPorts but sometimes they don't do dependecies very well. For instance, I have a newer version of Ruby installed and I wanted to update a module through MP and it lists Perl5.8 as a dependency and tries to install it. On Tiger, Perl is already at 5.8 so what the hey! It isn't the first time I have been hit with that either. Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Python 2.4.4 on OSX
On Mar 25, 7:08 am, "has" <[EMAIL PROTECTED]> wrote: > On 24 Mar, 18:30, "Robert Hicks" <[EMAIL PROTECTED]> wrote: > > > I want to upgrade to 2.5 but I don't see any unistall instructions > > anywhere. > > To repeat what others have said: don't uninstall existing > Python.framework builds. Frameworks support multiple versions quite > happily, and removing them is more hassle than it's worth. Just > install the official framework build from python.org > (http://www.python.org/ftp/python/2.5/python-2.5-macosx.dmg), which should > also update your shell profiles as necessary. > > HTH > > has Thanks... Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Join strings - very simple Q.
En Sun, 25 Mar 2007 15:31:46 -0300, Paulo da Silva <[EMAIL PROTECTED]> escribió: > John Machin escreveu: >> On Mar 25, 12:32 am, Paulo da Silva <[EMAIL PROTECTED]> wrote: >>> John Machin escreveu: >> [e.g. it's easy to miss the one line in the >> "official" Python tutorial that refers to them] (3) why you were not >> using obvious(?) methods to find out for yourself -- much faster than >> posing a question on the newsgroup, and you don't have to face the >> possibility of an impertinent response :-) > > That's the kind of answer I hate. Of course anyone could find an > answer to any questions without posting them to this NG. But knowing why you didn't follow all those "obvious" paths is valuable - it can be used to improve the documentation, so the next guy doesn't *have* to ask here. > You could just type ",".join(L). > Look at the time we are loosing! It's not a loose at all... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
En Sun, 25 Mar 2007 15:40:14 -0300, gslm <[EMAIL PROTECTED]> escribió: > But I'm sorry.I haven't understood what i must do for ruunnig phyton > command.I delete path from proportiesof my computer.Then i open > command line of phyton.But when i write phyton these view below: > Traceback: > File ""; line 1 in > NameError: name phyton is not defined > Sorry may be you think i'm comic but i am not be able to correct. So, you *already* have started the Python interpreter. You don't have to type any more thing to start! If you see a console like this: Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> you are inside the Python interpreter. You may use IDLE, an integrated editor+debugger+other things (Start menu, All programs, Python, Idle). Or install the Python for Windows extensions, by Mark Hammond, that comes with its own editor (PythonWin) and may be better suited for a Windows environment https://sourceforge.net/projects/pywin32/ Try reading some introductory texts. The book "Dive into Python" may be useful: www.diveintopython.org There is a wiki with more resources: http://wiki.python.org/moin/ -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
On Mar 25, 1:06 pm, "gslm" <[EMAIL PROTECTED]> wrote: > Hi! > I'm too new on phyton.I have installed phyton.But when I write phyton > command, unfortunately, i can't run.I suppose that it is bacause of > setting path.But i can't solve. > Can you help? You need to set what is called your PATH environment variable. See: http://www.computerhope.com/issues/ch000549.htm and add C:\python\ (or wherever your python package is installed) to your PATH. > > Another thing is, when i double click the .py file, there are the > project form and the command line.How can i provide to view only the > project? I don't quite understand what you're asking here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interactive session, alternating prompt. readline? curses?
En Sun, 25 Mar 2007 14:04:09 -0300, Berend van Berkum <[EMAIL PROTECTED]> escribió: > I'm looking at building an interactive session in front of some > rdfobj instances. I've used cmd and just found code.Interactive*. > > However, my question, can I change the "prompt" string in respond > to user input using readline? AFAIK I'll need curses to do this? > And colored prompts? I've never used code.Interactive* and it looks like it interprets Python code, not arbitrary code. Using cmd, you can set the prompt attribute. For colors, I think you may need curses or ncurses or similar... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
gslm schrieb: > First, thaks a lot. > But I'm sorry.I haven't understood what i must do for ruunnig phyton > command.I delete path from proportiesof my computer.Then i open > command line of phyton.But when i write phyton these view below: > Traceback: > File ""; line 1 in > NameError: name phyton is not defined Such an answer comes from Python, I think you must already be in the interactive interpreter. Do you see something similar to this, with your cursor after the ">>>"? Python 2.5 (r25:51908, Oct 6 2006, 15:22:41) [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> At this point you can enter valid Python statements, but you can't call Python from Python (wouldn't make sense anyway). I'd look at this page first: http://www.python.org/about/gettingstarted/ HTH Hertha -- http://mail.python.org/mailman/listinfo/python-list
Save time processing netcdf
Hello,
I am working with a netcdf file and trying to remove a long string
from it e.g.
"KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH DATA
BLAH DATA BLAH"
Right now what I have works, but takes a long time to run... I think
this could be cut down to a quick 2 second run, but now takes around 5
minutes primarily because of the problem described below...
Why can't I use something like line 9 to get the entire string (which
returns [0], not
["KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH
DATA BLAH DATA BLAH"])? Rather I have to loop through it grabbing one
character at a time which drastically increases the processing time
and is very cumbersome.
Any one have any ideas or suggestions?
0 #OPEN NetCDF FILE TO READ
1 allDimNames=file.dimensions.keys()
2 max_string_length=file.dimensions['maxstringLen']
3 variableNames=file.variables.keys()
4 globalAttList=dir(file)
5 globalAttValue=getattr(file,'filePeriod')
6
7#GRABS DATA FROM STRING (2 DIMENSIONAL ARRAY) WITH THE CHARACTERS AS
INDIVIDUAL 8ELEMENTS
9 #YOU CAN'T JUST SPECIFY DATA VALUES
DATA[0][0:max_string_length]
10 data=file.variables['rawstring'].getValue()
11 num_stations=data.shape
12 station_id=[str(mz)]
13
14 for m in station_id:
15 station_id=m
16 prec=[]
17 temps=[]
18
19 #Cycles through all of the stations in the file
(LARGE ARRAY!!)
20 for k in range(num_stations[0]):
21 #Finds a certain station
22 if data[k][6]=='K' and
data[k][7]==station_id[0:1] and data[k]
[8]==station_id[1:2] and 23data[k][9]==station_id[2:3] and data[k]
[15]=='5' or data[k][6]=='K' and data[k][7]==station_id[0:1] and
24data[k][8]==station_id[1:2] and data[k][9]==station_id[2:3] and
data[k][15]=='4':
25
26 #SEPARATES STRING
CHARACTER BY CHARACTER ONLY WAY I'VE 27BEEN
ABLE TO FIGURE OUT HOW TO READ ENTIRE STRING INTO A STRING
28 for j in
range(max_string_length):
29
prec.append(str(data[k][j]))
30 S= ''.join(prec)
31 # # # ##THEN RIP OFF THE
WHITESPACE AT THE RIGHT OF THE
STRING
32 code=S.rstrip("\0")
33
Thanks for any of your help!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Returned mail: see transcript for details (1174853648)
--|||-- Request Management System - Time Inc. --- To confirm this message was intended to be created as a request in the Internet Technology Group's Request Management System, please reply to this message and type '/OK' (without the quotes) as the text of your message. Do not retype your request and feel free to delete the rest of this text from your reply. --- If the Request Management System does not receive your ack- knowledgement within 24 hours, your original request will be terminated, thus requiring resubmission of the request. --- -- http://mail.python.org/mailman/listinfo/python-list
Re: functions, classes, bound, unbound?
En Sun, 25 Mar 2007 17:22:36 -0300, 7stud <[EMAIL PROTECTED]> escribió: > On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: >> On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: >> >> > Is there some other way to retrieve a user-defined function object >> > from a class other than using the class name or an instance? >> >> What Steven B. already said, MyClass.__dict__['someFunc'], is a >> different way than MyClass.someFunc that produces different results. > > methObj = Test.__dict__["greet"] > print methObj.im_self > > Traceback (most recent call last): > File "test1.py", line 7, in ? > print methObj.im_self > AttributeError: 'function' object has no attribute 'im_self' Because this way, you get a function, not a method. I'd say "read something about descriptors" but... Nicolas Bourbaki [a collective of french mathematicians writing under that alias] said on a book about set theory: Any school boy can understand all of this with a minimum of effort, but for truly understanding what we are talking about, around four years of prior training on mathematics may be required. (I can't find the exact citation). I suggest first learn to use Python and then try to understand how it does what it does, along the way, and looking for answers when you have a question. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: functions, classes, bound, unbound?
On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: > On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > > > MyClass.someFunc > > > Is there some other way to retrieve a user-defined function object > > from a class other than using the class name or an instance? > > What Steven B. already said, MyClass.__dict__['someFunc'], is a > different way than MyClass.someFunc that produces different results. That doesn't seem to fit what GvR was talking about. From this example: class Test(object): def greet(): print "Hello" methObj = Test.__dict__["greet"] print methObj.im_self I get this output: Traceback (most recent call last): File "test1.py", line 7, in ? print methObj.im_self AttributeError: 'function' object has no attribute 'im_self' So it doesn't look like a method object gets created when you retrieve a function from a class like that. Compare to: class Test(object): def greet(): print "Hello" methObj = Test.greet print methObj.im_self output: None > Since the method is an attribute of a class, what other kinds of means > are you expecting to be possible? > I'm just wondering why in this description: When a user-defined method object is created by retrieving a user- defined function object from a class, its im_self attribute is None and the method object is said to be unbound. When one is created by retrieving a user-defined function object from a class via one of its instances, its im_self attribute is the instance, and the method object is said to be bound. - GvR didn't explicitly mention using the class name to retrieve the function object in the first sentence. It seems to imply there are other ways to retrieve the function object from the class that cause a method object to be created. -- http://mail.python.org/mailman/listinfo/python-list
Re: functions, classes, bound, unbound?
On Mar 25, 9:13 am, "7stud" <[EMAIL PROTECTED]> wrote: > Is there some other way to retrieve a user-defined function object > from a class other than using the class name or an instance? On Mar 25, 3:00 am, [EMAIL PROTECTED] wrote: > What Steven B. already said, MyClass.__dict__['someFunc'], is a > different way than MyClass.someFunc that produces different results. 7stud wrote: > That doesn't seem to fit what GvR was talking about. From this > example: > > class Test(object): > def greet(): > print "Hello" > > methObj = Test.__dict__["greet"] > print methObj.im_self > > I get this output: > > Traceback (most recent call last): > File "test1.py", line 7, in ? > print methObj.im_self > AttributeError: 'function' object has no attribute 'im_self' Yep. The thing in the class __dict__ is the original *function*. The thing you get from something like ``Test.greet`` is the *method*. Here's another way of looking at it:: >>> class Test(object): ... pass ... >>> def greet(): ... print 'Hello' ... >>> greet >>> Test.greet = greet >>> Test.__dict__['greet'] >>> Test.__dict__['greet'] is greet True Note that ``Test.__dict__['greet']`` is the ``greet`` *function*, not some wrapper of that function. When you access the class attribute normally, Python creates an 'unbound method' object:: >>> Test.greet >>> Test.greet is greet False >>> Test.greet.im_func >>> Test.greet.im_func is greet True See that ``Test.greet`` gives you an 'unbound method' object which just wraps the real 'function' object (which is stored as the 'im_func' attribute)? That's because under the covers, classes are actually using doing something like this:: >>> Test.__dict__['greet'].__get__(None, Test) >>> Test.greet == Test.__dict__['greet'].__get__(None, Test) True So if you want to get a method from a function, you can always do that manually yourself:: >>> greet.__get__(None, Test) Hope that helps, STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Multi-line strings with formatting
Steven D'Aprano wrote: > On Fri, 23 Mar 2007 19:39:53 -0700, Paul McGuire wrote: > >> (and I'm glad I'm not the only one who uses 'l' for a scratch list >> variable...) > > Yes, and come the revolution, every last one of you will be down the salt > mines. > Better that than up against the wall, I suppose. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
Please, can you read again? Yes, I understand that in phyton interpreter, i can't call phyton command.Thanks... But how can i run '.py' files from this command line?I wanted to use the phyton command for this. When i click a py extended file, for example calendar.py in lib directory, file opens, then suddenly close,except graphical ones.Why? How can i see the results? And where can i learn which library must i import for whic class? Sorry, i ask much:(But after learning these starting knowledeges, i read tutorials, manuals etc. But now i haven't found my answers yet. Regards... -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
On Mar 25, 6:23 pm, "gslm" <[EMAIL PROTECTED]> wrote: > Please, can you read again? > Yes, I understand that in phyton interpreter, i can't call phyton > command.Thanks... > > But how can i run '.py' files from this command line?I wanted to use > the phyton command for this. > > When i click a py extended file, for example calendar.py in lib > directory, file opens, then suddenly close,except graphical ones.Why? > How can i see the results? > > And where can i learn which library must i import for whic class? > > Sorry, i ask much:(But after learning these starting knowledeges, i > read tutorials, manuals etc. > But now i haven't found my answers yet. > Regards... For god's sake. It's PYTHON, not PHYTON. Use IDLE and run your files from there. That way you won't have to mess with the hideous windows console. However, if you really want to use the windows console, keep in mind that it will always close automatically when the program ends. That is true for Python, C, whatever, unless it was open before. So, Start- >run, type "cmd" then run python filename.py. If that does not work, it's because the path is not set correctly. And that's probably because you keep mispelling Python. See below: " But I'm sorry.I haven't understood what i must do for ruunnig phyton command.I delete path from proportiesof my computer.Then i open command line of phyton.But when i write phyton these view below: Traceback: File ""; line 1 in NameError: name phyton is not defined " ^^^ Obviously, "Phyton" will never be defined. Stephen -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
gslm wrote: > Please, can you read again? > Yes, I understand that in phyton interpreter, i can't call phyton > command.Thanks... > > But how can i run '.py' files from this command line?I wanted to use > the phyton command for this. > > When i click a py extended file, for example calendar.py in lib > directory, file opens, then suddenly close,except graphical ones.Why? > How can i see the results? > > And where can i learn which library must i import for whic class? > > Sorry, i ask much:(But after learning these starting knowledeges, i > read tutorials, manuals etc. > But now i haven't found my answers yet. > Regards... > http://www.python.org/doc/faq/windows.html#how-do-i-run-a-python-program-under-windows regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: problem at installing phyton on windows
gslm wrote:
> Please, can you read again?
> Yes, I understand that in phyton interpreter, i can't call phyton
> command.Thanks...
>
> But how can i run '.py' files from this command line?I wanted to use
> the phyton command for this.
Once you are in the Python interpreter you can run Python files, but
the best way to run files is one of the following:
* From the command prompt (DOS prompt); type something like this:
python file.py
* In the file manager (Windows Explorer, not Internet Explorer), open/
run file.py.
If you *really* want to run files in the interpreter, you can do
something like this:
execfile("file.py")
> When i click a py extended file, for example calendar.py in lib
> directory, file opens, then suddenly close,except graphical ones.Why?
> How can i see the results?
For things that don't open windows you really need to run them from
the command prompt.
> And where can i learn which library must i import for whic class?
Look at the library reference: each of the listed libraries are named,
and for the calendar module you'd put this in your program (or type it
at the Python prompt):
import calendar
Note that in Python programs or at the Python prompt you do not refer
to it as calendar.py or C:\Python24\Lib\calendar.py (or wherever it
lives): Python knows where to look and knows to add the .py on the end
of the file.
Note also that this doesn't run the calendar module, so it isn't quite
the same as running the calendar.py file as described above.
> Sorry, i ask much:(But after learning these starting knowledeges, i
> read tutorials, manuals etc.
> But now i haven't found my answers yet.
I hope this helps a little.
Paul
--
http://mail.python.org/mailman/listinfo/python-list
Re: a calendar example
On Sun, 25 Mar 2007 11:09:54 -0700, gslm wrote: > Hi! > I want to do a calendar where pictures on.Can you have any free > example like this which can help me ? > Regards... These websites can help you: http://search.yahoo.com/ http://www.google.com/ -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: A better webpage filter
Anton Vredegoor <[EMAIL PROTECTED]> writes: [...] > Most web pages I visit lately are taking so much room for ads (even > with adblocker installed) that the mere 20 columns of text that are > available for reading are slowing me down unacceptably. I have tried [...] http://webcleaner.sourceforge.net/ Not actually tried it myself, though did browse some of the code once or twice -- does some clever stuff. Lots of other Python-implemented HTTP proxies, some of which are relevant (though AFAIK all less sophisticated than webcleaner), are listed on Alan Kennedy's nice page here: http://xhaus.com/alan/python/proxies.html A surprising amount of diversity there. John -- http://mail.python.org/mailman/listinfo/python-list
EuroPython 2007: Call for Proposals
Book Monday 9th July to Wednesday 11th July 2007 in your calendar! EuroPython 2007, the European Python and Zope Conference, will be held in Vilnius, Lithuania. Last year's conference was a great success, featuring a variety of tracks, amazing lightning talks and inspiring keynotes. With your participation, we want to make EuroPython 2007, the sixth EuroPython, even more successful than the previous five. Talks, Papers and Themes This year we have decided to borrow a few good ideas from PyCon, one of which is to move away from the 'track' structure. Instead, speakers are invited to submit presentations about anything they have done that they think would be of interest to the Python community. We will then arrange them into related groups and schedule them in the space available. In the past, EuroPython participants have found the following themes to be of interest: * Science * Python Language and Libraries * Web Related Technologies * Education * Games * Agile Methodologies and Testing * Social Skills In addition to talks, we will also accept full paper submissions about any of the above themes. The Call for Refereed Papers will be posted shortly. The deadline for talk proposals is Friday 18th May at midnight (24:00 CEST, Central European Summer Time, UTC+2). Other ways to participate - Apart from giving talks, there are plenty of other ways to participate in the conference. Just attending and talking to people you find here can be satisfying enough, but there are three other kinds of activity you may wish to plan for: Lightning Talks, Open Space and Sprints. Lightning Talks are very short talks that give you just enough time to introduce a topic or project, Open Space is an area reserved for informal discussions, and Sprints are focused gatherings for developers interested in particular projects. For more information please see the following pages: * Lightning Talks: http://www.europython.org/sections/events/lightning_talks * Open Space: http://www.europython.org/sections/events/open_space * Sprints: http://www.europython.org/sections/sprints_and_wiki Your Contribution - To propose a talk or a paper, go to... * http://www.europython.org/submit For more general information on the conference, please visit... * http://www.europython.org/ Looking forward to seeing what you fine folk have been up to, The EuroPython Team -- http://mail.python.org/mailman/listinfo/python-list
call to function by text variable
yeah the subject doesn't really make sense does it? anyway want I want to do is this: if n == 1: self.operations.insert(pos, operations.Replace.Panel(self, main)) elif n == 2: self.operations.insert(pos, operations.ChangeCase.Panel(self, main)) elif n == 3: self.operations.insert(pos, operations.Move.Panel(self, main)) As you can see all the different functions have the same variables, so it would be easier if I could just make a list and use that. like this: list = ["Replace", "ChangeCase", "Move"] textVariable = list[n] self.operations.insert(pos, operations.[textVariable].Panel(self, main)) Is something sort of like that possible? TIA -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
Great, thanks so much for posting that. It's worked a treat and I'm
getting HTML files with the list of h2 tags I was looking for. Here's
the code just to share, what a relief :) :
...
from BeautifulSoup import BeautifulSoup
import re
page = open("soup_test/tomatoandcream.html", 'r')
soup = BeautifulSoup(page)
myTagSearch = str(soup.findAll('h2'))
myFile = open('Soup_Results.html', 'w')
myFile.write(myTagSearch)
myFile.close()
del myTagSearch
...
I do have two other small queries that I wonder if anyone can help
with.
Firstly, I'm getting the following character: "[" at the start, "]" at
the end of the code. Along with "," in between each tag line listing.
This seems like normal behaviour but I can't find the way to strip
them out.
There's an example of stripping comments and I understand the example,
but what's the *reference* to the above '[', ']' and ',' elements?
for the comma I tried:
soup.find(text=",").replaceWith("")
but that throws this error:
AttributeError: 'NoneType' object has no attribute 'replaceWith'
Again working with the 'Removing Elements' example I tried:
soup = BeautifulSoup("you are a banana, banana, banana")
a = str(",")
comments = soup.findAll(text=",")
[",".extract() for "," in comments]
But if I'm doing 'import beautifulSoup' this give me a "soup =
BeautifulSoup("you are a banana, banana, banana")
TypeError: 'module' object is not callable" error, "import
beautifulSoup from BeautifulSoup" does nothing
Secondly, in the above working code that is just pulling the h2 tags -
how the blazes do I 'prettify' before writing to the file?
Thanks in advance!
Mark.
..
On Mar 25, 6:51 pm, Jorge Godoy <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] writes:
> > Hi All,
>
> > Apologies for the newbie question but I've searched and tried all
> > sorts for a few days and I'm pulling my hair out ;[
>
> > I have a 'reference' HTML file and a 'test' HTML file from which I
> > need to pull 10 strings, all of which are contained within tags,
> > e.g.:
> > http://www.someplace.com/";>Go Someplace
>
> > Once I've found the 10 I'd like to write them to another 'results'
> > html file. Perhaps a 'reference results' and a 'test results' file.
> >>From where I would then like to 'diff' the results to see if they
> > match.
>
> > Here's the rub: I cannot find a way to pull those 10 strings so I can
> > save them to the results pages.
> > Can anyone please suggest how this can be done?
>
> > I've tried allsorts but I've been learning Python for 1 week and just
> > don't know enough to mod example scripts it seems. don't even get me
> > started on python docs.. ayaa ;] Please feel free to teach me to suck
> > eggs because it's all new to me :)
>
> > Thanks in advance,
>
> > Mark.
>
> Take a look at BeautifulSoup. It is easy to use and works well with some
> malformed HTML that you might find ahead.
>
> --
> Jorge Godoy <[EMAIL PROTECTED]>- Hide quoted text -
>
> - Show quoted text -
--
http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
ianaré wrote: > yeah the subject doesn't really make sense does it? > > anyway want I want to do is this: > if n == 1: > > self.operations.insert(pos, operations.Replace.Panel(self, main)) > > elif n == 2: > > self.operations.insert(pos, operations.ChangeCase.Panel(self, > main)) > > elif n == 3: > > self.operations.insert(pos, operations.Move.Panel(self, main)) > > As you can see all the different functions have the same variables, so > it would be easier if I could just make a list and use that. > > like this: > > > list = ["Replace", "ChangeCase", "Move"] > textVariable = list[n] > self.operations.insert(pos, operations.[textVariable].Panel(self, > main)) > > Is something sort of like that possible? > Indeed. You don't need to use textual names (though for that you can investigate "getattr()) - the following, naturally, is untested: ops = [operations.Replace, operations.ChangeCase, operations.Move ] self.operations.insert(pos, ops[n-1].Panel(self, main) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
ianaré wrote: > like this: > > > list = ["Replace", "ChangeCase", "Move"] > textVariable = list[n] > self.operations.insert(pos, operations.[textVariable].Panel(self, > main)) > > Is something sort of like that possible? Yes: self.operations.insert( pos, getattr(operations, textVariable).Panel(self.main) ) -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
En Sun, 25 Mar 2007 19:36:26 -0300, ianaré <[EMAIL PROTECTED]> escribió: > list = ["Replace", "ChangeCase", "Move"] > textVariable = list[n] > self.operations.insert(pos, operations.[textVariable].Panel(self, > main)) > > Is something sort of like that possible? Try getattr: textVariable = "Replace" getattr(operations, textVariable) == operations.Replace Perhaps you could just store the result in your list; instead of ["Replace", "ChangeCase", "Move"], use [operations.Replace, operations.ChangeCase, operations.Move] (it's not always applicable, of course: maybe operations is reassigned, or those attributes mutate or don't always exist...) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
On Mar 25, 3:36 pm, "ianaré" <[EMAIL PROTECTED]> wrote: > yeah the subject doesn't really make sense does it? > > anyway want I want to do is this: > if n == 1: > > self.operations.insert(pos, operations.Replace.Panel(self, main)) > > elif n == 2: > > self.operations.insert(pos, operations.ChangeCase.Panel(self, > main)) > > elif n == 3: > > self.operations.insert(pos, operations.Move.Panel(self, main)) > > As you can see all the different functions have the same variables, so > it would be easier if I could just make a list and use that. > # Your list would contain the unbound functions: unbound_funcs = [operations.Replace.Panel, operations.Change.Panel, operations.Move.Panel] # and invocation would be: self.operations.insert(pos, unbound_funcs[n - 1](self, main)) -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Join strings - very simple Q. ERRATA
Paulo da Silva escreveu: > John Machin escreveu: >> On Mar 25, 12:32 am, Paulo da Silva <[EMAIL PROTECTED]> wrote: >>> John Machin escreveu: > ... ... > knowledge. If you feel that it is a question that deserves the > honour of your response, just do it. Write it on the stones and > send them down to the common people :-) . ... Should be read *ordinary* people. This is an error caused by language differeneces where comum (pt) is ordinary (en) and ordinario (pt relatively ofensive term) is common (en). ... > > Yes, and also, as last resource, I could always consult an oracle > somewhere in the ancient Greece, *come* back and unsubscribe this NG. :-) > Regards. Paulo -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
Hi, try this: func = getattr(operations, ["Replace", "ChangeCase", "Move"][n]) HTH, Jan "ianaré" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] > yeah the subject doesn't really make sense does it? > > anyway want I want to do is this: > if n == 1: > >self.operations.insert(pos, operations.Replace.Panel(self, main)) > > elif n == 2: > >self.operations.insert(pos, operations.ChangeCase.Panel(self, > main)) > > elif n == 3: > >self.operations.insert(pos, operations.Move.Panel(self, main)) > > As you can see all the different functions have the same variables, so > it would be easier if I could just make a list and use that. > > like this: > > > list = ["Replace", "ChangeCase", "Move"] > textVariable = list[n] > self.operations.insert(pos, operations.[textVariable].Panel(self, > main)) > > Is something sort of like that possible? > > > TIA > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
Cool now I can run it through the translator.
ops = (_("Directory"), _("Replace"), _("ChangeCase"),
_("Move"), _("Swap"), _("Insert"), _("ChangeLength"))
self.operations.insert(pos, getattr(operations, ops[n]).Panel(self,
main))
Thanks guys!
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
En Sun, 25 Mar 2007 19:44:17 -0300, <[EMAIL PROTECTED]> escribió:
> from BeautifulSoup import BeautifulSoup
> import re
>
> page = open("soup_test/tomatoandcream.html", 'r')
> soup = BeautifulSoup(page)
>
> myTagSearch = str(soup.findAll('h2'))
>
> myFile = open('Soup_Results.html', 'w')
> myFile.write(myTagSearch)
> myFile.close()
>
> del myTagSearch
> ...
>
> Firstly, I'm getting the following character: "[" at the start, "]" at
> the end of the code. Along with "," in between each tag line listing.
> This seems like normal behaviour but I can't find the way to strip
> them out.
findAll() returns a list. You convert the list to its string
representation, using str(...), and that's the way lists look like: with
[] around, and commas separating elements. If you don't like that, don't
use str(some_list).
Do you like an item by line? Use "\n".join(myTagSearch) (remember to strip
the str() around findAll)
Do you like comma separated items? Use ",".join(myTagSearch)
Read about lists here http://docs.python.org/lib/typesseq.html and strings
here http://docs.python.org/lib/string-methods.html
For the remaining questions, I strongly suggest reading the Python
Tutorial (or any other book like Dive into Python). You should grasp some
basic knowledge of the language at least, before trying to use other tools
like BeautifulSoup; it's too much for a single step.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
On Mar 25, 7:01 pm, "ianaré" <[EMAIL PROTECTED]> wrote:
> Cool now I can run it through the translator.
>
> ops = (_("Directory"), _("Replace"), _("ChangeCase"),
>_("Move"), _("Swap"), _("Insert"), _("ChangeLength"))
>
> self.operations.insert(pos, getattr(operations, ops[n]).Panel(self,
> main))
>
> Thanks guys!
erm ... brainfart LOL. But now I can link it to the translated list.
--
http://mail.python.org/mailman/listinfo/python-list
XML minidom Parsing and ToPrettyXML
I am trying to write a script that reads an XML file (using the minidom module), makes an edit to a few attributes, then saves it back. If I use minidom.Document() to create the xml file, then write it with toprettyprint, it looks fine. However, if I use xml.minidom.parse to parse the xml document, change a few attributes with setAttribute, then write back with toprettyxml, my XML file gets loaded up with spaces between many of the elements. Like this, I assume this has to do with the way xml.dom.minidom.parse parses the file, because it will even do this without changing any attributes. This whitespace damages readability, and bloats up the file. Anyone know of a way to make the file look as it should, hopefully in a pythonic way? -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner GTK question
On 2007-03-25, dashawn888 <[EMAIL PROTECTED]> wrote:
> gui.py:79: GtkWarning: Quit: missing action
> menubar = uimanager.get_widget('/MenuBar')
>
This should probably be action="Quit".
Dave Cook
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
Yep, I agree! once I've got this done I'll be back to trawling the
tutorials.
Life never gives you the convenience of learning something fully
before having to apply what you have learnt ;]
Thanks for the feedback and links, I'll be sure to check those out.
Mark.
On Mar 26, 12:05 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sun, 25 Mar 2007 19:44:17 -0300, <[EMAIL PROTECTED]> escribió:
>
>
>
>
>
> > from BeautifulSoup import BeautifulSoup
> > import re
>
> > page = open("soup_test/tomatoandcream.html", 'r')
> > soup = BeautifulSoup(page)
>
> > myTagSearch = str(soup.findAll('h2'))
>
> > myFile = open('Soup_Results.html', 'w')
> > myFile.write(myTagSearch)
> > myFile.close()
>
> > del myTagSearch
> > ...
>
> > Firstly, I'm getting the following character: "[" at the start, "]" at
> > the end of the code. Along with "," in between each tag line listing.
> > This seems like normal behaviour but I can't find the way to strip
> > them out.
>
> findAll() returns a list. You convert the list to its string
> representation, using str(...), and that's the way lists look like: with
> [] around, and commas separating elements. If you don't like that, don't
> use str(some_list).
> Do you like an item by line? Use "\n".join(myTagSearch) (remember to strip
> the str() around findAll)
> Do you like comma separated items? Use ",".join(myTagSearch)
> Read about lists herehttp://docs.python.org/lib/typesseq.htmland strings
> herehttp://docs.python.org/lib/string-methods.html
>
> For the remaining questions, I strongly suggest reading the Python
> Tutorial (or any other book like Dive into Python). You should grasp some
> basic knowledge of the language at least, before trying to use other tools
> like BeautifulSoup; it's too much for a single step.
>
> --
> Gabriel Genellina- Hide quoted text -
>
> - Show quoted text -
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
[EMAIL PROTECTED] wrote:
> Great, thanks so much for posting that. It's worked a treat and I'm
> getting HTML files with the list of h2 tags I was looking for. Here's
> the code just to share, what a relief :) :
> ...
> from BeautifulSoup import BeautifulSoup
> import re
>
> page = open("soup_test/tomatoandcream.html", 'r')
> soup = BeautifulSoup(page)
>
> myTagSearch = str(soup.findAll('h2'))
>
> myFile = open('Soup_Results.html', 'w')
> myFile.write(myTagSearch)
> myFile.close()
>
> del myTagSearch
> ...
>
> I do have two other small queries that I wonder if anyone can help
> with.
>
> Firstly, I'm getting the following character: "[" at the start, "]" at
> the end of the code. Along with "," in between each tag line listing.
> This seems like normal behaviour but I can't find the way to strip
> them out.
Ah. What you want is more like this:
page = open("soup_test/tomatoandcream.html", 'r')
soup = BeautifulSoup(page)
htags = soup.findAll({'h2':True, 'H2' : True}) # get all H2 tags, both cases
myFile = open('Soup_Results.html', 'w')
for htag in htags : # for each H2 tag
texts = htag.findAll(text=True) # find all text items within this h2
s = ' '.join(texts).strip()+ '\n' # combine text items into clean
string
myFile.write(s) # write each text from an H2 element on a line.
myFile.close()
John Nagle
--
http://mail.python.org/mailman/listinfo/python-list
Re: XML minidom Parsing and ToPrettyXML
Paul Kozik wrote: > However, if I use xml.minidom.parse to parse the xml document, change > a few attributes with setAttribute, then write back with toprettyxml, > my XML file gets loaded up with spaces between many of the elements. Use 'toxml' method, that writes XML document without any modification. w. -- http://mail.python.org/mailman/listinfo/python-list
replacing one instance with another
Hi,
I'm not sure why this doesn't work:
>>>dic_myinstances={}
>>>class MyClass(object):
def __init__(self, id):
global dic_myinstances
if dic_myinstances.has_key(id):
self = dic_myinstances[id]
else:
dic_myinstances[id] = self
>>>ins1 = MyClass('xx')
>>>ins2 = MyClass('yy')
>>>ins3 = MyClass('xx')
>>>ins3 is ins1
False
Why isn't ins3 the same as ins1? How can I get this to work?
thanks
--
http://mail.python.org/mailman/listinfo/python-list
Re: replacing one instance with another
Hi,
I solved it myself! I realised that __new__ creates self prior to
init, so this works:
>>>dic_myinstances={}
>>>class MyClass(object):
def __new__(self,id):
global dic_myinstances
if dic_myinstances.has_key(id):
return dic_myinstances[id]
else:
dic_myinstances[id] = self
return self
>>>ins1 = MyClass('xx')
>>>ins2 = MyClass('yy')
>>>ins3 = MyClass('xx')
>>>print ins3 is ins1
True
Is this the best way to do this?
--
http://mail.python.org/mailman/listinfo/python-list
Re: replacing one instance with another
Hi, yet again to myself!
I've realised after further testing and reading that I actually need
to do this:
>>>dic_myinstances={}
>>>class MyClass(object):
def __new__(cls,id):
global dic_myinstances
if dic_myinstances.has_key(id):
return dic_myinstances[id]
else:
dic_myinstances[id] = super(MyClass, cls).__new__(cls, id)
return dic_myinstances[id]
def __init__(self,id):
print id
>>>ins1 = MyClass('xx')
'xx'
>>>ins2 = MyClass('yy')
'yy'
>>>ins3 = MyClass('xx')
'xx'
>>>ins3 is ins1
True
--
http://mail.python.org/mailman/listinfo/python-list
Re: replacing one instance with another
En Sun, 25 Mar 2007 23:34:51 -0300, manstey <[EMAIL PROTECTED]> escribió:
> I've realised after further testing and reading that I actually need
> to do this:
>
dic_myinstances={}
class MyClass(object):
> def __new__(cls,id):
> global dic_myinstances
> if dic_myinstances.has_key(id):
> return dic_myinstances[id]
> else:
> dic_myinstances[id] = super(MyClass, cls).__new__(cls, id)
> return dic_myinstances[id]
> def __init__(self,id):
> print id
>
ins1 = MyClass('xx')
> 'xx'
ins2 = MyClass('yy')
> 'yy'
ins3 = MyClass('xx')
> 'xx'
ins3 is ins1
> True
That's fine, but notice that __init__ is called even if the instance
already exists. That's usually undesirable, and you can use a factory
function instead:
def MyClassFactory(id):
inst = dic_myinstances.get(id)
if inst is None:
dic_myinstances[id] = inst = MyClass(id)
return inst
(Notice that no global statement is needed, even on your __new__)
You can make it a static method if you wish.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: organizing collections of small modules
Jorge Godoy wrote: > "Eric S. Johansson" <[EMAIL PROTECTED]> writes: > >> I have a bunch of small modules that I use within my application. Most of >> these modules are single file modules. Currently, I have them set up as >> stand-alone modules but because it's a royal pain to fetch five or 10 of >> these >> modules for each application and tracking whether or not they are all up to >> date, I'm considering putting them all into one collection (rcsoc >> a.k.a. random cross-section of code[1]) so it's easier to load, install, and >> manage. >> >> Are there better techniques for managing collections of modules in 2.4 or >> later? >> >> ---eric >> >> >> [1] derives from the expression that hamburger is "random cross-section of >> cow" > > I'm using setuptools for that. If they're somehow connected -- > e.g. mathematics, database, finance, etc. -- then I create one single package > for them. If they aren't, then creating several packages isn't hard. I already have working setup.py files and the docs indicates that it should be a 1 liner to convert from distutils. > If they are useful enough you can publish them on PyPI and then it is just a > matter of "easy_install" them. If they aren't then you'll have to collect > them somewhere to use easy_install ;-) I think a couple should be generaly useful (file system based queue, union configuration files). when it all works, I'll publish. > > It also supplies means to determine the minimum / maximum / exact version that > is required, so this also helps with how up-to-date your library has to be to > be used with some application. a big win IMO -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
In article <[EMAIL PROTECTED]>,
Jan Schilleman <[EMAIL PROTECTED]> wrote:
>Hi,
>
>try this:
>func = getattr(operations, ["Replace", "ChangeCase", "Move"][n])
>
>HTH,
>Jan
>
>"ianaré" <[EMAIL PROTECTED]> schreef in bericht
>news:[EMAIL PROTECTED]
>> yeah the subject doesn't really make sense does it?
>>
>> anyway want I want to do is this:
>> if n == 1:
>>
>>self.operations.insert(pos, operations.Replace.Panel(self, main))
.
.
.
I think you meant "...[n - 1]" rather than "...[n]".
I'm a tiny bit surprised no one has organized this in terms
of a dictionary. I don't know, of course, how robust is the
characterization of n as a small integer. Maybe
lookup_table = {
0: "Replace",
1: "ChangeCase",
2: "Move"}
captures the sentiment; maybe something else does it better.
--
http://mail.python.org/mailman/listinfo/python-list
ANN: Urwid 0.9.8 - Console UI Library
Announcing Urwid 0.9.8 -- Urwid home page: http://excess.org/urwid/ Tarball: http://excess.org/urwid/urwid-0.9.8.tar.gz About this release: === This release improves Urwid's performance by 70% to 450% (reducing running time by 41% to 82%)[1] for some benchmarks[2]. New base classes have been introduced for widgets, canvases and list walkers. Some bugs have been fixed. Python 2.2 or later is now required. There were three major changes that contributed to the performance improvement in this release. The Canvas class was rewritten so that canvases can be combined more efficiently. Canvas objects are now cached so that most unchanged widgets will not need to re-render themselves. There is a new C module for some of the heavily used low-level string functions contributed by Rebecca Breu. Urwid's raw_display module may now be used with libraries like Twisted that have their own event loops. Use the new get_input_descriptors() and get_input_nonblocking() methods instead of get_input() when using an external event loop. While I have tried to maintain compatibility with older versions of Urwid, some of the changes in this release may affect existing code. Please report any problems you have to the mailing list or the IRC channel. [1] http://article.gmane.org/gmane.comp.lib.urwid/415 [2] http://excess.org/urwid/browser/contrib/trunk New in this release: * Rendering is now significantly faster. * New Widget base class for all widgets. It includes automatic caching of rows() and render() methods. It also adds a new __super attribute for accessing methods in superclasses. Widgets must now call self._invalidate() to notify the cache when their content has changed. To disable caching in a widget set the class variable no_cache to a list that includes the string "render". * Canvas classes have been reorganized: Canvas has been renamed to TextCanvas and Canvas is now the base class for all canvases. New canvas classes include BlankCanvas, SolidCanvas and CompositeCanvas. * External event loops may now be used with the raw_display module. The new methods get_input_descriptors() and get_input_nonblocking() should be used instead of get_input() to allow input processing without blocking. * The Columns, Pile and ListBox widgets now choose their first selectable child widget as the focus widget by defaut. * New ListWalker base class for list walker classes. * New Signals class that will be used to improve the existing event callbacks. Currently it is used for ListWalker objects to notify their ListBox when their content has changed. * SimpleListWalker now behaves as a list and supports all list operations. This class now detects when changes are made to the list and notifies the ListBox object. New code should use this class to wrap lists of widgets before passing them to the ListBox constructor. * New PollingListWalker class is now the default list walker that is used when passing a simple list to the ListBox constructor. This class is intended for backwards compatibility only. When this class is used the ListBox object is unable to cache its render() method. * The curses_display module can now draw in the lower-right corner of the screen. * All display modules now have start() and stop() methods that may be used instead of calling run_wrapper(). * The raw_display module now uses an alternate buffer so that the original screen can be restored on exit. The old behaviour is available by seting the alternate_buffer parameter of start() or run_wrapper() to False. * Many internal string processing functions have been rewritten in C to improve their performance. * Compatible with Python >= 2.2. Python 2.1 is no longer supported. About Urwid === Urwid is a console UI library for Python. It features fluid interface resizing, UTF-8 support, multiple text layouts, simple attribute markup, powerful scrolling list boxes and flexible interface design. Urwid is released under the GNU LGPL. -- http://mail.python.org/mailman/listinfo/python-list
__init__.py
When looking at other peoples code (to learn from it) I keep seeing an empty file named "__init__.py". What's the purpose of this? Thanks Tina -- http://mail.python.org/mailman/listinfo/python-list
Re: __init__.py
Tina I wrote: > When looking at other peoples code (to learn from it) I keep seeing an > empty file named "__init__.py". What's the purpose of this? > > Thanks > Tina Duh! Never mind... found it. Kinda neat actually :) T -- http://mail.python.org/mailman/listinfo/python-list
Sending ECHO_REQUEST (pinging) with python
Hi, I've writing a python application in which I'd like to have a small "ping label", to always tell the current ping time to the server. It seems however that I have to be root to send those imcp packages, but I guess there must be a workaround since I can easily use the "ping" command as ordinary user. Do anybody know how to do this in python? -- http://mail.python.org/mailman/listinfo/python-list
Re: call to function by text variable
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Jan Schilleman <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> try this:
>> func = getattr(operations, ["Replace", "ChangeCase", "Move"][n])
>>
>> HTH,
>> Jan
>>
>> "ianaré" <[EMAIL PROTECTED]> schreef in bericht
>> news:[EMAIL PROTECTED]
>>> yeah the subject doesn't really make sense does it?
>>>
>>> anyway want I want to do is this:
>>> if n == 1:
>>>
>>>self.operations.insert(pos, operations.Replace.Panel(self, main))
> .
> .
> .
> I think you meant "...[n - 1]" rather than "...[n]".
>
> I'm a tiny bit surprised no one has organized this in terms
> of a dictionary. I don't know, of course, how robust is the
> characterization of n as a small integer. Maybe
>
> lookup_table = {
> 0: "Replace",
> 1: "ChangeCase",
> 2: "Move"}
>
> captures the sentiment; maybe something else does it better.
>
Surely for this requirement the *only* advantage of a dictionary over a
list is its ability to index with arbitrary values and thereby avoid the
need to use [n-1]. Wouldn't it therefore be less perverse to use
lookup_table = {
1: "Replace",
2: "ChangeCase",
3: "Move"}
Of course the dictionary would be a big win if the integer choice values
weren't a linear sequence. Otherwise using a list with a fixed offset is
likely to be quicker.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list
Unicode zipping from Python code?
Hi! As I experienced in the year 2006, the Python's zip module is not unicode-safe. With the hungarian filenames I got wrong result. I need to convert iso-8859-2 to cp852 chset to get good result. As I see, this module is "a command line tool" imported as extension. Now I search for something that can handle the characters good, or handle the unicode filenames. Does anyone knows about a python project that can do this? Or other tool what I can use for zipping intern. characters? Thanks for your help! dd -- http://mail.python.org/mailman/listinfo/python-list
cgi python
Hi Christian,
I have seen your well-solved cgi-python answers. That's why I think you
would be able to answer my query related to the same.
I am writing a cgi program and placing it in cgi-bin folder of Apache
Server. Now I have written a python script in the same folder to
generate a graph 'genebarchart.py'.
When I run this program from shell, i.e.,
C:\Program Files\Apache Group\Apache2\cgi-bin>python genebarchart.py
it runs well and creates the graph in htdocs folder as I save the graph
there using a save command within the python script, but when I use the
os.system command to call the python script within the cgi-code, i.e.,
os.system ("python genebarchart.py")
as both the scripts are in the same folder, it doesn't creates the graph
in htdocs folder. Can u please tell me why?
Thanks,
Piyali
--
http://mail.python.org/mailman/listinfo/python-list
