Re: how to get name of function from within function?
I'm with Steven Bethard on this; I don't know what you (Christopher J. Bottaro) are trying to do. Based on your example, does the following meet your needs? >>> class Spam(object): ... def funcA(self): ... print "A is called" ... def __getattr__(self, name): ... if name.startswith("_"): ... raise AttributeError, name ... f = get_function(name) ... if f is not None: ... return f ... raise AttributeError, name ... >>> def get_function(name): ... return globals().get(name + "IMPL", None) ... >>> x = Spam() >>> x.funcA() A is called >>> x.funcB() Traceback (most recent call last): File "", line 1, in ? File "", line 10, in __getattr__ AttributeError: funcB >>> def funcBIMPL(): ... print "Calling all bees" ... >>> x.funcB() Calling all bees >>> Confused-ly-your's Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements
Nicolas Fleury wrote: > There's no change in order of deletion, it's just about defining the > order of calls to __exit__, and they are exactly the same. BTW, my own understanding of this is proposal is still slight. I realize a bit better that I'm not explaining myself correctly. > As far as I > know, PEP343 has nothing to do with order of deletion, which is still > implementation-dependant. It's not a constructor/destructor thing like > in C++ RAII, but __enter__/__exit__. I'm mixing (because of my lack of full comprehension) RAII with your proposal. What I meant to say was in the PEP with locking(someMutex) with opening(readFilename) as input with opening(writeFilename) as output ... it's very well defined when the __exit__() methods are called and in which order. If it's with locking(someMutex) with opening(readFilename) as input with opening(writeFilename) as output with the __exit__()s called at the end of the scope (as if it were a __del__, which it isn't) then the implementation could still get the __exit__ order correct, by being careful. Though there would be no way to catch an exception raised in an __exit__. I think. >> Your approach wouldn't allow the following > > No, I said making the ':' *optional*. I totally agree supporting ':' is > useful. Ahh, I think I understand. You want both with abc: with cde: pass and with abc with def and to have the second form act somewhat like RAII in that the __exit__() for that case is called when the scope ends. Hmm. My first thought is I don't like it because I'm a stodgy old traditionalist and don't like the ambiguity of having to look multiple tokens ahead to figure out which form is which. I can see that it would work. Umm, though it's tricky. Consider with abc with defg: with ghi with jkl: 1/0 The implementation would need to track all the with/as forms in a block so they can be __exit__()ed as appropriate. In this case ghi.__exit() is called after jkl.__exit__() and before defg.__exit__ The PEP gives an easy-to-understand mapping from the proposed change to how it could be implemented by hand in the existing Python. Can you do the same? > True. But does it look as good? Particularly the _ part? I have not idea if the problem you propose (multiple with/as blocks) will even exist so I can't comment on which solution looks good. It may not be a problem in real code, so not needing any solution. Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: any macro-like construct/technique/trick?
If you still must have something like the c preprocessor then unix has m4 (and it seems there is a windows version http://gnuwin32.sourceforge.net/packages/m4.htm). The start of the doc reads: GNU M4 ** GNU `m4' is an implementation of the traditional UNIX macro processor. It is mostly SVR4 compatible, although it has some extensions (for example, handling more than 9 positional parameters to macros). `m4' also has builtin functions for including files, running shell commands, doing arithmetic, etc. Autoconf needs GNU `m4' for generating `configure' scripts, but not for running them. - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope
"Elliot Temple" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I want to write a function, foo, so the following works: > > def main(): > n = 4 > foo(n) > print n > > #it prints 7 > > if foo needs to take different arguments, that'd be alright. > > Is this possible? No, you cannot *rebind* in intermediate scopes. However you can alter. nl = [4] foo(nl( print nl[0] #could print anything Or pass dict or instance Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get name of function from within function?
Steven Bethard wrote: [...snip...] > Yes, has's suggestion is probably the right way to go here. I'm still > uncertain as to your exact setup here. Are the functions you need to > wrap in a list you have? Are they imported from another module? A > short clip of your current code and what you want it to do would help. But I want to avoid having to write each wrapper myself. As it is now, when I want to add a public method to my class named myFunc, I first write myFunc which is a wrapper to the implementation: def myFunc(self): try: self.myFuncIMPL() except: # error handling code def myFuncIMPL(self): # do the real stuff here, no need to worry about error handling stuff # cuz its done in the wrapper I guess I'm just lazy, but I don't want to write the wrapper func for each new func I want to add. I want it done automatically. > I don't know. What does PHP's __call() do? I don't know PHP, and it > wasn't in the online manual http://www.php.net/docs.php. http://www.php.net/manual/en/language.oop5.overloading.php I haven't tried it yet, but this is what I would do with __call(): function __call($name, $args) { $name .= 'IMPL'; try { $this->$name($args); } except { # error handling; } } function funcA() { # do something } function funcBIMPL($a, $b) { # do something } So I imagine it would work like this: $obj = new MyClass(); $obj->funcA(); # actually calls funcA because the function # exists in the class $obj->funcB($a, $b); # funcB doesn't exist, so __call() gets called with # args 'funcB', array($a, $b) # so inside __call(), we append 'IMPL' to $name, then invoke # $this->funcBIMPL($a, $b) Using this setup, when I want to add a new function called mySuperFunc(), I merely have to define mySuperFuncIMPL() and magically the wrapper is "made for me"...=) Thanks for the help and ideas! -- http://mail.python.org/mailman/listinfo/python-list
Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements
Nicolas Fleury <[EMAIL PROTECTED]> writes: > What about making the ':' optional (and end implicitly at end of current > block) to avoid over-indentation? > > def foo(): > with locking(someMutex) > with opening(readFilename) as input > with opening(writeFilename) as output > ... How about this instead: with locking(mutex), opening(readfile) as input: ... So there could be more than one expression in one with. > would be equivalent to: > > def foo(): > with locking(someMutex) > with opening(readFilename) as input > with opening(writeFilename) as output > ... The thing is that with normal try-finally block, you can add more things to it easily. This kind of with thing does not allow adding more stuff to it in any other way than adding more indentation. Anyway, I like the idea of the PEP too. -- Ilpo Nyyssönen # biny # /* :-) */ -- http://mail.python.org/mailman/listinfo/python-list
Re: couple of new python articles on onlamp
Kongulo(google crawling tool) seems to be using your App, py2exe. Great work, Thomas! Thomas Heller wrote: > Jeremy Jones <[EMAIL PROTECTED]> writes: > > >>I've got a couple of new articles on ONLamp: >> >>Writing Google Desktop Search Plugins >>http://www.onlamp.com/pub/a/python/2005/06/01/kongulo.html >> >>and >> >>Python Standard Logging >>http://www.onlamp.com/pub/a/python/2005/06/02/logging.html >> >> >>Comments, criticisms, flames all welcome. > > > I've read the logging article, and I like it. Good work. > > Thanks, > > Thomas -- george -- http://mail.python.org/mailman/listinfo/python-list
weird cgi problem w/ apache
Hello all. i have a strange problem with some python cgi scripts. the deal is. i keep loosing permission to write to a file created by a cgi script. the file is created in a directory created by a python script. but after the file is created by the cgi script, another script in the same folder cannot open it to write to. think that its a permissions issue. the thing is, all of it works on my Arch linux computer, but it doesn't work on my Ubuntu computer. same folders, same everything (except http.conf) because debian sets up its modules differently. how come it will create the directory, create the files, but not let me go back into the file to edit? any suggestions? what could be different? from one computer to the next? -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope
On Friday 03 June 2005 07:17 pm, Elliot Temple wrote: > Nothing is wrong with it in this case. I just want to know if Python > can do what I said. Read the python-list "working with pointers" thread from Tuesday. Good answers were posted there. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope
Elliot Temple wrote: > Nothing is wrong with it in this case. I just want to know if Python > can do what I said. With a number of difficult hacks, yes. Passing around objects as namespaces, however, is vastly easier and far superior. -- Robert Kern [EMAIL PROTECTED] "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope
On Jun 4, 2005, at 2:13 AM, Leif K-Brooks wrote: > Elliot Temple wrote: > >> I want to write a function, foo, so the following works: >> >> def main(): >> n = 4 >> foo(n) >> print n >> >> #it prints 7 >> > > What's wrong with: > > def foo(n): > return 7 > > def main(): > n = 4 > n = foo(n) > print n > > Anything else (including the tricks involving mutable objects that > will > no doubt be posted) will result in ugly, hard to maintain code. Nothing is wrong with it in this case. I just want to know if Python can do what I said. -- Elliot Temple http://www.curi.us/ --- [This E-mail scanned for viruses by Declude Virus] -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope
Elliot Temple wrote: > I want to write a function, foo, so the following works: > > def main(): > n = 4 > foo(n) > print n > > #it prints 7 What's wrong with: def foo(n): return 7 def main(): n = 4 n = foo(n) print n Anything else (including the tricks involving mutable objects that will no doubt be posted) will result in ugly, hard to maintain code. -- http://mail.python.org/mailman/listinfo/python-list
Scope
I want to write a function, foo, so the following works: def main(): n = 4 foo(n) print n #it prints 7 if foo needs to take different arguments, that'd be alright. Is this possible? I already tried this (below), which doesn't work. foo only changes the global n. n = 3 def main(): def foo(var, context, c2): exec var + " = 7" in context, c2 n = 4 foo("n", locals(), globals()) print n if __name__ == '__main__': main() print n And of course I tried: >>> def inc(n): ... n += 3 ... >>> a = 4 >>> inc(a) >>> a 4 -- Elliot Temple http://www.curi.us/ --- [This E-mail scanned for viruses by Declude Virus] -- http://mail.python.org/mailman/listinfo/python-list
Re: tutorial
zzz wrote: > May I know where is the good website for Python tutorial? Many thanks. How about...the Python website? (www.python.org) Google is also a good place to find a great multitude of things, including Python Tutorials. -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python config problem
David Stanek wrote: > On Fri, Jun 03, 2005 at 01:16:17PM -0600, Manuel Pellecer wrote: > > i want to use mod_python with Apache2 and i made a .htaccess in the > > subdirectory where i have all my scripts: > > > > The .htacces goes like this: > > > > AddHandler mod_python .py > > PythonHandler mptest > > PythonDebug On > > Try adding the following line to your .htaccess file: > PythonPath "sys.path + ['/your/path']" > Where '/your/path' is the path in which mptest.py resides. Explicitly overriding PythonPath when using mod_python is not recommended as it causes more problems than good usually. It certainly should not be required to get this working when everything is setup correctly. Suggested that the original poster read: http://www.dscpl.com.au/projects/vampire/articles/modpython-001.html That article is specifically written to help out people with their first mptest example, listing what can go wrong and how to go about working it out. Suggest anything after that is better asked on mod_python mailing list. Graham -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse.py: FutureWarning error
Terry Reedy wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Terry Reedy wrote: >> >>>"kosuke" <[EMAIL PROTECTED]> wrote in message >>>news:[EMAIL PROTECTED] >>> >>> man python --- COMMAND LINE OPTIONS >>> >>> >>>This should REALLY be on the doc page of the Python site. >> >>Hear, hear! I never even knew this existed! >> >>Where should it go in the docs? In the Language Reference or the Tutorial >>or...? > > > Since the Tutorial already has section 2. Using the Python Interpreter that > discusses a few of the switches, I would add it as an appendix with a > reference to the appendix at the end of the appropriate subsection. > Perhaps I will submit a tracker item. Sounds good to me. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get name of function from within function?
Christopher J. Bottaro wrote: > Basically I want to wrap every function in try/except automatically. [snip] > every function (err, method) is enclosed in the exact > same try/except error handling code. Everytime I make a new function, I > copy/paste that try/catch block. Yes, has's suggestion is probably the right way to go here. I'm still uncertain as to your exact setup here. Are the functions you need to wrap in a list you have? Are they imported from another module? A short clip of your current code and what you want it to do would help. For example, if they are the only thing another module contains, you can use has's wrapFunction function and do something like: import functionmodule for name in dir(functionmodule): if not name.startswith('_'): func = wrapFunction(getattr(functionmodule, name)) setattr(functionmodule, name, func) > Is there something like PHP's __call() method in Python? I don't know. What does PHP's __call() do? I don't know PHP, and it wasn't in the online manual http://www.php.net/docs.php. >>>Also, is there a way to turn normal positional args into a tuple without >>>using *? Like this: >>> >>>def f(a, b, c): >>> print get_args_as_tuple() >>> >>> >>f(1, 2, 3) >>> >>>(1, 2, 3) >> >>Um... >> >>py> def f(a, b, c): >>... print (a, b, c) >>... >>py> f(1, 2, 3) >>(1, 2, 3) >> >>? > > In your method, if the name and/or number of positional arguments changes, > the body of the function must change. I want to avoid that. But if the name and/or number of positional arguments changes, you're already changing the function definition. What's the real use case here? Are you really just printing them? Or are you doing something else? STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing a warnings filter?
Torsten Bronger wrote: > When I add a warning filter with warnings.filterwarnings, how can I > get rid of it? I've read about resetwarnings(), but it removes all > filters, even those that I didn't install in a certain function. I have never used this module, but judging by a quick glance of the source to "warnings.py", it appears that warning filters are added to a list called "warnings.filters". They are added to the beginning of the list unless you pass a true value for the "append" parameter of "filterwarnings", in which case they are added to the end. The usual way to remove items from a list apply, ie.: del warnings.filters[0] # if append was false del warnings.filters[-1] # if append was true Note that all of these operations modify module data, which could have implications in multithreaded programs. If your program is multithreaded, you may want to consider using locks. Hope this helps, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: What are OOP's Jargons and Complexities?
Xah Lee wrote: > to be continued tomorrow. Please don't... mkb. -- http://mail.python.org/mailman/listinfo/python-list
Re: tutorial
I'm a beginner as well, and I liked this one: http://docs.python.org/tut/tut.html But I ended up buying the "Learning Python" book anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get name of function from within function?
Christopher J. Bottaro wrote: > Basically I want to wrap every function in try/except automatically. Simplest way to do that would be something like: def wrapFunction(func): def wrapper(*args, **kargs): try: return func(*args, **kargs) except Exception, e: raise # your error handling code here return wrapper HTH -- http://mail.python.org/mailman/listinfo/python-list
Controlling source IP address within urllib2
Does anybody know how to control the source IP address (IPv4) when using the urllib2 library? I have a Linux box with several IP addresses in the same subnet, and I want to simulate several individuals within that subnet accessing web pages independently. I need the functionality of urllib2 because there will be redirects and other HTTP-type functions to implement. It would be nice if I could create (and bind) sockets myself and then tell the urllib functions to use those sockets. Perhaps there is some sort of "back-door" way of doing this??? Any hints are appreciated! -Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: The need to put "self" in every method
Fernando M. wrote: > Hi, > > i was just wondering about the need to put "self" as the first > parameter in every method a class has because, if it's always needed, > why the obligation to write it? couldn't it be implicit? > > Or is it a special reason for this being this way? > > Thanks. Here's how I view it... (It may not be strictly correct, so corrections are welcome.) It helps to think of new style class's as code patterns or templates to create class-instance objects. Since you don't know what the name of the instance object is going to be when you write the class, a way to refer to the contents of the not yet created object is needed. Passing the class-instance reference as the first argument is how Python gets a reference to the local name space of the method. You can then use that name to access the other objects in the class-instance or to create new objects in the class-instance from within the method without knowing what the class-instance name is before hand. Python doesn't pass the 'self' reference when a locally defined function is called inside a class or method. By having to *explicitly* receive the 'self' reference in the argument list, it is clear when the 'self' reference is available for use and when it's not. Cheers, _Ron_Adam -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get name of function from within function?
Steven Bethard wrote: > Christopher J. Bottaro wrote: >> I want to get the name of the function from within the function. >> Something like: >> >> def myFunc(): >> print __myname__ >> > myFunc() >> 'myFunc' > > There's not a really good way to do this. Can you give some more detail > on what exactly you're trying to do here? I want to make wrappers around functions but I can't use __getattr__ because the functions are being published as a SOAP service and the SOAP lib I'm using requires a callable object as the argument to the publishing function. Basically I want to wrap every function in try/except automatically. Typically, I suppose people would do that with __getattr__. The way my code is now is that every function (err, method) is enclosed in the exact same try/except error handling code. Everytime I make a new function, I copy/paste that try/catch block. Its ugly, it clutters the code, its prone to error, and if i decide to change the error handling code later, I have to change tons of functions. Actually, I just realized that function call arguments are not passed to __getattr__, so my idea of wrapping function calls that way won't work. Is there something like PHP's __call() method in Python? >> Also, is there a way to turn normal positional args into a tuple without >> using *? Like this: >> >> def f(a, b, c): >> print get_args_as_tuple() >> >f(1, 2, 3) >> >> (1, 2, 3) > > Um... > > py> def f(a, b, c): > ... print (a, b, c) > ... > py> f(1, 2, 3) > (1, 2, 3) > > ? In your method, if the name and/or number of positional arguments changes, the body of the function must change. I want to avoid that. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements
Andrew Dalke wrote: >>def foo(): >> with locking(someMutex) >> with opening(readFilename) as input >> with opening(writeFilename) as output >> ... > > > Nothing in Python ends at the end of the current block. > They only end with the scope exits. The order of deletion > is not defined, and you would change that as well. There's no change in order of deletion, it's just about defining the order of calls to __exit__, and they are exactly the same. As far as I know, PEP343 has nothing to do with order of deletion, which is still implementation-dependant. It's not a constructor/destructor thing like in C++ RAII, but __enter__/__exit__. But yes, it creates a precedent by creating a statement affecting the end of the current indentation block. But that's what this PEP is all about... > Your approach wouldn't allow the following No, I said making the ':' *optional*. I totally agree supporting ':' is useful. > If the number of blocks is a problem it wouldn't be that > hard to do > > with multi( locking(someMutex), > opening(readFilename), > opening(writeFilename) ) as _, input, output: > ... True. But does it look as good? Particularly the _ part? Regards, Nicolas -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get name of function from within function?
Christopher J. Bottaro wrote: > I want to get the name of the function from within the function. Something > like: > > def myFunc(): > print __myname__ > myFunc() > 'myFunc' There's not a really good way to do this. Can you give some more detail on what exactly you're trying to do here? Depending on a function's name within that function is probably a bad idea... You *can* do this using a sys._getframe() hack: py> def my_func(): ... print sys._getframe().f_code.co_name ... py> my_func() my_func But that depends on a non-public API. Also, what do you want to happen if someone binds another name to your function? The code above will print the original name even if it's different from the new name(s): py> g = my_func py> del my_func py> g() my_func py> my_func() Traceback (most recent call last): File "", line 1, in ? NameError: name 'my_func' is not defined > Also, is there a way to turn normal positional args into a tuple without > using *? Like this: > > def f(a, b, c): > print get_args_as_tuple() > f(1, 2, 3) > > (1, 2, 3) Um... py> def f(a, b, c): ... print (a, b, c) ... py> f(1, 2, 3) (1, 2, 3) ? STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python config problem
Getting mod_python to work is hard because there are many things to get into account. Your Apache version should match the proper mod_python version, as well as the python version amd so on... If you are having many problems, I suggest installing Apache2Triad, which is a package that will install everything you need (and more) all at once. www.apache2triad.net -- http://mail.python.org/mailman/listinfo/python-list
Re: provide 3rd party lib or not... philosophical check
Maurice LING <[EMAIL PROTECTED]> writes: > Just a philosophical check here. When a program is distributed, is it > more appropriate to provide as much of the required 3rd party > libraries, like SOAPpy, PLY etc etc, in the distribution itself or it > is the installer's onus to get that part done? If you absolutely need a 3rd party library, you have to make a careful decision whether to include it or not. Generally when in doubt, I'd say include it. But if you can, try to avoid needing external modules and instead use what comes in the Python distro so your code is otherwise self-contained. That is the Python philosophy of "using the batteries". If writing an extra ten lines of code or sacrificing an unimportant feature lets you do something with the Python library that you could do in 1 line with a 3rd party module, then write the ten lines or drop the feature, and get rid of the external dependency. If the module saves a big amount of work or does something important, then use it, but if the library's usefulness extends to many other developers, maybe that means you should start making the case to get the 3rd party module included in future Python releases, assuming the module's license permits it. -- http://mail.python.org/mailman/listinfo/python-list
Re: What are OOP's Jargons and Complexities?
Paul McGuire wrote: > we just recently on > this forum had someone ask about "polymorphism" when what they really > meant was "overloaded method signatures." (It is even more unfortunate > that language features such as overloaded method signatures and > operator overloading get equated with OOP I've actually heard "overloaded method signatures" be referred to as ad-hoc polymorphism. Aren't there like 4 types of polymorphism: inheritance, ad-hoc, parameter templetization (sp?), and something else...can't remember. -- C -- http://mail.python.org/mailman/listinfo/python-list
Re: Pressing A Webpage Button
"Esben Pedersen" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > How do i know which methods the ie object has? dir(ie) doesn't show > Navigate. For ie object: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/IWebBrowser2/IWebBrowser2.asp For document object: http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_document.asp -- http://mail.python.org/mailman/listinfo/python-list
Re: calling ksh script from python
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > thanks for your input... > well I just find out that modifying environment through ksh call is not > possible (can't get the new evironment back to python). I think the > best thing to do is to translate all my ksh to pure python... I thought > that I could re-use some stufff, but I guest I'm going to translate > everything... Right, that's true - more generally, no process can modify another's environment. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: calling ksh script from python
In article <[EMAIL PROTECTED]>, Thorsten Kampe <[EMAIL PROTECTED]> wrote: > * Cameron Laird (2005-06-02 18:08 +0100) > > In article <[EMAIL PROTECTED]>, > > Donn Cave <[EMAIL PROTECTED]> wrote: > >>Meanwhile, it might be worthwhile to reconsider the use > >>of ksh here, if you have any choice in the matter. Ksh > >>is fine for interactive use, but has some unfortunate > >>flaws as a programming shell, and due to proprietary issues > >>one commonly encounters an alternative implementation that's > >>even worse. On most modern platforms, sh will have a pretty > >>good programming feature set, and will be more reliable > >>(especially if it isn't just ksh by another name.) > > . > > Infidel. While I sure feel that way about csh(1), it > > surprises me you'd criticize ksh(1) so. 'Fact, 'mong > > all the *sh-s, I *recommend* ksh for programming. May- > > be the two of us see things differently. > > http://groups-beta.google.com/group/comp.unix.shell/msg/98578e8d95137a3c Well, that certainly must just about say it all. It's nice to see that the author knows rc and es, which are indeed a couple of very much better designed shells. I am not sure I agree with him so much on shell programming in general, but it depends on what his point really may be. For sure, it's good to be aware of those things, at any rate. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
how to get name of function from within function?
I want to get the name of the function from within the function. Something like: def myFunc(): print __myname__ >>> myFunc() 'myFunc' Really what I want to do is to easily strip off the prefix of a function name and call another function. Like this: def prefix_myFunc(a, b, c): name = __myname__[7:] call(name, a, b, c) That would call myFunc(a, b, c). How do I accomplish this 'elegantly', err...'pythonicly'..=) Also, is there a way to turn normal positional args into a tuple without using *? Like this: def f(a, b, c): print get_args_as_tuple() >>> f(1, 2, 3) (1, 2, 3) I don't want to use def f(*args): print args because I want to keep the error checking capability that comes with using a fixed number of positional args. Thank you for the help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interest group software
> > David> Is there already any software out there to manage a Python > David> Interest Group? Something that can register users, take RSVPs > for > David> meetings, etc. > > I suspect a fair number take advantage of meetup.com. > > Skip > > The original group did use meetup.com. I'm not too fond of them charging a monthly fee for their service. If something suitable does not exists I can always write it in Python! David -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interest group software
Skip Montanaro wrote: > David> Is there already any software out there to manage a Python > David> Interest Group? Something that can register users, take RSVPs for > David> meetings, etc. > > I suspect a fair number take advantage of meetup.com. And a fair number of people now suspect meetup.com of taking advantage of them, by introducing completely unreasonable fees (in relation to what is offered in return) - see http://slashdot.org/article.pl?sid=05/04/13/0359253&tid=187&tid=215&tid=98 Tim C -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interest group software
David Stanek wrote: > Is there already any software out there to manage a Python Interest > Group? Something that can register users, take RSVPs for meetings, > etc. I dare say that Roundup - http://roundup.sourceforge.net/ - (not to be confused with Roundup - http://www.roundup.com/ ) - could be used effectively for such purposes, since it provides both Web and email interfaces for ad hoc interest groups. Not good for weedy types, though. Tim C -- http://mail.python.org/mailman/listinfo/python-list
Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements
Nicolas Fleury wrote: > What about making the ':' optional (and end implicitly at end of current > block) to avoid over-indentation? > > def foo(): > with locking(someMutex) > with opening(readFilename) as input > with opening(writeFilename) as output > ... > > would be equivalent to: > > def foo(): > with locking(someMutex) > with opening(readFilename) as input > with opening(writeFilename) as output > ... Nothing in Python ends at the end of the current block. They only end with the scope exits. The order of deletion is not defined, and you would change that as well. Your approach wouldn't allow the following with locking(mutex): increment_counter() x = counter() with locking(mutex): decrement_counter() except by making a new block, as if 1: locking(mutex) x = counter() if 1: locking(mutex) If the number of blocks is a problem it wouldn't be that hard to do with multi( locking(someMutex), opening(readFilename), opening(writeFilename) ) as _, input, output: ... Untested sketch of an implementation class multi(object): def __init__(self, *args): self.args = args def __enter__(self): results = [] for i, arg in enumerate(self.args): try: results.append(arg.__enter__()) except: # back up through the already __entered__ args exc = sys.exc_info() for j in range(i-1, -1, -1): try: self.args[j].__exit__(*exc) except: # Need to get the new exception, to match the PEP behavior exc = sys.exc_info() raise exc[0], exc[1], exc[2] return results def __exit__(self, type, value, traceback): for arg in self.args[::-1]: try: arg.__exit__(type, value, traceback) except: type, value, traceback = sys.exc_info() Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interest group software
Try upcoming.org. In addition to the Web interface, they also offer a REST-ful API that you can use from your own app. Grig -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interest group software
David> Is there already any software out there to manage a Python David> Interest Group? Something that can register users, take RSVPs for David> meetings, etc. I suspect a fair number take advantage of meetup.com. Skip -- http://mail.python.org/mailman/listinfo/python-list
Python interest group software
Is there already any software out there to manage a Python Interest Group? Something that can register users, take RSVPs for meetings, etc. -- David Stanek www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgprkGXMh0xiQ.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python config problem
On Fri, Jun 03, 2005 at 01:16:17PM -0600, Manuel Pellecer wrote: > i want to use mod_python with Apache2 and i made a .htaccess in the > subdirectory where i have all my scripts: > > The .htacces goes like this: > > AddHandler mod_python .py > PythonHandler mptest > PythonDebug On Try adding the following line to your .htaccess file: PythonPath "sys.path + ['/your/path']" Where '/your/path' is the path in which mptest.py resides. -- David Stanek www.roninds.net GPG keyID #6272EDAF on http://pgp.mit.edu Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF pgpqT33AXn9gS.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: What are OOP's Jargons and Complexities?
The Rise of “Inheritance” In well-thought-out languages, functions can have inner functions, as well as taking other functions as input and return function as output. Here are some examples illustrating the use of such facilities: subroutine generatePower(n) { return subroutine (x) {return x^n}; } In the above example, the subroutine generatePower returns a function, which takes a argument and raise it to nth power. It can be used like this: print generatePower(2)(5) // prints 25 Example: fixedPoint: subroutine fixedPoint(f,x) { temp=f(x); while (f(x) != temp) { temp=f(temp); } return temp; } In the above example, fixedPoint takes two arguments f and x, where f is taken to be a function. It applies f to x, and apply f to that result, and apply f to that result again, and again, until the result is the same. That is to say, it computes f[f[f[...f[x]...]]]. FixedPoint is a math notion. For example, it can be employeed to implement Newton's Method of finding solutions as well as many problems involving iteration or recursion. FixedPoint may have a optional third parameter of a true/false function fixedPoint(func,arg,predicate) for determining when the nesting should stop. In this form, it is equivalent to the “while loop” in procedural languages. Example: composition: subroutine composition(a,b,c,...) { return subroutine {a(b(...c...))}; } The above example is the math concept of function composition. That is to say, if we apply two functions in sequence as in g[f[x]], then we can think of it as one single function that is a composition of f and g. In math notation, it is often denoted as (g∘f). For example, g[f[x]]→y is the same as (g∘f)[x]→y. In our pseudo-code, the function composition takes any number of arguments, and returns a single function of their composition. When we define a subroutine, for example: subroutine f(n) {return n*n} the function is power of two, but the function is named f. Note here that a function and its name are two different concepts. In well-thought-out languages, defining a function and naming a function are not made inseparable. In such languages, they often have a keyword “lambda” that is used to define functions. Then, one can assign it a name if one so wishes. This separation of concepts made many of the lingustic power in the above examples possible. Example: lambda (n) {return n^2;}\\ a function (lambda (n) {return n^2;})(5) \\ a function applied to 5. f = lambda (n) {return n^2;}\\ a function is defined and named f(5)\\ a function applied to 5. lambda (g) {return lambda {g(f)} } \\ a function composition of (g∘f). The above facilities may seem exotic to industrial programers, but it is in this milieu of linguistic qualities the object oriented paradigm arose, where it employees facilities of inner function (method), assigning function to variable (instantiation), function taking function as inputs (calling method thru object), and application of function to expressions (applying method to data in a class). The data-bundled-with-functions paradigm finds fitting application to some problems. With the advent of such Objet-Oriented practice, certain new ideas emerged. One of great consequence is the idea of inheritance. In OOP practice computations are centered around data as entities of self-contained boxed sets (objects). Thus, frequently one needs slightly different boxed sets than previously defined. Copy and Pasting existing code to define new boxed sets quickly made it unmanageable. (a messy set of classes). With powerful lingustic evironment and habituation, one began to write these new boxed-subroutines (classes) by extending old subroutines (classes) in such a way that the new subroutine contains all variables and subroutines of a base subroutine without any of the old code appearing in the body of the subroutine. Here is a pseudo-code illustration: g = subroutine extend(f) { new variables ... new inner-subroutines ... return a subroutine that also contains all stuff in subroutine f } Here, “extend” is a function that takes another function f, and returns a new function such that this new function contains all the boxed-set things in f, but added its own. This new boxed-set subroutine is given a name g. In OOP parlance, this is the birth of inheritance. Here, g inherited from that of f. f is called the base class or superclass of g. g is the derived class or subclass of f. In functional terms, inheritance mechanism is a function E that takes another function f as input and returns a new function g as output, such that g contained all enclosed members of f with new ones defined in E. In pure OOP languages such as Java, the function E is exhibited as a keyword “extends”. For example, the above code would be in Java: class g extends f { new variables ... new inner-subroutines ... } Here is the same example in Python, where inheritance takes the form of a class definition with a para
Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements
Guido van Rossum wrote: > After many rounds of discussion on python-dev, I'm inviting public > comments for PEP 343. Rather than posting the entire PEP text here, > I'm inviting everyone to read it on line > (http://www.python.org/peps/pep-0343.html) and then post comments on a > Wiki page I've created for this purpose > (http://wiki.python.org/moin/WithStatement). > > I think this is a good one; I hope people agree. Its acceptance will > obsolete about 4 other PEPs! (A sign that it fulfills a need and that > the proposed solution is powerful.) I like the PEP very much; I guess most C++ programmers are missing that capability in Python. (I was following the discussion on python-dev, and I'm pleased and surprised how good the result/compromise is). What about making the ':' optional (and end implicitly at end of current block) to avoid over-indentation? def foo(): with locking(someMutex) with opening(readFilename) as input with opening(writeFilename) as output ... would be equivalent to: def foo(): with locking(someMutex) with opening(readFilename) as input with opening(writeFilename) as output ... Regards, Nicolas -- http://mail.python.org/mailman/listinfo/python-list
mod_python config problem
i want to use mod_python with Apache2 and i made a .htaccess in the subdirectory where i have all my scripts: The .htacces goes like this: AddHandler mod_python .py PythonHandler mptest PythonDebug On and I changed the main configuracion file of Apache2 like this: #--memepelle AllowOverride FileInfo #memepelle-- and i made a mptest.py that goes like this: from mod_python import apache def handler(req): req.content_type = "text/plain" req.write("Hello World!") return apache.OK But i still have this error and i don't know why Mod_python error: "PythonHandler mptest" Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch log=debug) File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 454, in import_module f, p, d = imp.find_module(parts[i], path) ImportError: No module named mptest Please some help!!! -- http://mail.python.org/mailman/listinfo/python-list
Formatting Time
I never thought id need help with such a thing as time formatting (admittadly i never did it before) but ok, i guess there is a first for everything. I have a float variable representing seconds, and i want to format it like this: 0:00:00 (h:mm:ss) Now search as I might i am finding this quite elusive, i had a look at the time module but that seems overly complicated for this. Anyone got any simple solutions to doing this? cheers! = Amazing, two days and no replies, cant be that i have stumped the python community with this... I have ( a rather bad feeling) that I am having trouble with my email again. I can recieve mail, but on some mailinglists (hear this one and the gentoo list) I can get other peoples topics in the list, but never get mails re. topics I posted (including the original post and any subsequent replies). All in all rather strange. Therefore if anyone has responded to my question, please CC me so that I can receive the info. thx. -- http://mail.python.org/mailman/listinfo/python-list
Re: thread vs GC
Paul Rubin wrote: > Any suggestions for the cleanest way to get rid of the thread? As Jeff explains, it is rather unlikely that GC will collect primegen objects, since the generating thread holds self as a local variable. You should make background_generator have explicit q and event arguments, and you should signal the event in __del__. However, this won't terminate the thread, since it still hangs in .put. So it might be easiest to .read() in __del__ first. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Snakelets 1.41 and Frog 1.6
I'm happy to announce the release of Snakelets 1.41 and at the same time Frog 1.6. Snakelets is a Python web application server. This project provides a threaded web server, Ypages (HTML+Python language, similar to Java's JSPs) and Snakelets: code-centric page request handlers (similar to Java's Servlets). Frog is a Blog server application written for Snakelets. It is small but has many features, such as BBcode markup, XHTML+CSS page output, multiple users, no database required, anti-spam measures, email notification, Smileys, RSS feeds, and more. Please find more info on both projects here: http://snakelets.sourceforge.net/ Download: http://sourceforge.net/project/showfiles.php?group_id=41175 The detailed release notes have been added to the version section. Have fun! --Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Re: scripting browsers from Python
[Michele Simionato] > > I would like to know what is available for scripting browsers from > > Python. [...] > > to do POST requests too. I don't want to use urllib to emulate a > > browser, I am > > interested in checking that browser X really works as intended with my > > application. Any suggestion? [...] [Stephen Thorne] > I use pbp, http://pbp.berlios.de/ [...] Again, that doesn't do what Michele wants. John -- http://mail.python.org/mailman/listinfo/python-list
Re: scripting browsers from Python
Olivier Favre-Simon <[EMAIL PROTECTED]> writes: [...] > > I'd like to have a reimplementation of ClientForm on top of something > > like BeautifulSoup... > > > > > > John > > When taken separately, either ClientForm, HTMLParser or SGMLParser work > well. > > But it would be cool that competent people in the HTML parsing domain join > up, and define a base parser interface, the same way smart guys did with > WSGI for webservers. Perhaps. Given a mythical fixed quantity of volunteer coding effort I could assign to any HTML parsing project, I'd really prefer that somebody separated out the HTML parsing, tree building and DOM code from Mozilla and/or Konqueror. > So libs like ClientForm would not raise say an AttributeError if some > custom parser class does not implement a given attribute. > > Adding an otherwise unused attribute to a parser just in case one day it > will interop with ClientForm sounds silly. And what if ClientForm changes > its attributes, etc. [...] I'm sorry, I didn't really follow that at all. What I hoped to get from implementing the ClientForm interface on top of something like BeautifulSoup was actually two things: 1. Better parsing 2. Access to a nice, and comprehensive, object model that lets you do things with non-form elements, and the ability to move back and forth between ClientForm and BeautifulSoup objects. I already did this for the HTML DOM with DOMForm (unsupported), but for various reasons the implementation is horrid, and since I no longer intend to put in the effort to support JavaScript, I'd prefer a nicer tree API than the DOM. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Pressing A Webpage Button
J Correia wrote: > "Elliot Temple" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>How do I make Python press a button on a webpage? I looked at >>urllib, but I only see how to open a URL with that. I searched >>google but no luck. >> >>For example, google has a button how would i make a script to press that button? >> >>Just for fun, is there any way to do the equivalent of typing into a >>text field like the google search field before hitting the button? >>(I don't actually need to do this.) > > > You don't say which OS... if you're running IE on Windows you > can use COM as follows... > > from win32com.client import Dispatch > from time import sleep > > ie = Dispatch("InternetExplorer.Application") > ie.Visible = 1 > ie.Navigate("http://www.google.com";) > while ie.ReadyState != 4:# Wait for browser to finish loading. > sleep(1) > doc = ie.Document > doc.f.q.value = "qwerty"# form name is 'f'; search field name is 'q' > doc.f.btnG.click()# click on button 'btnG' How do i know which methods the ie object has? dir(ie) doesn't show Navigate. /Esben -- http://mail.python.org/mailman/listinfo/python-list
Re: couple of new python articles on onlamp
"Jeremy Jones" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I've got a couple of new articles on ONLamp: > > Writing Google Desktop Search Plugins > http://www.onlamp.com/pub/a/python/2005/06/01/kongulo.html Wow, another use for Python. I should get this. Thanks. I would add the important fact ', written in Python' at the end of "One such plugin is Kongulo, a web spider. " Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse.py: FutureWarning error
"Kent Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Terry Reedy wrote: >> "kosuke" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> >>>man python --- >>> >>>COMMAND LINE OPTIONS >> >> >> This should REALLY be on the doc page of the Python site. > > Hear, hear! I never even knew this existed! > > Where should it go in the docs? In the Language Reference or the Tutorial > or...? Since the Tutorial already has section 2. Using the Python Interpreter that discusses a few of the switches, I would add it as an appendix with a reference to the appendix at the end of the appropriate subsection. Perhaps I will submit a tracker item. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: couple of new python articles on onlamp
Jeremy Jones <[EMAIL PROTECTED]> writes: > I've got a couple of new articles on ONLamp: > > Writing Google Desktop Search Plugins > http://www.onlamp.com/pub/a/python/2005/06/01/kongulo.html > > and > > Python Standard Logging > http://www.onlamp.com/pub/a/python/2005/06/02/logging.html > > > Comments, criticisms, flames all welcome. I've read the logging article, and I like it. Good work. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: saving .zip or .txt email attachments instead of deleting them
Here is the complete traceback..sorry about that though. I used the run button and entered in "C:\email.txt" for the msgfile parameter thats used for input This email.txt file has a zip file attached to it and is all in text, so hopefully I am working with the correct input file. I used the pop3 example given in the python documentation to pick up a message on the mail server and read and wrote the information to a file --> email.txt Traceback (most recent call last): File "C:\PYTHON23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\My Documents\python scripts\EmailUnpack.py", line 83, in ? main() File "C:\My Documents\python scripts\EmailUnpack.py", line 71, in main ext = mimetypes.guess_extension(part.get_type()) File "C:\PYTHON23\lib\mimetypes.py", line 178, in guess_extension extensions = self.guess_all_extensions(type, strict) File "C:\PYTHON23\lib\mimetypes.py", line 157, in guess_all_extensions type = type.lower() AttributeError: 'NoneType' object has no attribute 'lower' Again, thanks! --Barry -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Cleveland Area Python Interest Group
Is the first meeting on June 6th, I only ask due to short notice. If so I'll be there. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Win32 and Condor
It's been a while since I've experimented with Condor, but it looks like " 'Access is denied.'", You might want to figure out what user the condor service is running as and log in as that user and try to run your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: odbc and python
MM wrote: > Are there any other odbc packages other than the win32all and mxodbc > ones? The win32all odbc.pyd can't access table structure info like > SQLColumns, and mxobdc requires a commercial license which is > unjustifiable for this tiny project. Any other OS alternatives for > win32?. Thanks. The mxODBC package contains a lot of grunt work making access to metadata work smoothly for many targets. I never found the license too expensive for the work (and thought) that it saved me. If you are targeting a single DBMS, or already have a strong understanding of your DB's schema, some other solution may do you as well. I'd be careful you don't spend far more effort getting corner cases to work right with a cobbled-together system than you'll save by using mxODBC. I am not connected to mxODBC other than as a very satisfied customer. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Compile debug packages on windows
First, I compiled Python in DEBUG on Win32 with MSCV.net and the solution distributed in the Python packages. Second, I try to compiled NUMARRAY with my python debug : python_d setup.py build And the compilation crash with the following message : the file python25.lib does not exist (it is normal, because only python25_d.lib exist !) I opened the source file which include Python.h, which include pyconfig.h.located in the directory PC. Then, I found this : #ifdef MS_COREDLL # ifndef Py_BUILD_CORE /* not building the core - must be an ext */ # if defined(_MSC_VER) /* So MSVC users need not specify the .lib file in their Makefile (other compilers are generally taken care of by distutils.) */ # ifdef _DEBUG # pragma comment(lib,"python25_d.lib") # else # pragma comment(lib,"python25.lib") # endif /* _DEBUG */ # endif /* _MSC_VER */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ Then, the symbol _DEBUG need to be define... (I added at the beginning of the file: it seems to be the solution) to import the debug version instead of the release version. But, how can I run the compilation (options on the comand line maybe) which use the python25_d.lib, i.e. how the symbol _DEBUG can be defined when I write 'python_d setup.py build' ? In other words, with a Python in debug, I would generate packages in debug too and propagate the debug mode from Python to the packages... Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: bdist_wininst to distribute a patched python
mg <[EMAIL PROTECTED]> writes: > Hi, > > Because of I have patched Python, I would like to create a Windows > installer containing my patched-Python. So, I try to use the option > 'bdist_wininst' on the setup.py file distributed by python it is > supported ? bdist_wininst can only be used to create distributions of Python modules and packages, not Python itself. > If yes, I have a problem : the run tell me that pyconfig.h does not > exist. What is the solution ? > > Thanks -- http://mail.python.org/mailman/listinfo/python-list
couple of new python articles on onlamp
I've got a couple of new articles on ONLamp: Writing Google Desktop Search Plugins http://www.onlamp.com/pub/a/python/2005/06/01/kongulo.html and Python Standard Logging http://www.onlamp.com/pub/a/python/2005/06/02/logging.html Comments, criticisms, flames all welcome. Jeremy Jones -- http://mail.python.org/mailman/listinfo/python-list
Re: minidom Node to Element
Hang on! It *knows*! Wow, you can call getElementsByTagName() on a Node object and it does the right thing. Weird, but I like it! Very Python! R. On Fri, 03 Jun 2005 17:07:37 +0100, "Richard Lewis" <[EMAIL PROTECTED]> said: > Hey, > > Can I convert an xml.dom.Node object to an xml.dom.Element object? I > want to do the conversion inside a condition like this: > > if node.nodeType == Node.ELEMENT_NODE: > # do conversion: > element = Element(node) > element = node.toElement() > > so it definitely won't cause problems. I just can't find a way to do it! > > (I want to be able to call getElementsByTagName() on the resultant > object; any other workarounds which allow the same functionality would > be just as cool ;-) > > Cheers, > Richard > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
bdist_wininst to distribute a patched python
Hi, Because of I have patched Python, I would like to create a Windows installer containing my patched-Python. So, I try to use the option 'bdist_wininst' on the setup.py file distributed by python it is supported ? If yes, I have a problem : the run tell me that pyconfig.h does not exist. What is the solution ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
minidom Node to Element
Hey, Can I convert an xml.dom.Node object to an xml.dom.Element object? I want to do the conversion inside a condition like this: if node.nodeType == Node.ELEMENT_NODE: # do conversion: element = Element(node) element = node.toElement() so it definitely won't cause problems. I just can't find a way to do it! (I want to be able to call getElementsByTagName() on the resultant object; any other workarounds which allow the same functionality would be just as cool ;-) Cheers, Richard -- http://mail.python.org/mailman/listinfo/python-list
RE: Formatting Time
Coates, Steve (ACHE) wrote: import time t=36100.0 time.strftime('%H:%M:%S',time.gmtime(t)) > '10:01:40' But if t>=24*60*60 then H cycles back to 0 >>> import time >>> t=24*60*60 >>> time.strftime('%H:%M:%S',time.gmtime(t)) '00:00:00' >>> Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
RE: tempfile.gettempdir() result on Windows
| [Leo Breebaart] | | | | On MS Windows, I am trying to find out a good default location to | | save some temporary files. | | | | The tempfile module seemed to have exactly what I wanted: | | | | >>> import tempfile | | >>> tempfile.gettempdir() | | 'c:\\docume~1\\admini~1\\locals~1\\temp' | | >>> | | | | My problem (entirely cosmetic, but still) is that I also need to | | show this location to the users of my program, who I suspect | | would be much happier with a 'proper' Windows path than with this | | '~1' DOS malarkey. | | | | Does anybody know how I can obtain a temp directory in 'verbose' | | format (or somehow convert the gettempdir() result to that)? | [Tim Golden] | Have a look at win32api.GetLongPathName | (from the pywin32 extensions, in case it wasn't | obvious). So something like this: | | | import tempfile | import win32api | | print tempfile.gettempdir () | print win32api.GetLongPathName (tempfile.gettempdir ()) | | | | TJG And, incidentally, while you're there, the win32api.GetTempPath function does the same as tempfile.gettempdir so you don't even have to import the tempfile module if you don't want to. TJG (again) This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
RE: tempfile.gettempdir() result on Windows
[Leo Breebaart] | | On MS Windows, I am trying to find out a good default location to | save some temporary files. | | The tempfile module seemed to have exactly what I wanted: | | >>> import tempfile | >>> tempfile.gettempdir() | 'c:\\docume~1\\admini~1\\locals~1\\temp' | >>> | | My problem (entirely cosmetic, but still) is that I also need to | show this location to the users of my program, who I suspect | would be much happier with a 'proper' Windows path than with this | '~1' DOS malarkey. | | Does anybody know how I can obtain a temp directory in 'verbose' | format (or somehow convert the gettempdir() result to that)? Have a look at win32api.GetLongPathName (from the pywin32 extensions, in case it wasn't obvious). So something like this: import tempfile import win32api print tempfile.gettempdir () print win32api.GetLongPathName (tempfile.gettempdir ()) TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
tempfile.gettempdir() result on Windows
On MS Windows, I am trying to find out a good default location to save some temporary files. The tempfile module seemed to have exactly what I wanted: >>> import tempfile >>> tempfile.gettempdir() 'c:\\docume~1\\admini~1\\locals~1\\temp' >>> My problem (entirely cosmetic, but still) is that I also need to show this location to the users of my program, who I suspect would be much happier with a 'proper' Windows path than with this '~1' DOS malarkey. Does anybody know how I can obtain a temp directory in 'verbose' format (or somehow convert the gettempdir() result to that)? -- Leo Breebaart <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 and BLT
Could you please expand the BLT acronym. For the life of me, the only thing I associate it with is a Bacon, Lettuce and Tomato sandwich, and I'm sure that's not what you meant. John Roth "Lyddall's" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello. > > I am new to this list, but wondered if anyone could help me. I have had > Python set up with PMW and BLT on two machines previous to my current > laptop, but I can't seem to get them all to work together on this machine. > It may be the version of python (2.4, with TCL 8.4) that I have installed > since I had older version on the other machines. > > Anyway - can anyone give me suggestions of how to get BLT to work? > (versions: python 2.4, Tcl 8.4, BLT 2.4) I have run the BLT installer, > copied the dlls into the tcl/bin directory and added that directory to my > path. Still the demos don't recognize BLT as being installed. > > Alternatively - what would be the best graphics extension to learn in > place of BLT if, as it seems, BLT is not supported by anyone any longer. > > thank you, > Ali > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting Time
Am Fri, 03 Jun 2005 09:29:41 +0100 schrieb Ognjen Bezanov: > I never thought id need help with such a thing as time formatting > (admittadly i never did it before) but ok, i guess there is a first for > everything. > > I have a float variable representing seconds, and i want to format it > like this: > > 0:00:00 (h:mm:ss) Hi, Does this work? (not well tested) i=12009 # Number of seconds res=[] # dh, m for d in [24*60*60, 60*60, 60]: res.append("%02d" % (i/d)) i=i%d res.append("%02d" % i) print ":".join(res) # --> 00:03:20:09 (d:h:m:s) -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Removing a warnings filter?
Hallöchen! When I add a warning filter with warnings.filterwarnings, how can I get rid of it? I've read about resetwarnings(), but it removes all filters, even those that I didn't install in a certain function. In particular, I want to transform one special form of warning in an exception to keep track of it more easily. However, before leaving my function I want to restore the old status. How can this be achieved? Thank you! Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: Just remember that Python is sexy
Yes, but we don't want it to get out of hand, like calling it orgy() instead of join(). Or condom() instead of secure(). Or onClimax() instead of onFinished() :-)On 5/31/05, Eric Pederson <[EMAIL PROTECTED]> wrote: > I often can't remember that to remove spaces from a string whether it's> strip() or trim(), and when finding patterns with the re library> whether it's find() or search() and when iterating over key, values of > a dictionary whether it's items() or entries().> But then I remember that Python is "sexy".> It is sexier to strip() than to trim().> You do a strip search() not a find() search. > And you remove items() of clothing and not entries() of clothing.Genius! I will never perplex myself with string_foo.trim() again. (I do forget)I recommend this be adopted as a naming standard for Python methods: "The method name should have a sexy connotation"Eric Pedersonhttp://www.songzilla.blogspot.com :::domainNot="@something.com"domainIs=domainNot.replace("s","z")ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs::: -- http://mail.python.org/mailman/listinfo/python-list
Re: compile python in release...
[mg] > My problem is here : all the source files are compiled with the -g > flag which might be the debug flag. (On the other hand, the option > -DNDEBUG is defined : it's normal !) Then my question is : Is exist > a flag/option to run the shell script named 'configure' allowing to > remove the '-g' flag located in the generated makefile ? There is no relation between `-g' and `-DNDEBUG', they control different things. What people usually do is leaving `-g' for compilation and linking, but stripping the resulting binary or library at installation time. See the documentation of `strip' and the `-s' option of `install'. -- François Pinard http://pinard.progiciels-bpi.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: anygui,anydb, any opinions?
Skip Montanaro wrote: > Glade is fine for building Gtk user interfaces. I have no idea if there are > similar tools for other widget sets, though I wouldn't be surprised if such > tools existed. Once the GUI is fairly stable, most of the development after > that occurs in the underlying functional part of the code (at least in my > recent experience). For that, no amount of Glade slinging will help. Here are a few... http://wxglade.sourceforge.net/ http://boa-constructor.sourceforge.net/ http://spe.pycs.net/ http://www.roebling.de/ http://thekompany.com/products/blackadder/ There's also something inspired by Visual FoxPro... http://www.dabodev.com/ -- http://mail.python.org/mailman/listinfo/python-list
compile python in release...
Hi, I try to install two Python environments on my platform: one in release, the other in debug. I generate the RELEASE Python environment with the following instructions : > ./configure --prefix=/usr/local/python --enable-shared > make My problem is here : all the source files are compiled with the -g flag which might be the debug flag. (On the other hand, the option -DNDEBUG is defined : it's normal !) Then my question is : Is exist a flag/option to run the shell script named 'configure' allowing to remove the '-g' flag located in the generated makefile ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
RRArray for Python?
I was wondering if there is already some 'official' module for round robin arrays. Of course, it is relatively easy to implement your own if you need it, but IMHO it feels like there should be one, because they are so general-purpose. Here's my implementation, if someone needs one. If there are enough people supporting it's release, I could add it to some static web address. """ Round-robin array module This module contains class for a round-robin array and associated round-robin array database to contain long-time spanning sample values (cf. rrdtool). Arrays can be arbitrary length, and default slot values can be defined by the user. Edvard Majakari <[EMAIL PROTECTED]> """ class RRArrayError(Exception): pass class RRArray: """Simple round-robin class for arbitrary items""" def __init__(self, slots, default=None): """Instantiate RRArray object @param default: value to fill empty slots with >>> r = RRArray(10) # creates a round-robin array of length 10 >>> len(r) 10 """ self.default = default self._slots = slots self._array = [default]*slots self._next = 0 # points to next free index in array self._array_full = False def clear(self): """Erase array by setting all values to default fill value""" self._array = [self.default]*self._slots self._next = 0 self._array_full = False def contents(self): """Return contents of RRArray object as a list so that most recent item is the last position. >>> r = RRArray(3, 0) >>> r.contents() [0, 0, 0] >>> r.insert(2) >>> r.contents() [0, 0, 2] """ retval = self.latest(self._slots) retval.reverse() return retval def insert(self, item): """Insert an item to object >>> r = RRArray(3) >>> r.insert(42) >>> r.most_recent() == 42 and r.used_slots() == 1 True """ self._array[self._next % self._slots] = item if self._next == self._slots - 1: self._array_full = True self._next = 0 # wrap-around else: self._next += 1 def latest(self, count): """Return count most recent items Note that it is possible to receive default values which were never inserted, eg. r = RRArray(5) r.insert(2), r.latest(3) # would return [2, None, None] >>> r = RRArray(3) >>> r.insert(42) >>> r.insert(5) >>> r.insert(7) >>> r.insert(11) >>> r.latest(2) [11, 7] >>> r.contents() [5, 7, 11] """ if count > self._slots: err = "attempted to get %d items from rra of size %d" raise RRArrayError(err % (count, self._slots)) latest_idx = self._latest_index() head = self._array[0:latest_idx+1] head.reverse() if count >= len(head): tail = self._array[latest_idx+1:self._slots] tail.reverse() head.extend(tail) return head[0:count] def most_recent(self): """Return most recent item inserted. An IndexError is raised if no items have been inserted yet. """ if self._next == 0 and not self._array_full: raise IndexError("no items inserted yet") return self._array[(self._next - 1) % self._slots] def used_slots(self): """Return number of used slots.""" if self._next < self._slots and not self._array_full: return self._next else: return self._slots ### private and special methods def __len__(self): """Return number of slots in the object.""" return self._slots def _latest_index(self): return (self._next - 1) % self._slots def _test(): import doctest, rrarray doctest.testmod(rrarray) if __name__ == '__main__': _test() -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! "Debugging is twice as hard as writing the code in the firstplace. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian W. Kernighan -- http://mail.python.org/mailman/listinfo/python-list
Question about 'wave' module
Hello Python World! I've been playing with the 'wave' and 'audioop' modules in the library, and I have a question. When I tried to read a "wav" file with samples in 32-bit float, I got the following error: Traceback (most recent call last): File "Play.py", line 111, in ? playWAV(sys.argv[1]) File "Play.py", line 69, in playWAV f = wave.open(fname,'rb') File "D:\Python23\lib\wave.py", line 483, in open return Wave_read(f) File "D:\Python23\lib\wave.py", line 162, in __init__ self.initfp(f) File "D:\Python23\lib\wave.py", line 143, in initfp self._read_fmt_chunk(chunk) File "D:\Python23\lib\wave.py", line 264, in _read_fmt_chunk raise Error, 'unknown format: ' + `wFormatTag` wave.Error: unknown format: 3 Although the documentation doesn't explicitly say so, it appears that only 16-bit format is supported. I looked at the source code ('wave.py'), and I think my hunch is correct. On lines 245 (in method 'readframes') and 412 (in method 'writeframesraw'), a call is made to the array method 'byteswap' if the machine is "big- endian", without testing to see if the samples are 16-bit or 32-bit. I don't understand how this could work without knowing how many bytes to "swap", (ie, 2 or 4). Has anyone on this list used these modules? Am I missing something? BTW, I'm on version 2.3.2 for Windows. The 32-bit sound file was created with a program called "Audacity". I believe the format of the file is a valid wave file format, I'm able to play it with Windows Media Player. Thanks for your help. mail2web - Check your email from the web at http://mail2web.com/ . -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing and source structure troubles
The "best" way depends on how you have structured your program. From what you've told I believe that setting the directories like dir1 dir2 dir3 is a good approach. As for the import errors you're getting, check this section from the tutorial: http://docs.python.org/tut/node8.html#SECTION00840 It describes how to setup packages in Python - and that's exactly what you need. You'll see that in order to import dir3 from dir2 you must import the full name of the package (ie. import dir1.dir3). See the intra-packages reference http://docs.python.org/tut/node8.html#SECTION00842 Regards, Tiago S Daitx On 6/3/05, Echo <[EMAIL PROTECTED]> wrote: > Hello, > > I am having trouble with putting the source for a program I am working on in > different directories. > I have the directories set up like this: > > dir1 >dir2 >dir3 > > I want the source in dir2 to be able to import from the source in dir3(is > this possible). I get import errors when I tried doing this. > > A less preferred structure that I tried was like this: > dir1 >dir3 > dir2 > > I thought that this way would work. but this way I get even more import > errors. two files in dir2 have a 'from dir3.dir2 import bla' however, in one > of the files, I get an import error. any idea why this is?? > > What is the best way to structure the program I am working on? I have 3 > groups of source files. One has the files that start the program and some > tools. Another group has all the main files. And the last group is just some > misc stuff. How would the best way to accomplish this be? > > -- > -Echo > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem calling Python methods from C
In message <[EMAIL PROTECTED]>, Stephen Kellett <[EMAIL PROTECTED]> writes Following my posting with the solution for anyone else that wants to know the answer. The solution appears to be not to use: >module = PyImport_AddModule("gc"); But to use module = PyImport_ImportModule("gc"); Stephen -- Stephen Kellett Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html Computer Consultancy, Software Development Windows C++, Java, Assembler, Performance Analysis, Troubleshooting -- http://mail.python.org/mailman/listinfo/python-list
Re: decimal and trunkating
chris wrote: > I'm new to Python ... and I've used decimal._round() as above. What's the > deal with using underscore methods? (A link will do if that'll save you some > typing). Generally the underscore methods provide *internal* functionality that might be used by other, more externally accessible (i.e. documented!) methods in the object. While as I've said I'm no expert in Decimal and can't say how _round() is intended to be used, it is not documented (as far as I can see) and certainly therefore follows this way of thinking about underscore methods. Several of us have found at least one suitable alternative (i.e. quantize()) that don't rely on underscore methods. (Think of the underscore as being a non-binding convention that says "don't use this externally if possible, as it doesn't form part of the contract guaranteed by this object... it may be removed in the future, may not work exactly as you wish, may have side effects that aren't documented or haven't been analyzed fully when used externally, etc.") -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: SFTP
Kornfeld Rick (sys1rak) wrote: > Good Morning > > I have scoured the internet looking for an Python SFTP API. So far, I > have been unable to find a suitable answer. Our needs are pretty basic. > FTP & TELNET are being removed from our environment and I need to > utilize SFTP for file transfers. > > As is probably said often, I am new to Python (love it) and need a > solution that provides adequate examples and documentation. I am hoping > for an open source answer, however, I am not ruling out having to > purchase something. > > Can anyone shed some light on this for me ? > Strange the second hit on a google for python sftp was this:- http://www.lag.net/paramiko/ I also implemented (using pexpect) a very basic 'interface' to command line sftp) http://pexpect.sourceforge.net/ pexpect is *nix only (as far as I know) both of these come with simple to follow examples... Martin. -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner question: Logs?
Robert Kern wrote: > Greg Ewing wrote: [about the "from xxx import *" syntax] >> Better still, don't even *mention* it to a beginner. >> They don't need to know about it. At all. Really. > > Well, the OP's use is precisely why "from xxx import *" exists: the > interactive prompt. In that case (and, really, any time) Terry's solution is quite suitable and an excellent substitute. Even at the interactive prompt some of the dangers (mostly the potential for name collisions) of "from xxx import *" are still present. -Peter -- http://mail.python.org/mailman/listinfo/python-list
SFTP
Title: Message Good Morning I have scoured the internet looking for an Python SFTP API. So far, I have been unable to find a suitable answer. Our needs are pretty basic. FTP & TELNET are being removed from our environment and I need to utilize SFTP for file transfers. As is probably said often, I am new to Python (love it) and need a solution that provides adequate examples and documentation. I am hoping for an open source answer, however, I am not ruling out having to purchase something. Can anyone shed some light on this for me ? Best Regards,___Rick Kornfeld -- http://mail.python.org/mailman/listinfo/python-list
Problem calling Python methods from C
Hello everyone, I'm trying to do something in C calling Python and its failing. I'd be grateful if you could take a look and hopefully you have an answer. What I'm trying to do is determine the address of the "collect" function in the "gc" module. I want to do this so that we can determine when a garbage collection happens, regardless of how it is triggered (explicitly by a user call, or implicitly by the behaviour of the program allocating lots of data). As far as I can tell, the gc.collect function is not exposed as a C API, so I cannot hook that to do the monitoring I want. Therefore the only way to get the address to hook is to inspect the Python module function dictionaries, well I think its the only way :-) The approach is to get the module that holds "gc". You can do this by calling PyImport_AddModule for an existing module - it will return it. Then you get the dictionary of methods from the module and lookup the method in there. Well, that was my theory after looking at the Python source code. I've shown the source code below. // get "collect" method from GC module // this module should always be present // as it is a fundamental part of Python PyObject*module; DWORD funcAddress = NULL; module = PyImport_AddModule("gc"); if (module != NULL) { // get dictionary of methods for this module PyObject*dict; dict = PyModule_GetDict(module); if (dict != NULL) { // lookup "collect" in the dictionary PyObject*func; int numItems; // check we have some elements, // strangely there are only 2 numItems = PyDict_Size(dict); // this works, good, that is expected func = PyDict_GetItemString(dict, "__name__"); // this fails, why? "collect" is a method in "gc" // I would expect it to work func = PyDict_GetItemString(dict, "collect"); } } Hopefully someone can shed some light on why this doesn't work, or explain what the correct method should be if I am doing the wrong thing. Answers as descriptions, Python or C most welcome. Cheers Stephen -- Stephen Kellett Object Media Limitedhttp://www.objmedia.demon.co.uk/software.html Computer Consultancy, Software Development Windows C++, Java, Assembler, Performance Analysis, Troubleshooting -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse.py: FutureWarning error
John Machin wrote: > Michael Hoffman wrote: > >> Terry Reedy wrote: >> >>> c) Check to see if Python has a startup option for suppressing warnings >>> >>> As to c) python -h gives a list indicating what I thought, that -W >>> controls warnings, but gives insufficient info for me to use it, and >>> I didn't find any more in the docs. I hope someone else chimes in. >> >> >> >> man python. Search for -W. > > > """ > C:\junk>man python > 'man' is not recognized as an internal or external command, > operable program or batch file. > """ Well it's obviously not going to work if you don't install man. """ C:\Documents and Settings\MichaelH>man python PYTHON(1) NAME python - an interpreted, interactive, object-oriented programming language """ Here's a copy of the man page: http://linuxcommand.org/man_pages/python1.html -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting Time
quoth the Ognjen Bezanov: > I never thought id need help with such a thing as time formatting > (admittadly i never did it before) but ok, i guess there is a first for > everything. > > I have a float variable representing seconds, and i want to format it > like this: > > 0:00:00 (h:mm:ss) > > Now search as I might i am finding this quite elusive, i had a look at > the time module but that seems overly complicated for this. Anyone got > any simple solutions to doing this? cheers! def printTime(seconds): hours = seconds / 3600 seconds = seconds - (hours * 3600) minutes = seconds / 60 seconds = seconds - (minutes * 60) print "%i:%s:%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2)) I am certainly no pro at python but this seems to do it for me. I am sure someone could write it much more elegantly. I am still a little confused as to how you have a float that represents seconds? This will only work if 'seconds' is an int ( al la ' 44342865') but maybe it could help you? -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 pgp6I7q4f3fVW.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
RE: Formatting Time
> -Original Message- > From: Ognjen Bezanov [mailto:[EMAIL PROTECTED] > Sent: 03 June 2005 09:30 > To: python-list@python.org > Subject: Formatting Time > > I never thought id need help with such a thing as time > formatting (admittadly i never did it before) but ok, i guess > there is a first for everything. > > I have a float variable representing seconds, and i want to > format it like this: > > 0:00:00 (h:mm:ss) > > Now search as I might i am finding this quite elusive, i had > a look at the time module but that seems overly complicated > for this. Anyone got any simple solutions to doing this? cheers! > c:\Python24\programs>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> t=36100.0 >>> time.strftime('%H:%M:%S',time.gmtime(t)) '10:01:40' >>> Steve ** The information contained in, or attached to, this e-mail, may contain confidential information and is intended solely for the use of the individual or entity to whom they are addressed and may be subject to legal privilege. If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager. Please do not copy it for any purpose, or disclose its contents to any other person. The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company. The recipient should check this e-mail and any attachments for the presence of viruses. The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email. ** -- http://mail.python.org/mailman/listinfo/python-list
Re: decimal and trunkating
"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Peter Hansen wrote: > > Reinhold Birkenfeld wrote: > >> He is speaking of Decimals... > >> > >> d = Decimal("199.999") > >> d._round(5, decimal.ROUND_DOWN) > > > > Is one really supposed to call the underscore methods like that? > > Umm... no, I think not ;) But I couldn't find something better. > > Reinhold I'm new to Python ... and I've used decimal._round() as above. What's the deal with using underscore methods? (A link will do if that'll save you some typing). -- http://mail.python.org/mailman/listinfo/python-list
Re: optparse.py: FutureWarning error
Terry Reedy wrote: > "kosuke" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>man python --- >> >>COMMAND LINE OPTIONS > > > This should REALLY be on the doc page of the Python site. Hear, hear! I never even knew this existed! Where should it go in the docs? In the Language Reference or the Tutorial or...? Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: metaclass that inherits a class of that metaclass?
You should read the metaclass book, if you can find it. For the reference, see http://www-106.ibm.com/developerworks/linux/library/l-pymeta.html http://www-128.ibm.com/developerworks/linux/library/l-pymeta2/index.html Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: calling ksh script from python
* Cameron Laird (2005-06-02 18:08 +0100) > In article <[EMAIL PROTECTED]>, > Donn Cave <[EMAIL PROTECTED]> wrote: >>Meanwhile, it might be worthwhile to reconsider the use >>of ksh here, if you have any choice in the matter. Ksh >>is fine for interactive use, but has some unfortunate >>flaws as a programming shell, and due to proprietary issues >>one commonly encounters an alternative implementation that's >>even worse. On most modern platforms, sh will have a pretty >>good programming feature set, and will be more reliable >>(especially if it isn't just ksh by another name.) > . > Infidel. While I sure feel that way about csh(1), it > surprises me you'd criticize ksh(1) so. 'Fact, 'mong > all the *sh-s, I *recommend* ksh for programming. May- > be the two of us see things differently. http://groups-beta.google.com/group/comp.unix.shell/msg/98578e8d95137a3c -- http://mail.python.org/mailman/listinfo/python-list
Re: Information about Python Codyng Projects Ideas
"M1st0" <[EMAIL PROTECTED]> writes: > I hope that here is the right place for this kind of discussion. There's a new mailing list [EMAIL PROTECTED] which is probably more appropriate for specifics, but this list is probably OK for general discussion. Cheers, mwh -- Solaris: Shire horse that dreams of being a race horse, blissfully unaware that its owners don't quite know whether to put it out to grass, to stud, or to the knackers yard. -- Jim's pedigree of operating systems, asr -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Kiosks Serve The World
[EMAIL PROTECTED] wrote: > Jeff_Relf wrote: > > >>As I've told you a quintillion times, Earthlink's insanity aside, >>Win_XP is a virtual network, quite indepent of the connection used. >>Linux is hardly an OS, it's just a kernel. > > > The world doesn't need a 'virtual network'...it needs an Internet Kiosk. > > While Jeff the Bolshevik was sleeping; American Capitalism produced what the > Governments of India, Africa and China could not: A $69 Internet Kiosk from > which they can derive Knowledge, Commerce and Society. > > Yes, listen here World Bank, Unicef, UN, Bono, Gate$ Foundation: > > Do you want the world to have computers? > > Then cough up $69 a head to Microtek and have them send it Ground Freight to > Burkina Faso, Outer Mongolia and Bangalore. > > As for 'virtual networks' -- yes, virtual in the sense of not being > real...in the sense of not having substance. Yes. virtual. > Since this appears to have nothing at all to do with Python, perhaps you guys could go and fight in some other corner of the playground? heard-it-all-before-ly y'rs - steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: metaclass that inherits a class of that metaclass?
infidel wrote: > Ok, forget everything I've said. The more I think about this the less > I understand it. I'm way out of my league here. > > sitting-down-and-shutting-up-ly y'rs, > > Well, that's a sign of maturity right there ;-) some-people-just-don't-know-when-to-ly y'rs - steve -- Steve Holden+1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: odbc and python
Giles Brown schrieb: > MM wrote: > >>Are there any other odbc packages other than the win32all and mxodbc >>ones? The win32all odbc.pyd can't access table structure info like >>SQLColumns, and mxobdc requires a commercial license which is >>unjustifiable for this tiny project. Any other OS alternatives for >>win32?. Thanks. > > > You could potentially make the ODBC calls using ctypes a la: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303667 > > Not tried this myself and imagine it could be a bit tedious. > > Cheers, > Giles > If someone wants to try this approach (personally, I don't use databases), it seems that the tools provided with ctypes, if you have gccxml (and MSVC) installed, should give a good start. Running h2xml windows.h sql.h -o sql.xml -c and xml2py sql.xml -rSQL.* -o sql.py -lodbc32 -d creates a 830 lines Python module, containing a lot of useful SQL stuff, which can be hacked on. To give an impression, the file starts with the following lines, so a lot of constants and datatypes are already defined: # generated by 'xml2py' # flags 'sql.xml -rSQL.* -o sql.py -lodbc32 -d -m ctypes.com' from ctypes import * SQL_DATETIME = 9 # Variable c_int SQL_MAX_USER_NAME_LEN = 107 # Variable c_int SQL_DEFAULT_TXN_ISOLATION = 26 # Variable c_int SQL_API_SQLFREEHANDLE = 1006 # Variable c_int SQL_ALTER_TABLE = 86 # Variable c_int SQL_IS_DAY_TO_SECOND = 10 SQL_API_SQLCOLUMNS = 40 # Variable c_int SQL_TXN_READ_UNCOMMITTED = 1 # Variable c_long SQL_TRANSACTION_READ_UNCOMMITTED = SQL_TXN_READ_UNCOMMITTED # alias SQL_DBMS_NAME = 17 # Variable c_int SQLSMALLINT = c_short SQLRETURN = SQLSMALLINT SQLHANDLE = c_void_p SQLHDBC = SQLHANDLE SQLUSMALLINT = c_ushort @ stdcall(SQLRETURN, 'odbc32', [SQLHDBC, SQLUSMALLINT, POINTER(SQLUSMALLINT)]) def SQLGetFunctions(p1, p2, p3): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/sql.h 735 return SQLGetFunctions._api_(p1, p2, p3) SQL_TRUE = 1 # Variable c_int SQLHSTMT = SQLHANDLE SQLCHAR = c_ubyte UDWORD = c_ulong @ stdcall(SQLRETURN, 'odbc32', [SQLHSTMT, SQLUSMALLINT, POINTER(SQLCHAR), SQLSMALLINT, POINTER(SQLSMALLINT), POINTER(SQLSMALLINT), POINTER(UDWORD),POINTER(SQLSMALLINT), POINTER(SQLSMALLINT)]) def SQLDescribeCol(p1, p2, p3, p4, p5, p6, p7, p8, p9): # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/sql.h 650 return SQLDescribeCol._api_(p1, p2, p3, p4, p5, p6, p7, p8, p9) SQL_DROP = 1 # Variable c_int SQL_DATA_SOURCE_NAME = 2 # Variable c_int SQL_TXN_SERIALIZABLE = 8 # Variable c_long SQL_TRANSACTION_SERIALIZABLE = SQL_TXN_SERIALIZABLE # alias Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: calling ksh script from python
thanks for your input... well I just find out that modifying environment through ksh call is not possible (can't get the new evironment back to python). I think the best thing to do is to translate all my ksh to pure python... I thought that I could re-use some stufff, but I guest I'm going to translate everything... -- http://mail.python.org/mailman/listinfo/python-list
Re: [python-gtk] problem with multiple inheritance
Greg Ewing wrote: > Taki Jeden wrote: > >> class view_tree_model(gtk.GenericTreeModel,gtk.TreeSortable): >> >> raises a "TypeError: multiple bases have instance lay-out conflict" >> Is this a bug in gtk, or python-gtk, or something? > > It's not a bug, it's a limitation of the way Python > handles inheritance from built-in types. You can only > inherit from more than one built-in type if they have > compatible C structures, and it appears that the two > you're trying to inherit from aren't compatible. > > You'll have to think of some way of doing whatever > you're trying to do without inheriting from multiple > gtk types. > Ok, but the code isn't mine - it is tinyERP (tinyerp.org). And people are running it, that's why I assume the problem is not in the code. BG -- Zamiast sensownej sygnatury...: | http://www.safetycam.pl | http://www.bpcc.org.pl/en,0,0.html | http://www.spoko.neostrada.pl | http://www.gorny.najlepsze.pl/imiona -- http://mail.python.org/mailman/listinfo/python-list
Re: read input for cmd.Cmd from file
Achim Domma (Procoders) wrote: > I'm writing a simple shell using cmd.Cmd. It would be very usefull if I > could read the commands as batchjob from a file. I've tried the following: [...] Your original approach should work too if you clear the use_rawinput flag and provide a do_EOF() method that handles the file end: import cmd class Cmd(cmd.Cmd): def do_this(self, arg): print "this>", arg def do_that(self, arg): print " http://mail.python.org/mailman/listinfo/python-list
Re: Console Scripts
On 3 Jun 2005 01:21:04 -0700, Prema <[EMAIL PROTECTED]> wrote: > Just something which will be a simple answer for someone . > With an interactive python script, sometimes it seems necessary to > clear the terminal in order to provide a clear presentation to users > > With Bash then we just do a 'clear' statement but this does not seem to work > well in python. http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3edf6589c533f78e -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Formatting Time
I never thought id need help with such a thing as time formatting (admittadly i never did it before) but ok, i guess there is a first for everything. I have a float variable representing seconds, and i want to format it like this: 0:00:00 (h:mm:ss) Now search as I might i am finding this quite elusive, i had a look at the time module but that seems overly complicated for this. Anyone got any simple solutions to doing this? cheers! -- http://mail.python.org/mailman/listinfo/python-list
Console Scripts
Hi People ! Just something which will be a simple answer for someone . With an interactive python script, sometimes it seems necessary to clear the terminal in order to provide a clear presentation to users With Bash then we just do a 'clear' statement but this does not seem to work well in python. There must be something we are missing ! Tnanks for any tips Kind regards Mike -- http://mail.python.org/mailman/listinfo/python-list