Slightly OT: Why all the spam?
Does anyone know why we get so much spam to this group? It's starting to get embarrasing to read at work and that's just not how it should be. Cheers! /Joel -- http://mail.python.org/mailman/listinfo/python-list
Re: howto check does module 'asdf' exist? (is available for import)
On May 21, 11:17 pm, dmitrey <[EMAIL PROTECTED]> wrote: > howto check does module 'asdf' exist (is available for import) or no? try : import asdf del asdf except ImportError : #do stuff ... > (without try/cache of course) Oops sorry, you didn't want it the obvious way ... but why ever not? -- http://mail.python.org/mailman/listinfo/python-list
Re: i/o prob revisited
[EMAIL PROTECTED] wrote: > >ok i am able to trace the error ...It says: >Traceback (most recent call last): > File "C:\Projects\ODX Import\code_ini\odxparse_mod.py", line 294, in > >input_xml_sec = open(output_file,'r') >TypeError: coercing to Unicode: need string or buffer, file found >Any solutions. I don't see how the error could possibly make it any clearer. "open" expects a file name. "output_file" is not a file NAME. It is a file OBJECT. If you want to reopen that file, then pass the file NAME here. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter button state = DISABLED
"Hamilton, William " <[EMAIL PROTECTED]> wrote: > > From: Eric Brunel > On Thu, 17 May 2007 09:30:57 +0200, Hendrik van Rooyen > > <[EMAIL PROTECTED]> wrote: > > > "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > >> En Wed, 16 May 2007 03:22:17 -0300, Hendrik van Rooyen > > >>> I have never seen this working in Tkinter, unless the button was > > >>> pressed > > >>> on the > > >>> widget > > >>> in question - and worse, once you have clicked down on a ButtonRelease > > >>> binding > > >>> you can move the mouse pointer anywhere you like, even out of the > > >>> application > > >>> and when you release it, the bound function is called... > > >>> > > >>> Its either a bug or a feature, I don't know. > > >> > > >> Uhmm... I'm not sure I understand you completely. I only said that the > > >> "command" is fired only when the mouse button is pressed on the widget, > > >> AND released inside the same widget. If both events don't happen in the > > >> same widget, "command" won't fire. Maybe you are saying the same > > >> thing... > > >> anyway I'm not a Tk expert. > > > > > > No command is ok and you have described it right - its ButtonRelease > > that > > > seems broken to me > > > > Apparently, this behaviour is the intended one, at least for buttons; see: > > http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M11 > > > > As for the question "why?", maybe you should ask it on the c.l.tcl > > newsgroup? > > The difference between bind and the button's command parameter makes sense > to me. You'd use bind to create something like a right-click menu, where > you want the same thing to happen whether the button is disabled or not. > You use the command parameter when you care about the state of the button. > That is a good point. What I was actually nattering on about was the unexpected behaviour of the ButtonRelease binding - from its name, you would expect it to call the bound function when a click is released on the button. It does not do that. Having been told that its the expected behaviour, I can imagine it to be useful in "drag and drop" scenarios, to implement something from the source side - a "thrower" - as opposed to the "catcher" type of behaviour that its name suggests. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists vs tuples (newbie)
"Szabolcs" <[EMAIL PROTECTED]> wrote: > > I was wondering about why are there both tuples and lists? Is there > anything I can do with a tuple that I cannot do with a list? > > In what circumstances is it advantageous to use tuples instead of lists? > Is there a difference in performance? > > I am still learning Python, so please be gentle ... On this group you do not have to be afraid - there may be barking, but the bulldogs all have rubber teeth... >From a practical perspective, use lists - they have more methods. When you want to use a list as a key in a dict, then you can't, as keys have to be immutable. So then you convert your list to a tuple and use it as a key. Its the only place I have found where you *have* to use a tuple. You will be told a lot of stuff about lists being for homogenous items, and tuples being records like a C struct. Take note, nod your head, and then ignore it, and put whatever you like into your lists. They are your lists, not someone else's, and you can put in just what you like, and it all works, in spite of whatever the design intention had been. Aside from the hashing issue, there is nothing that a tuple can do that can't be done as well or better by a list. Heretically yours, Hendrik -- http://mail.python.org/mailman/listinfo/python-list
converting text and spans to an ElementTree
I have some text and a list of Element objects and their offsets, e.g.:: >>> text = 'aaa aaa aaabbb bbbaaa' >>> spans = [ ... (etree.Element('a'), 0, 21), ... (etree.Element('b'), 11, 18), ... (etree.Element('c'), 18, 18), ... ] I'd like to produce the corresponding ElementTree. So I want to write a get_tree() function that works like:: >>> tree = get_tree(text, spans) >>> etree.tostring(tree) 'aaa aaa aaabbb bbbaaa' Perhaps I just need some more sleep, but I can't see an obvious way to do this. Any suggestions? Thanks, STeVe -- http://mail.python.org/mailman/listinfo/python-list
^? Ron Jeremeys Dick Gets Longer!
http://stentorinternet.info - Animated Flash on Ron jeremies dick stuffin a young 19yr old chick. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use private method in a class
On May 21, 9:49 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to write a python class with a new data type such as: > class Cc14: >def __init__(self, realpart, imagpart): > self.r=realart > self.i=imagpart > >def __saturator(x): > return x+1 >def out(self,x): > return Cc14(__saturator(x.r), __saturator(x,i)) > > When I use the method out such as: > z.out > > Python complains: > > global name '_Cc14_saturator' is not defined. > > Is the way put two underscore in front of the definitio making the method > becomes private? > > Why in the same clase, I could not use the __saturator method? > > Thanks > > Frank > It seems you have several issues here: (1) To avoid syntax errors, self.r=realart should be: self.r=realpart (2) Your __saturator method definition needs the reference to self: def __saturator(self, x): (3) And lastly, the body of the out() method needs two corrections: return Cc14(self.__saturator(x.r), self.__saturator(x.i)) Is it really necessary to "privatize" the saturator method? In Python, all class methods are public and visible by default. A method name __methodname in a class "foo" turns into "_foo__methodname" in an instance of the class. This is known as name mangling. It is simply a convention supported by Python when a class attribute name begins with two underscores. It prevents a programmer from calling something like C.__saturator(arg), but still allows calling C._Cc14__saturator(arg). IMHO, you could just leave the saturator definition as "def saturator(self, x):" Anyway, in your case the 3 fixes above will allow you now to do this: >>>C = Cc14(2,3) >>>result = C.out(C) >>>result.r, result.i (3, 4) Which is beginning to look like your design intent.. Cheers, -Basilisk96 -- http://mail.python.org/mailman/listinfo/python-list
Re: Types in Python (was: managed lists?)
On May 22, 10:28 am, Ben Finney <[EMAIL PROTECTED]> wrote: > "Jorgen Bodde" <[EMAIL PROTECTED]> writes: > > Right now i have a list in a class that I export as a member > > variable to the outside world, it is a standard list (e.g. [] ) but > > I wish to have a stronger type checking when adding objects, that > > only some objects are allowed and others are not. > > This is a poor idiom in Python. The object system allows powerful > polymorphism: the only thing that your application should be checking > is if the objects *can be used* in a particular way, not that they > belong to a specific subset of the type hierarchy. And this very succintly sums up the nature of Python's polymorphism by interface (duck-typing). An understanding of this is central to groking the way typing and OO are done in python. "Jorgen Bodde" <[EMAIL PROTECTED]> writes: > I solved it now, by using isinstance() and giving the class name as > argument to the list There may be some situations in which testing for class (or inheritance) are appropriate, however in the vast majority of cases doing so is a mistake. The object should itself know what to do in any given situation (or throw an exception if it doesn't). Similarly your program should be responding to exceptions rather than checking before hand whether its OK to go on. Instead of reaching for 'isinstance()' you should probably be using 'try : ... except: ...' > and it sometimes frustates me to no end that a wrongly given > argument explodes somewhere deep inside my application without > giving any clue why it blew up in the first place.. If by 'explode' you mean spitting out feedback (as opposed to hanging), you should find at least a few clues. At the very least, you now know one of the exceptions your code will need to handle. Asun -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
jay wrote: > > Anyway, I had one more quick question... in order to run wxPython apps, > do I have to have MacPython, etc. loaded on each Mac (or PC) in order > for it to run any apps I write? Or is there a way to compile the code > to where I can distribute an app I write and the other users don't need > to load anything in order to run the app? Google for "py2app." It's the standard tool for distributing standalone Python apps on OS X. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
> After this I went to the tutorial and started trying out some of the > examples. I pasted the code to separate text files and then ran them > through a Terminal window. This stuff is freaking cool!!! Now I > just have to figure out how this all works! > "wxPython in Action" is a decent book for learning wxPython: http://www.manning.com/rappin/ As with any GUI toolkit, there is a learning curve until you get used to how the components work together. But there is enough hands-on material to get started with simple GUI apps. > Anyway, I had one more quick question... in order to run wxPython > apps, do I have to have MacPython, etc. loaded on each Mac (or PC) in > order for it to run any apps I write? Or is there a way to compile > the code to where I can distribute an app I write and the other users > don't need to load anything in order to run the app? Again, I can't speak for Macs, but I know that for Windows there is one package suitably called "py2exe", available from http://www.py2exe.org/ which allows you to freeze your code and distribute it to multiple users as an executable file plus some extra baggage files containing bytecode and necessary DLL's, including the Python interpreter itself. This way, the end user does not need to install Python, wxPython, or any other Python libraries used by your project, nor does the end user even need to know anything about Python. Pros? The app is ready to run as shipped. Cons? Relatively large size of the distributable package - a typical simple GUI app is 6MB+ when packaged this way. Although... with the acres of storage space available on today's media, this is hardly a problem. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Types in Python (was: managed lists?)
On May 22, 10:28 am, Ben Finney <[EMAIL PROTECTED]> wrote: > "Jorgen Bodde" <[EMAIL PROTECTED]> writes: > > Right now i have a list in a class that I export as a member > > variable to the outside world, it is a standard list (e.g. [] ) but > > I wish to have a stronger type checking when adding objects, that > > only some objects are allowed and others are not. > > This is a poor idiom in Python. The object system allows powerful > polymorphism: the only thing that your application should be checking > is if the objects *can be used* in a particular way, not that they > belong to a specific subset of the type hierarchy. And this very succintly sums up the nature of Python's polymorphism by interface (duck-typing). An understanding of this is central to groking the way typing and OO are done in python. "Jorgen Bodde" <[EMAIL PROTECTED]> writes: > I solved it now, by using isinstance() and giving the class name as > argument to the list There may be some situations in which testing for class (or inheritance) are appropriate, however in the vast majority of cases doing so is a mistake. The object should itself know what to do in any given situation (or throw an exception if it doesn't). Similarly your program should be responding to exceptions rather than checking before hand whether its OK to go on. Instead of reaching for 'isinstance()' you should probably be using 'try : ... except: ...' > and it sometimes frustates me to no end that a wrongly given > argument explodes somewhere deep inside my application without > giving any clue why it blew up in the first place.. If by 'explode' you mean spitting out feedback (as opposed to hanging), you should find at least a few clues. At the very least, you now know one of the exceptions your code will need to handle. Asun -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
Wow!! Thanks so much for your quick and helpful replies! I really appreciate it!! :-) I tried installing off 'wxPython2.8-osx-ansi-2.8.4.0-universal10.4- py2.5.dmg' on my OS 10.4.9 system which wouldn't install. So I installed off 'python-2.5-macosx.dmg' and then installed off 'wxPython2.8-osx-ansi-2.8.4.0-universal10.4-py2.5.dmg' which seemed to work. I find the instructions confusing as to what to install. After this I went to the tutorial and started trying out some of the examples. I pasted the code to separate text files and then ran them through a Terminal window. This stuff is freaking cool!!! Now I just have to figure out how this all works! Anyway, I had one more quick question... in order to run wxPython apps, do I have to have MacPython, etc. loaded on each Mac (or PC) in order for it to run any apps I write? Or is there a way to compile the code to where I can distribute an app I write and the other users don't need to load anything in order to run the app? Thanks again for your help with all this. I really appreciate you all taking the time to look and answer our questions. Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
> 2. Is there a good book to start with while learning Python? I'm > currently reading 'Python Essential Reference' by David M. Beazley. > So far it looks like a pretty good book, but would like more > tutorials to work with (I've also been reading through the tutorials > at 'python.org' which has some excellent stuff!). Take a walk through the text "How to Think Like a Computer Scientist": http://www.ibiblio.org/obp/thinkCSpy/ It's medium-paced, well-organized, and - quite importantly IMHO - builds well on knowledge acquired in the previous chapters as it progresses. There are plenty of hands-on examples; and really, the text was written by a high school teacher for a CS curriculum, so it's structured more like a tutorial. I found it to be priceless when I first got interested in Python, and I would highly recommend it to any newbie, whether with previous programming experience or not, but who has never laid eyes on Python before. As I think back on it, the book gives you just enough information to make you hungry for more - and indeed, after reading it I had enough insight to explore Python on my own and started writing useful programs by myself. > > 3. Currently, I write most of my code with Xcode (on the Mac > platform) using Applescript. This gives me GUI capabilities. Is > there anything you'd recommend that I could use for Python that would > give me a GUI interface? I'd like this to be able to work for both > the Mac and Windows platforms. I've been reading a little about > 'Claro Graphics Toolkit' and 'PyGUI'... would you recommend either of > those? I'll be writing code on a Mac so I need something that will > run on that system. > Try wxPython. I've seen it run on a Mac with OS X and Windows simultaneously, where the operating systems were switched from one to the other at the touch of a button, and the GUI had a very native look in either platform (mind you, the app was running exactly the same code in both cases!). I write my code on a win32 box, so I have no further pointers for you regarding a Mac. -Basilisk96 -- http://mail.python.org/mailman/listinfo/python-list
how to use private method in a class
Hi, I am trying to write a python class with a new data type such as: class Cc14: def __init__(self, realpart, imagpart): self.r=realart self.i=imagpart def __saturator(x): return x+1 def out(self,x): return Cc14(__saturator(x.r), __saturator(x,i)) When I use the method out such as: z.out Python complains: global name '_Cc14_saturator' is not defined. Is the way put two underscore in front of the definitio making the method becomes private? Why in the same clase, I could not use the __saturator method? Thanks Frank >From: "wang frank" <[EMAIL PROTECTED]> >To: python-list@python.org >Subject: A newbie question >Date: Mon, 21 May 2007 23:04:06 + > >Hi, > >I am trying to write a python class with a new data type such as: >class Cc14: >def __init__(self, realpart, imagpart): > self.r=realart > self.i=imagpart > >def __add__(self,x): > return self.r+x,r, self.i+x.i > >If I have >x=Cc14(4,5) >y=Cc14(4,5) >z=x+y > >z will be a tuple instead of Cc14. How can I return a Cc14 class? > >Thanks >Frank > >_ >ウェブページを印刷しても途切れない!便利なブラウザ MSN版IE7 を使おう >http://promotion.msn.co.jp/ie7/ > >-- >http://mail.python.org/mailman/listinfo/python-list _ オンライン地図マガジン「地図マガ」創刊!全国水族館マップを特集 http://chizumaga.jp/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On May 21, 10:50 am, brad <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Just wondering on what peoples opinions are of the GUIs avaiable for > > Python? > > We have used wxPython with great results. It's cross platform. Can use > native OS widgets and is easy to program. Compiles easily to exe > binaries for Windows users as well. > > Best of luck, > Brad I don't recoment gtk because it doesn't install well on python 2.5 on windows. It is a shame because it has alot of realy nice 3d packages. I would stick with wxpython and tkinter for general use gui use there are other options for the high tek 3d stuff -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
Christopher Arndt wrote: > I have a few quibles with your summary of Python's properties: > On 21 Mai, 08:16, John Nagle <[EMAIL PROTECTED]> wrote: >> Memory management >> is safe and managed by reference counts backed by a garbage collector. >> Weak references are supported. Built in data types are numerics, ASCII >> and Unicode strings, dynamic arrays, fixed size tuples, and hashes. > > Python lists are much more than arrays. More like a linked list. > You forgot sets. And functions, classes, methods, instances (see > above) Python lists are implemented as C arrays that are resized as necessary. - Josiah -- http://mail.python.org/mailman/listinfo/python-list
Re: Cycle detection and object memory usage?
Gabriel Genellina wrote: > En Sun, 20 May 2007 23:54:15 -0300, Jim Kleckner <[EMAIL PROTECTED]> > escribió: > >> I understand from the documentation that types with a finalizer method >> that participate in cycles can't be collected. > > Yes; older Python versions could not manage any kind of cycles, now only > objects with __del__ cause problems. > You can explicitely break the cycle (removing the reference, ensuring that > some finalization method is always called, maybe using try/finally) or you > may use weak references (by example, in a tree-like structure, a node > might hold a weak reference to its parent). > >> What is the best way to go about finding these cycles? >> Googling gives a variety of methods none of which seem terribly >> mainstream for such a common problem. > > Avoid them in the first place :) > Use the gc module: after a call to gc.collect(), see if something remains > in gc.garbage I would have sworn that there were uncollectable objects when I tried this before. Now they don't show up. I guess that is good... Which leads to >> Object memory usage: >> >> Has anyone written a function to sweep out an object to discover how >> much memory it and all the objects it references is using? This would >> be great for performance tuning. > > A rough estimate may be the object's pickle size. But it's hard to measure > precisely; by example, strings are immutable and you may have thousands of > shared references to the same string, and they require just a few bytes > each. Good idea, thanks. I take it then that memory profiling isn't available? -- http://mail.python.org/mailman/listinfo/python-list
Re: Components for a client/server architecture
Samuel wrote: > On Mon, 21 May 2007 12:06:50 +0200, Diez B. Roggisch wrote: > >> I'm not sure which configuration you want to change how often. But I'm >> not convinced that the python threading limitations really do make a >> difference here. Do you really benefit from multi-core capabilities in >> this scenario? > > The threading issues are not bound to multi cpu systems. The problem is > that some of Python's blocking functions require holding the global lock. > > "Not all built-in functions that may block waiting for I/O allow other > threads to run." > "It is not possible to interrupt the acquire() method on a lock" > http://docs.python.org/lib/module-thread.html You really should read the source. static PyObject * lock_PyThread_acquire_lock(lockobject *self, PyObject *args) { int i = 1; if (!PyArg_ParseTuple(args, "|i:acquire", &i)) return NULL; Py_BEGIN_ALLOW_THREADS i = PyThread_acquire_lock(self->lock_lock, i); Py_END_ALLOW_THREADS return PyBool_FromLong((long)i); } That snippet of code shows that acquiring a lock does release the GIL. Whether or not you are able to interrupt the underlying operating system lock acquisition is platform dependent (on *nix, you can signal anything to die). Now, whether or not some other code does or does not release the GIL depends on its implementation. However, having used threads on Windows and Linux, with files, sockets, databases, etc., I haven't ever experienced a case where the threads did something that wasn't reasonable except in once case*. > I also found that IronPython does not have a global lock, so far it seems > well suited for solving the problems I am trying to avoid. I am still > looking for a good comparison between IronPython, Python, and Jython. From what I've been reading over the last couple years, IronPython is relatively competitive with Python, being faster or slower depending on the things you are doing. Jython is syntactically limited to Python 2.2 at present, so if you want decorators, descriptors, etc., you are out of luck. >> Sounds like CORBA to me. CORBA has a very mature and good implementation >> for Python called OmniORB, and interoperability with other orbs (the >> ones available for e.g. Java) is very good - as CORBA as standard is >> mature. > > I have worked with Bonobo (an implementation of CORBA) before, though not > on the network - it is fairly complex. But I did not think of using it > for this purpose, it might actually make sense. I'll have to look into > the transport protocol more. You should also consider XML-RPC. Setting up and using XML-RPC in Python is quite easy (see the recipes in the Python cookbook), both as a server and client. If you are thinking about running the server in Jython or IronPython anyways, you can always use the standard library XML-RPC libraries from Python, aside from the sockets stuff, it's all in Python. - Josiah * That one case was with mixing a 3rd party library that seemed to have an incomplete Python wrapping that caused values from two thread stacks to be exchanged. The only way I was able to tickle it was with older versions of wxPython + wx.FileConfig + Scintilla + Python's compiler module. -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving class used in pickle
En Mon, 21 May 2007 16:24:55 -0300, Berthold Höllmann <[EMAIL PROTECTED]> escribió: > Jeffrey Barish <[EMAIL PROTECTED]> writes: > >> I have a class derived from string that is used in a pickle. In the new >> version of my program, I moved the module containing the definition of >> the class. Now the unpickle fails because it doesn't find the module. >> I > > You can fiddle with the file class used reading the pickled file. I.e. > the "read()" method could replace each instance of "foo.myclass" by > "greatnewmodule.mynewclass" could bring you back in the game. There is a hook in the pickle module (load_global or find_global) that you can override instead, and it's exactly for this usage, see: http://docs.python.org/lib/pickle-sub.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Types in Python (was: managed lists?)
"Jorgen Bodde" <[EMAIL PROTECTED]> writes: > I still have to get used to the lack of (strong) types, Python does not have weak types, it has strong types. An object knows its type, and the rules on coercion to other types are minimal and well-defined. Python does not have static typing, it has dynamic typing. A name can be bound and re-bound to any type of object through the lifetime of the program. http://www.artima.com/weblogs/viewpost.jsp?thread=7590> or do a web search for: weak strong dynamic static python > and it sometimes frustates me to no end that a wrongly given > argument explodes somewhere deep inside my application without > giving any clue why it blew up in the first place.. I'm not sure what you mean here. The exception raised should say what the problem is; can you give an example of what you're talking about? > Right now i have a list in a class that I export as a member > variable to the outside world, it is a standard list (e.g. [] ) but > I wish to have a stronger type checking when adding objects, that > only some objects are allowed and others are not. This is a poor idiom in Python. The object system allows powerful polymorphism: the only thing that your application should be checking is if the objects *can be used* in a particular way, not that they belong to a specific subset of the type hierarchy. > It was quite easy to create it, but I wonder if there is already a > standard solution for lists that carry only objects of a single > type? Wrap the code that *uses* that list in a 'try: ... except FooError:' structure, to catch and report errors when the objects in the list don't exhibit the correct behaviour. This way, if Frank extends a totally unrelated type so that it behaves as your code expects (e.g. has the appropriate attributes, has methods that respond appropriately), he can insert objects of that type into the list and it will work correctly. > I solved it now, by using isinstance() and giving the class name as > argument to the list This breaks polymorphism: objects of the type Frank created will fail this test, even though they will work perfectly well without that heavy-handed isinstance() restriction. > (thank god that everything in Python is an object ;-) ) where I > check against when adding, but re-inventing the wheel is silly > ofcourse Indeed. Hopefully you will allow for polymorphism in your code. -- \ "Probably the earliest flyswatters were nothing more than some | `\ sort of striking surface attached to the end of a long stick." | _o__) -- Jack Handey | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: python shell/Intermediate Python tools.
In article <[EMAIL PROTECTED]>, Paddy <[EMAIL PROTECTED]> wrote: . . . >Sometimes you have to mess with the case of letters in wiki pages >which is the case here, but I did actually cut-n-paste the address >from Wikipedia as I like to look at the page from time to time as, >like yourself, I think doctest shows the true spirit of what is >Pythonic, and created the page when I found Wikipedia did not have it. So *you* were the one! Nice work--that is, I think we agree (despite my erratic spelling) that doctest deserves plenty of attention, and a Wiki page is a nice place to collect miscellaneous details. . . . >The other Python tool I am apt to carp on about is Kodos >http://kodos.sourceforge.net/ . >Kodos is a great tool for those new to reguar expressions. It allows >you to test your regular expressions on snippets of text and gives >great visual feedback on the results. After over a decade of writing >regexps I still use Kodos occasionally, and wish I had such a tool a >decade ago. Thanks for the tip. You might have an interest in http://regularexpressions.com/#what_is_is >. . . . I've sent copies of this follow-up both to Paddy and, on the chance that the URL will serve others, to comp.lang.python. -- http://mail.python.org/mailman/listinfo/python-list
Re: A newbie question
Thanks all for the help. It solves my problem. I want to build a class type for fixed point operation for a specifc chip. I could not use the build in complex data type. It is a daunting job for me since I has not use python before. Frank >From: Dan Bishop <[EMAIL PROTECTED]> >To: python-list@python.org >Subject: Re: A newbie question >Date: 21 May 2007 16:22:06 -0700 > >On May 21, 6:04 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I am trying to write a python class with a new data type such as: > > class Cc14: > >def __init__(self, realpart, imagpart): > > self.r=realart > > self.i=imagpart > > > >def __add__(self,x): > > return self.r+x,r, self.i+x.i > > > > If I have > > x=Cc14(4,5) > > y=Cc14(4,5) > > z=x+y > > > > z will be a tuple instead of Cc14. How can I return a Cc14 class? > >return Cc14(self.r+x,r, self.i+x.i) > >FYI, Python has a built-in "complex" type. > >-- >http://mail.python.org/mailman/listinfo/python-list _ オンライン地図マガジン「地図マガ」創刊!全国水族館マップを特集 http://chizumaga.jp/ -- http://mail.python.org/mailman/listinfo/python-list
Re: model browser
On Sunday 20 May 2007 10:55, Daniel Nogradi wrote: > Are there other options I overlooked? > > Daniel There is a CRUD template for TG: http://docs.turbogears.org/1.0/CRUDTemplate Might be what you're looking for. j -- Joshua Kugler Lead System Admin -- Senior Programmer http://www.eeinternet.com PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A newbie question
On May 21, 6:04 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to write a python class with a new data type such as: > class Cc14: >def __init__(self, realpart, imagpart): > self.r=realart > self.i=imagpart > >def __add__(self,x): > return self.r+x,r, self.i+x.i > > If I have > x=Cc14(4,5) > y=Cc14(4,5) > z=x+y > > z will be a tuple instead of Cc14. How can I return a Cc14 class? return Cc14(self.r+x,r, self.i+x.i) FYI, Python has a built-in "complex" type. -- http://mail.python.org/mailman/listinfo/python-list
Re: A newbie question
How about this: [code] def __add__(self,x): return Cc14(self.r+x.r, self.i+x.i) [/code] However... Are you aware that Python has built in support for complex numbers already? >>> x = 4+5j >>> y = 4+5j >>> x+y (8+10j) >>> -- http://mail.python.org/mailman/listinfo/python-list
A newbie question
Hi, I am trying to write a python class with a new data type such as: class Cc14: def __init__(self, realpart, imagpart): self.r=realart self.i=imagpart def __add__(self,x): return self.r+x,r, self.i+x.i If I have x=Cc14(4,5) y=Cc14(4,5) z=x+y z will be a tuple instead of Cc14. How can I return a Cc14 class? Thanks Frank _ ウェブページを印刷しても途切れない!便利なブラウザ MSN版IE7 を使おう http://promotion.msn.co.jp/ie7/ -- http://mail.python.org/mailman/listinfo/python-list
Re: converting strings to most their efficient types '1' --> 1, 'A' ---> 'A', '1.2'---> 1.2
py_genetic wrote: > Using a baysian method were my inital thoughts as well. The key to > this method, I feel is getting a solid random sample of the entire > file without having to load the whole beast into memory. If you feel only the first 1000 rows are representative, then you can take a random sample from the first 200-1000 rows depending on how good you think the typing was. At 10,000 bytes per row, you are only reading in a 10MB file if you read 1000 rows. I just timed reading a 28MB file (source tgz file of Open Office 2.0.1) from a local drive at about 1s. As I hope I have demonstrated, you will need only a small random sample from this 200-1000 for testing (maybe 5-15 depending on quality and priors). > What are your thoughts on other techniques? For example training a > neural net and feeding it a sample, this might be nice and very fast > since after training (we would have to create a good global training > set) we could just do a quick transform on a coll sample and ave the > probabilities of the output units (one output unit for each type). > The question here would encoding, any ideas? A bin rep of the vars? > Furthermore, niave bayes decision trees etc? I think these latter ideas require more characterization of your input than is necessary, especially with judicious ordering of simple converter tests. What properties, aside from passing and failing certain converter tests, would you use for the data types? For example, you might use fraction of the string that are integer digits as a property to classify integers. But how many CPU cycles would you spend counting these digits and calculating the fractions for your sample? Do you expect that your data quality is poor enough to warrant expending CPU cycles to quantify the several properties that might characterize each type? However, you might need some advanced learning tools if you want to automatically decide whether a column is a last name or a first name. I'm guessing this is not required and you would only want to know whether to make such a column an int or a string, in which case the testing is pretty straightforward and quick (number of tests per column < 10). I've never converted tables from organizations on a routine basis, but I have a feeling that the quality of these tables are not as poor as one might fear, especially given reasonable foreknowledge of how data types are typically encoded. James -- http://mail.python.org/mailman/listinfo/python-list
Re: List Moderator
Grant Edwards: > To quantify things for curiosity's sake, I just scanned through > the last 1000 postings in c.l.p. There was exactly 1 spam > message and two replies to spam messages complaining about > them. Looking at all my cached messages, I saw 9 including replies. Only one reply went through the mail server to reach me as shown by its headers (such as X-BeenThere: python-list@python.org). The most obvious non-reply *appeared* to be injected into usenet from Google Groups and today's "Boobies" was similar. If you are reading through usenet, spam messages are recognised and expired early - I don't know what mechanism is used for this. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python in a path that contains a blank
On 5/21/07, John Machin <[EMAIL PROTECTED]> wrote: > Is there not a similar trick on MacOS X? It's called a symlink: ln -s /Users/gdonald /foo -- Greg Donald http://destiney.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python in a path that contains a blank
On 21/05/2007 11:30 PM, Konrad Hinsen wrote: > I am trying to install Python from sources in my home directory on a Mac > cluster (running MacOS X 10.4.8). The path to my home directory contains > a blank, and since the installation procedure insists on getting an > absolute path for the prefix, I cannot avoid installing to a path whose > name contains a blank. Python does not seem to be prepared for this, as > it uses only the part before the blank, resulting in numerous error > messages. > > Does anyone know a workaround? > On Windows, the workaround for pesky paths (i.e. containing blanks or just inconveniently long) is the subst command: command-prompt>subst X: "C:\Documents and Settings" Thereafter X:\foo can be used wherever "C:\Documents and Settings\foo" would otherwise be required. Is there not a similar trick on MacOS X? HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: zipfile [module and file format, both] stupidly broken
On Sat, 19 May 2007 17:00:01 + (UTC), Martin Maney <[EMAIL PROTECTED]> wrote: ... > posted here and had so much fun. Apparently I don't speak for most readers here, but I had fun too. Smart, reasonable people write braindead code all the time. I think it's fine when people whine about that once in a while, as long as it's done in an entertaining manner. Less constructive than writing, testing and submitting a patch, but more constructive than slapping your monitor, cursing and doing nothing at all about it. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: [Fwd: Re: managed lists?]
Jorgen Bodde schrieb: > Hi Bruno, > > Thanks for your answer. > > Well what I am after is a list of relations to some class type. And in > that list I do not wish to have accidentally put ints, strings, only > one type of object, or interface. Now I can make the list interface > safe, but it is only meant for relational purposes only. So to > illustrate: > > Song <>>> Tab > Song <>--->> Tuning > > I want a "tabs" collection only consisting of Tab objects. They are > very specific so "mimicing" a tab interface is not something that will > be done anytime soon. > > I'm a traditional C++ programmer, and maybe I go through some > transitional phase I don't know but exposing my list as read / > (over)write property to the "outside world" being the rest of my > object model, is just asking for problems. So this "strong" typed list > will ensure me at "add" time the exception occurs, rather then > somewhere in my applciation who knows much later that something blows > up because the "object" from that list is retrieved and something > unpredictable goes wrong. Is that so weird to do? As I said earlier I > am a python newbie, I love the language, but the fact it can blow up > at unpredictable times, gives me shivers. > >> Everything in Python is an object. Including integers. And there's no >> 'char' type in Python. > > > The array type by the way says in the API that it can be constructed > with a simple type like a char as in a "c" type, an int as in a "i" > type etc.. > > See here: > > http://www.python.org/doc/1.5.2p2/lib/module-array.html > > So what I understand it's purpose is creating a buffer of some kind of > a fixed type to maybe communicate with other DLL's or objects that > require such a thing. > > As I said, I might be going through a transitional phase, but exposing > my relation list as simply a list class where all kinds of objects can > be dumped in, seems too much for me at this point ;-) > > Thanks, > - Jorgen Consider this: Who should add wrong-typed objects (see Bruno's post for reasons why you shouldn't care about types, anyways) to your list, when not you yourself? And if the programmer makes something wrong, he should fix it immediately. What happens if your application throws some error like "invalid type added to ObjectList"? Users won't unterstand it, so the intended audience is you again. Good night, Stargaming -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWBIE: Extending a For Statement.
On May 21, 9:21 am, mosscliffe <[EMAIL PROTECTED]> wrote: > On 21 May, 15:02, [EMAIL PROTECTED] wrote: > > > mosscliffe: > > > > if key in xrange (60,69) or key == 3: > > > I keep seeing again and again code like this, mostly from people not > > much expert of Python, but the PEP 260 shows the fast in was removed, > > so it's O(n). Maybe removing the fast __contains__ was bad for > > necomers (or just the casual Python users, that I belive is really > > large). > > > Bye, > > bearophile > > Being a non-expert in python in fact just a beginner / casual user, > can you expand on how 0(n) relates to > if key in xrange (60,69) or key == 3: the "key in xrange(60,69)" part: all that does is iterate through xrange(60, 69) and when a match is met, it returns true. If it ends up iterating through the whole list without finding a match, it returns false. > My mind tends to go blank at the mention of __xxx__. The above is the default behavior of the 'in' operator. That default behavior can be overridden by a class that has the __contains__ method. So "XXX in YYY" expands roughly to the following (as I understand it; I haven't actually looked it up): if hasattr(YYY, "__contains__"): return YYY.__contains__(XXX) else: for i in YYY: if XXX == YYY: return True return False > R -- http://mail.python.org/mailman/listinfo/python-list
Re: re.compile for names
On 22/05/2007 12:02 AM, Paul McGuire wrote: > On May 21, 8:46 am, brad <[EMAIL PROTECTED]> wrote: >> The goal of the list is to have enough strings to identify files that >> may contain the names of people. Missing a name in a file is unacceptable. >> Seems to me the OP is looking for people-names inside file-contents, not inside file-names. [snip] > You will also get better results if you constrain the location of the > match, for instance, looking for file names that *start* with > someone's name, instead of just containing them somewhere. YMevidentlyV :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: re.compile for names
On 22/05/2007 12:09 AM, brad wrote: > Marc 'BlackJack' Rintsch wrote: > >> What about names with letters not in the ASCII range? > > Like Asian names? The names we encounter are spelled out in English... > like Xu, Zu, Li-Cheng, Matsumoto, Wantanabee, etc. "spelled out in English"? "English" has nothing to do with it. The first 3 are Chinese, spelled using the Pinyin system, which happens to use "Roman" letters [including non-ASCII ü]. They may appear adorned with tone marks [not ASCII] or tone digits. The 4th and 5th [which is presumably intended to be "Watanabe"] are Japanese, using the Romaji system, which ... you guess the rest :-) Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
[Bruno Desthuilliers]> John, I'm really getting tired of your systemic and totally > unconstructive criticism. If *you* are not happy with Python, by all > means use another language. You are saying bad things about my darling! Python is my baby! Shame on you John Nagle, if you do it again I'll really beat you up and if I can't I'll call my brother who really knows CS! Side note: John Nagle contributed several bug reports, bug fixes and discussion about general features of python, pro and con. He is not a brainless fanboy, that is true :)[John Nagle]>>YouTube's home page is PHP. Try "www.youtube.com/index.php".>> That works, while the obvious alternatives don't.>> If you look at the page HTML, you'll see things like > onclick="_hbLink('LogIn','UtilityLinks');">Log In So there's definitely PHP inside YouTube.[Bruno Desthuilliers]> What about learning more on web servers configuration ?> http://zope.alostnet.eu/index.php> > "definitively php", hu ?What about reading what the person you are replying to actually wrote in this thread 3 days ago?http://mail.python.org/pipermail/python-list/2007-May/441376.htmlYou just gotta love the brainless fanboys that breed around each and every programming language :)Puff _ Connect to the next generation of MSN Messenger http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline-- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
Please have a look at Plone and Zope. "During the month of January 2006, we've had approx. 167 million hits" plone.org On 2007-05-16 23:04:17 +0200, Victor Kryukov <[EMAIL PROTECTED]> said: > Hello list, > > our team is going to rewrite our existing web-site, which has a lot of > dynamic content and was quickly prototyped some time ago. > > Today, as we get better idea of what we need, we're going to re-write > everything from scratch. Python is an obvious candidate for our team: > everybody knows it, everybody likes it, it has *real* objects, nice > clean syntax etc. > > Our main requirement for tools we're going to use is rock-solid > stability. As one of our team-members puts it, "We want to use tools > that are stable, has many developer-years and thousands of user-years > behind them, and that we shouldn't worry about their _versions_." The > main reason for that is that we want to debug our own bugs, but not > the bugs in our tools. > > Our problem is - we yet have to find any example of high-traffic, > scalable web-site written entirely in Python. We know that YouTube is > a suspect, but we don't know what specific python web solution was > used there. > > TurboGears, Django and Pylons are all nice, and provides rich features > - probably too many for us - but, as far as we understand, they don't > satisfy the stability requirement - Pylons and Django hasn't even > reached 1.0 version yet. And their provide too thick layer - we want > something 'closer to metal', probably similar to web.py - > unfortunately, web.py doesn't satisfy the stability requirement > either, or so it seems. > > So the question is: what is a solid way to serve dynamic web pages in > python? Our initial though was something like python + mod_python + > Apache, but we're told that mod_python is 'scary and doesn't work very > well'. > > And although http://www.python.org/about/quotes/ lists many big names > and wonderful examples, be want more details. E.g. our understanding > is that Google uses python mostly for internal web-sites, and > performance is far from perfect their. YouTube is an interesting > example - anybody knows more details about that? > > Your suggestions and comments are highly welcome! > > Best Regards, > Victor. -- João Santos [EMAIL PROTECTED] www.thegoldenaura.com -- http://mail.python.org/mailman/listinfo/python-list
Invalid pointer when accessing DB2 using python scripts
Hello, I was wondering if anyone is successfully using using Python(2.5)+DB2+pydb2. I get an error in all situations. It seems that this problem might be limited to python 2.5. A quick Google search suggests that with Python 2.5, memory model has become more stringent and mixing various types of memory calls are likely to produce this error. I am not familiar with writing Python C extensions, but from what I can tell, pydb2 extension is using only one type of memory call. Any workaround besides falling back to python 2.4? It seems pydb2 project isn't very active. I think IBM officially supports only PHP, ruby and perl, does IBM have any plans to support python bindings for DB2? Thanks P Adhia Environment: Ubuntu : Fiesty Fawn Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) DB2 9.1.2 Error: *** glibc detected *** python: free(): invalid pointer: 0xppp *** A simple program to reproduce this error. #! /usr/bin/env python import DB2 con = DB2.connect('ANYDB', 'xx', 'xx') csr = con.cursor() csr.close() con.close() -- http://mail.python.org/mailman/listinfo/python-list
Invalid pointer when accessing DB2 using python scripts
Hello, I was wondering if anyone is successfully using using Python(2.5)+DB2+pydb2. I get an error in all situations. It seems that this problem might be limited to python 2.5. A quick Google search suggests that with Python 2.5, memory model has become more stringent and mixing various types of memory calls are likely to produce this error. I am not familiar with writing Python C extensions, but from what I can tell, pydb2 extension is using only one type of memory call. Any workaround besides falling back to python 2.4? It seems pydb2 project isn't very active. I think IBM officially supports only PHP, ruby and perl, does IBM have any plans to support python bindings for DB2? Thanks P Adhia Environment: Ubuntu : Fiesty Fawn Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) DB2 9.1.2 Error: *** glibc detected *** python: free(): invalid pointer: 0xppp *** A simple program to reproduce this error. #! /usr/bin/env python import DB2 con = DB2.connect('ANYDB', 'xx', 'xx') csr = con.cursor() csr.close() con.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: [Fwd: Re: managed lists?]
Hi Bruno, Thanks for your answer. Well what I am after is a list of relations to some class type. And in that list I do not wish to have accidentally put ints, strings, only one type of object, or interface. Now I can make the list interface safe, but it is only meant for relational purposes only. So to illustrate: Song <>>> Tab Song <>--->> Tuning I want a "tabs" collection only consisting of Tab objects. They are very specific so "mimicing" a tab interface is not something that will be done anytime soon. I'm a traditional C++ programmer, and maybe I go through some transitional phase I don't know but exposing my list as read / (over)write property to the "outside world" being the rest of my object model, is just asking for problems. So this "strong" typed list will ensure me at "add" time the exception occurs, rather then somewhere in my applciation who knows much later that something blows up because the "object" from that list is retrieved and something unpredictable goes wrong. Is that so weird to do? As I said earlier I am a python newbie, I love the language, but the fact it can blow up at unpredictable times, gives me shivers. > Everything in Python is an object. Including integers. And there's no > 'char' type in Python. The array type by the way says in the API that it can be constructed with a simple type like a char as in a "c" type, an int as in a "i" type etc.. See here: http://www.python.org/doc/1.5.2p2/lib/module-array.html So what I understand it's purpose is creating a buffer of some kind of a fixed type to maybe communicate with other DLL's or objects that require such a thing. As I said, I might be going through a transitional phase, but exposing my relation list as simply a list class where all kinds of objects can be dumped in, seems too much for me at this point ;-) Thanks, - Jorgen -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving class used in pickle
Jeffrey Barish wrote: > I have a class derived from string that is used in a pickle. In the new > version of my program, I moved the module containing the definition of the > class. Now the unpickle fails because it doesn't find the module. I was > thinking that I could make the unpickle work by putting a copy of the > module in the original location and then redefine the class by sticking a > __setstate__ in the class thusly: > > def __setstate__(self, state): > self.__dict__.update(state) > self.__class__ = NewClassName > > My plan was to specify the new location of the module in NewClassName. > However, when I do this I get the message "'class' object layout differs > from 'class'". I don't think that they do as the new module is a copy of > the old one. I suspect that I am not allowed to make the class assignment > because my class is derived from string. What is the best way to update > the pickle? The only thought I have is to read all the data with the old > class module, store the data in some nonpickle format, and then, with > another program, read the nonpickle-format file and rewrite the pickle > with the class module in the new location. You could overwrite Unpickler.find_class(): import pickle from cStringIO import StringIO class AliasUnpickler(pickle.Unpickler): def __init__(self, aliases, *args, **kw): pickle.Unpickler.__init__(self, *args, **kw) self.aliases = aliases def find_class(self, module, name): module, name = self.aliases.get((module, name), (module, name)) return pickle.Unpickler.find_class(self, module, name) def loads(aliases, str): file = StringIO(str) return AliasUnpickler(aliases, file).load() if __name__ == "__main__": import before, after data = before.A() print data.__class__, data dump = pickle.dumps(data) data = loads({("before", "A"): ("after", "B")}, dump) print data.__class__, data In the example the aliases dictionary maps (module, classname) pairs to (module, classname) pairs. Of course this only works when the class layout wasn't changed. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: re.compile for names
On 21/05/2007 11:46 PM, brad wrote: > I am developing a list of 3 character strings like this: > > and > bra > cam > dom > emi > mar > smi > ... > > The goal of the list is to have enough strings to identify files that > may contain the names of people. Missing a name in a file is unacceptable. The constraint that you have been given (no false negatives) is utterly unrealistic. Given that constraint, forget the 3-letter substring approach. There are many two-letter names. I have seen a genuine instance of a one-letter surname ("O"). In jurisdictions which don't disallow it, people can change their name to a string of digits. These days you can't even rely on names starting with a capital letter ("i think paris hilton is do u 2"). > > For example, the string 'mar' would get marc, mark, mary, maria... 'smi' > would get smith, smiley, smit, etc. False positives are OK (getting > common words instead of people's names is OK). > > I may end up with a thousand or so of these 3 character strings. If you get a large file of names and take every possible 3-letter substring that you find, you would expect to get well over a thousand. > Is that > too much for an re.compile to handle? Suck it and see. I'd guess that re.compile("mar|smi|jon|bro|wil) is *NOT* the way to go. > Also, is this a bad way to > approach this problem? Yes. At the very least I'd suggest that you need to break up your file into "words" and then consider whether each word is part of a "name". Much depends on context, if you want to cut down on false positives -- "we went 2 paris n staid at the hilton", "the bill from the smith was too high". > Any ideas for improvement are welcome! 1. Get the PHB to come up with a more realistic constraint. 2. http://en.wikipedia.org/wiki/Named_entity_recognition HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On 5/21/07, Paul McNett <[EMAIL PROTECTED]> wrote: > Shameless plug: consider using Dabo on top of wxPython - we feel it > makes wxPython even easier and more pythonic, but admittedly there's a > bit of a learning curve there too. Even though Dabo is a full > application framework originally meant for desktop database > applications, it is modular and you can choose to only use the UI > bits... http://dabodev.com I second this. I used (and struggled!) with wxPython for over a year. The results were great, but I hated coding it. I switched to the Dabo UI wrapper, and stuff that used to take me a day to create is now done in an hour or two. -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
John Nagle a écrit : (snip) >YouTube's home page is PHP. Try "www.youtube.com/index.php". > That works, while the obvious alternatives don't. > If you look at the page HTML, you'll see things like > >onclick="_hbLink('LogIn','UtilityLinks');">Log In > > So there's definitely PHP inside YouTube. What about learning more on web servers configuration ? http://zope.alostnet.eu/index.php "definitively php", hu ? -- http://mail.python.org/mailman/listinfo/python-list
Re: doctest environment question
tag wrote: > On 21 May, 18:53, Peter Otten <[EMAIL PROTECTED]> wrote: >> The doctest code is executed in a module without a __name__, it seems. >> Unfortunately (in this case) the builtin module serves as a fallback >> helping out with its own name: >> >> >>> __name__ >> '__main__' >> >>> del __name__ >> >>> __name__ >> >> '__builtin__' >> >> What to do about it? doctest could be changed to execute code snippets in >> a module with a name and a sys.modules entry though I don't see much >> benefit here. > > Peter, thanks for the quick response, but I don't quite understand > what you're saying. I don't want to change doctest -- I want to find a > way to make my example pass using doctest. The environment that doctest provides is similar to the interactive interpreter but not identical. In particular there is no meaningful __name__. > doctest.testfile comes with lots of parameters, and I suspect if I > knew how to do it I could pass in the correct parameters to make this > example work. It's not what I actually want to document/test, it's a > minimal example which demonstrates the problem. Here are two alternatives: (1) >>> def f(): pass ... >>> del f >>> f() Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined (2) >>> def f(): pass ... >>> del globals()["f"] >>> f() Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined If these don't work you'll have to give a bit more context. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
Ivan Tikhonov a écrit : > Use php. I am lead programmer/maintainer of big website with a lot of > interactive stuff in user's backoffice and with a lot of interraction > to our non-web apps. > > PHP is a crap, but programming for web in python is a pain in the ass. Strange enough, MVHO on this is that PHP is crap *and* that programming "for the web" with it is a king-size PITA, *specially* compared to Python. > And php programmers are cheaper. "cheaper", yes. On an hourly basis. TCO is another problem... > Especialy avoid mod_python. Unless you have to deeply integrate with (and are willing to be forever tied to) Apache, I totally agree on this last one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
On May 16, 4:04 pm, Victor Kryukov <[EMAIL PROTECTED]> wrote: > Hello list, > > our team is going to rewrite our existing web-site, which has a lot of > dynamic content and was quickly prototyped some time ago. See #3 below > Our main requirement for tools we're going to use is rock-solid > stability. As one of our team-members puts it, "We want to use tools > that are stable, has many developer-years and thousands of user-years > behind them, and that we shouldn't worry about their _versions_." > TurboGears, Django and Pylons are all nice, and provides rich features > - probably too many for us - but, as far as we understand, they don't > satisfy the stability requirement - Pylons and Django hasn't even > reached 1.0 version yet. See #3 below > And their provide too thick layer - we want > something 'closer to metal', probably similar to web.py - See #1 below > Your suggestions and comments are highly welcome! Victor et al, I would propose that you ask some different questions. I propose these out of personal experience, much of it from making poor decisions and learning the hard way. Sorry if these sound gruff, I think its hard to avoid when using bullet points; in my mind, these are all being phrased as kindly and gently as I can. #1 Seek flexibility over being "closer to metal." I say this because whenever I've thought I wanted to be closer to metal, its because I didn't want to be constrained by a framework's assumptions. I guess another reason would be the need for raw performance with computations, but I think you would have said that if that was your goal. Still, "more flexible" is not always better. "flexible and well integrated" is slightly better than "flexible to the Nth degree." #2 Look for projects that deal with updates and security fixes in a way that is sensitive to users of critical applications. This is better than programs that change little. For example, does the "vendor" provide patches containing just critical updates? Do they have good, clear communication about changes that may break compatibility? How long are older versions maintained? Asking these questions will help you find a thriving project that is actively maintained and supported. (contrast to abandonware, which hasn't changed in ages) #3 Why haven't you mentioned maintainability or scalability? It sounds like you're coming from a platform that you have outgrown, either because your app can't keep up with it's load, or because you can't enhance it with the features you want. You're not simply refactoring it, you're starting over from the beginning. How often do you want to start from scratch? If the answer is, "this is the last time," then I'd worry *way* more about this and point #2 than anything else you mentioned. #4 (optional) Has your dev team built many python web-apps? I'm guessing no, or you'd already have picked a platform because of experience. If they have not, I'd personally also ask for a platform that is easy to learn, works well with the dev tools (IDE, debugger, version control) you're familiar with, and has good documentation (dead tree or online). The unfortunate news, I'm afraid to say, is that because of the python culture, you're still going to face tough decisions as there are several mature products who score high marks in the areas I've listed above. It seems the python community at large is insanely bent on doing things the "right" way, so there may just be too many good options to choose from. But its better to ask the right questions. -- Matthew Nuzum newz2000 on freenode -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to strip \n characters
On May 21, 7:05 am, Asun Friere <[EMAIL PROTECTED]> wrote: > On May 20, 10:49 pm, Michael Bentley <[EMAIL PROTECTED]> > wrote: > > > On May 20, 2007, at 7:41 AM, Michael Bentley wrote: > > > > (upload.strip()) > > > Oops: (upload.strip(),) or upload.strip() > > Superfluous though the braces around your original were, it should > still run ... > ie. (a) == a When you mean superfluous you mean it makes a diffrence in run-time or just code style? -- http://mail.python.org/mailman/listinfo/python-list
Re: [Fwd: Re: managed lists?]
(snip - I suppose I'm answering to Jorgen, but being another idiot myself I may be wrong... anyway:) > Thanks for the answer. I did make something myself after i could not > find anything, just because it was fun to do :-) I did saw array but > it was not for object, only for small types like int, char, Everything in Python is an object. Including integers. And there's no 'char' type in Python. > > The list I created uses a strong type check to make sure all objects > in the list are of the same type, like > > ol = objlist.ObjList(class_name = SomeClass) > > Now only classes that are an instance of SomeClass are allowed in the > array. ObjList mimics a normal list, it can index, iterate, find, > delete, append items so it was basically a drop-in replacement for my > _list = [] solution The problem with this kind of "solutions" is that it creates more problems than anything else. What you really want is a list objects that share a common interface, not a list of objects that are instances of a same class. As a simple example, let's say you need a list of file-like objects. Or to be more accurate, a list of objects that have a 'write' method that's compatible with file.write(). So StringIO instances should be allowed, but your code will reject them. You may have a perfectly valid reason to use StringIO instances instead of files in some situations, but with your (ill-named) 'ObjectList' stuff it won't be possible. For no good reason. -- http://mail.python.org/mailman/listinfo/python-list
^? Boobies Tities all under 16yr old chicks!
http://nudepicks.blogspot.com - Download these girls for free boobies! -- http://mail.python.org/mailman/listinfo/python-list
RE: Python Web Programming - looking for examples of solidhigh-tr affic sites
I just started using flex (flex.org) from Adobe for the front end and am quite amazed at what it can do. Good docs. Clean client/server api if you like xml. It's relatively new so you still have to turn over some rocks and kiss some frogs to figure out how to get exactly the behavior you want in some cases. of couse the end result is that you're running flash on the client, but if you don't use the extensive special effects, you may be ok. If flash is politically correct, you don't have to worry about server variants. Still use python on the server side. I might even consider writing python classes to generate their http://mail.python.org/mailman/listinfo/python-list
Re: Components for a client/server architecture
On Mon, 21 May 2007 12:06:50 +0200, Diez B. Roggisch wrote: > I'm not sure which configuration you want to change how often. But I'm > not convinced that the python threading limitations really do make a > difference here. Do you really benefit from multi-core capabilities in > this scenario? The threading issues are not bound to multi cpu systems. The problem is that some of Python's blocking functions require holding the global lock. "Not all built-in functions that may block waiting for I/O allow other threads to run." "It is not possible to interrupt the acquire() method on a lock" http://docs.python.org/lib/module-thread.html I also found that IronPython does not have a global lock, so far it seems well suited for solving the problems I am trying to avoid. I am still looking for a good comparison between IronPython, Python, and Jython. > Sounds like CORBA to me. CORBA has a very mature and good implementation > for Python called OmniORB, and interoperability with other orbs (the > ones available for e.g. Java) is very good - as CORBA as standard is > mature. I have worked with Bonobo (an implementation of CORBA) before, though not on the network - it is fairly complex. But I did not think of using it for this purpose, it might actually make sense. I'll have to look into the transport protocol more. > And from what I know about SOAP it's certainly not better > suited (besides the fact that it sucks big time anyway) SOAP seems well suited for web services. But it comes with quite some overhead, I tend to say that it's not a perfect fit for our purpose. Thank you for your comment! -Samuel -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
Well wxPython offers all of the above. They use XRC which is a XML file which can be loaded inside the GUI, that auto-creates the components + layout for you. It also supports creating the gui programatically, which might be very handy when your layout is undetermined or changes when users select options etc. I use wxPython because I am used to wxWidgets C++ and it is very good under python (I am a python newbie and the integration in python is fine). I use wxGlade to auto generate the GUI from inside the GUI designer, works great as well As for tkinter, PyQt or PyGTK, I do not have much experience with them. You don't change a winning formula ;-) - Jorgen On 5/21/07, Michael L Torrie <[EMAIL PROTECTED]> wrote: > On Mon, 2007-05-21 at 18:23 +0200, Petr Muller wrote: > > There's PyQt thingy, imho very good and easy to learn/use, but still > > powerful. I've used it for a small gui-oriented project with almost no > > problems and it worked like a charm. However, sometimes I had troubles > > finding useful documentation for it. > > I've also tried to play with PyGTK, it's quite nice and easy (and you > > have the advantage of Glade), but I don't like GTK way of creating GUI. > > I haven't used Tkinter a lot, only looked at it. And I didn't like it much. > > How does GTK's way of creating the GUI (I presume you're not talking > look and feel) differ from Qt's? From what I can see (having developed > large apps in both GTKmm and Qt (C++), they both function the same. In > other words you create the widget first, then parent it in a container > and add callbacks. Whereas wxPython's approach is somewhat different. > > It appears that most wxPython apps setup the GUI programmatically, > whereas Most Qt and Gtk apps tend to use XML-based gui-building > factories. In this latter case, Glade's method is quite different from > Qt's. > > > > > I would really suggest PyQt. (with a big IMHO :) > > > > Petr > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest for threading function always failed...
If all you are doing is testing that run() works correctly, you could probably also get away with just calling run() directly instead of also implicitly testing the Thread class as well. -Kathy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On Mon, 2007-05-21 at 18:23 +0200, Petr Muller wrote: > There's PyQt thingy, imho very good and easy to learn/use, but still > powerful. I've used it for a small gui-oriented project with almost no > problems and it worked like a charm. However, sometimes I had troubles > finding useful documentation for it. > I've also tried to play with PyGTK, it's quite nice and easy (and you > have the advantage of Glade), but I don't like GTK way of creating GUI. > I haven't used Tkinter a lot, only looked at it. And I didn't like it much. How does GTK's way of creating the GUI (I presume you're not talking look and feel) differ from Qt's? From what I can see (having developed large apps in both GTKmm and Qt (C++), they both function the same. In other words you create the widget first, then parent it in a container and add callbacks. Whereas wxPython's approach is somewhat different. It appears that most wxPython apps setup the GUI programmatically, whereas Most Qt and Gtk apps tend to use XML-based gui-building factories. In this latter case, Glade's method is quite different from Qt's. > > I would really suggest PyQt. (with a big IMHO :) > > Petr -- http://mail.python.org/mailman/listinfo/python-list
[Fwd: Re: managed lists?]
I answered off list (because besically I'm an idiot). So if you like, read up the current news. :) Original Message Subject:Re: managed lists? Date: Mon, 21 May 2007 21:30:37 +0200 From: Jorgen Bodde <[EMAIL PROTECTED]> To: Wildemar Wildenburger <[EMAIL PROTECTED]> References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> Hi Wildemar, Thanks for the answer. I did make something myself after i could not find anything, just because it was fun to do :-) I did saw array but it was not for object, only for small types like int, char, etc to be used for quick but efficient buffers of raw data (at least it looks like that). The list I created uses a strong type check to make sure all objects in the list are of the same type, like ol = objlist.ObjList(class_name = SomeClass) Now only classes that are an instance of SomeClass are allowed in the array, ObjList mimics a normal list, it can index, iterate, find, delete, append items so it was basically a drop-in replacement for my _list = [] solution If you are interested i can send you the source. I created a py.test module as well to test every method intensively. Regards, - Jorgen On 5/21/07, Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > Jorgen Bodde wrote: > > Right now i have a list in a class that I export as a member variable > > to the outside world, it is a standard list (e.g. [] ) but I wish to > > have a stronger type checking when adding objects, that only some > > objects are allowed and others are not. It was quite easy to create > > it, but I wonder if there is already a standard solution for lists > > that carry only objects of a single type? > > > > Don't have much time on me right now, so I'll just give you a hint: I > *think* python has an array-datatype somewhere in its STD-lib (that is: > in a module you have to import). Not sure, could have been only for > NumPy or so. A quick look into the docs should clarify that quickly. > > bye :) > W > -- http://mail.python.org/mailman/listinfo/python-list
py2exe compiling
Hello, I have just finished my script and am ready to distrabute it. I am having a little trouble using py2exe though. here is what i have at the top of my file for imports: import string, array, sgmllib, re, sys, cookielib, urllib2, random, ConfigParser, time from urllib2 import urlopen from ClientForm import ParseResponse from configobj import ConfigObj Now, there are some other file attributes i need a bit of help with. icon = nigel.ico file name = name file author = cody woolaver file version = 0.1.3 file comments = uhhh, a comment ^^ Thanks for your help ~Cody Woolaver -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving class used in pickle
Jeffrey Barish <[EMAIL PROTECTED]> writes: > I have a class derived from string that is used in a pickle. In the new > version of my program, I moved the module containing the definition of the > class. Now the unpickle fails because it doesn't find the module. I was > thinking that I could make the unpickle work by putting a copy of the > module in the original location and then redefine the class by sticking a > __setstate__ in the class thusly: > > def __setstate__(self, state): > self.__dict__.update(state) > self.__class__ = NewClassName > > My plan was to specify the new location of the module in NewClassName. > However, when I do this I get the message "'class' object layout differs > from 'class'". I don't think that they do as the new module is a copy of > the old one. I suspect that I am not allowed to make the class assignment > because my class is derived from string. What is the best way to update > the pickle? The only thought I have is to read all the data with the old > class module, store the data in some nonpickle format, and then, with > another program, read the nonpickle-format file and rewrite the pickle with > the class module in the new location. You can fiddle with the file class used reading the pickled file. I.e. the "read()" method could replace each instance of "foo.myclass" by "greatnewmodule.mynewclass" could bring you back in the game. Porting some applications of my from 32 to 64 bit i discovered that my Numeric int arrays really had to be int32. So i opened the (binary) pickled files and replaced the occurences of "'l'" by "'i'". Later we replaced Numeric by numpy. I used the editor approach again to replace "Numeric" string by "numpy" or "numpy.oldnumeric". A collegue of mine wrote a small reader class implementing the approach working on the input stream. Regards Berthold -- -- http://mail.python.org/mailman/listinfo/python-list
Re: doctest environment question
On 21 May, 18:53, Peter Otten <[EMAIL PROTECTED]> wrote: > The doctest code is executed in a module without a __name__, it seems. > Unfortunately (in this case) the builtin module serves as a fallback > helping out with its own name: > > >>> __name__ > '__main__' > >>> del __name__ > >>> __name__ > > '__builtin__' > > What to do about it? doctest could be changed to execute code snippets in a > module with a name and a sys.modules entry though I don't see much benefit > here. Peter, thanks for the quick response, but I don't quite understand what you're saying. I don't want to change doctest -- I want to find a way to make my example pass using doctest. doctest.testfile comes with lots of parameters, and I suspect if I knew how to do it I could pass in the correct parameters to make this example work. It's not what I actually want to document/test, it's a minimal example which demonstrates the problem. Thanks again. > > Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple web apps....mod_python or framework?
cbmeeks a écrit : > If you guys where going to do a simple web-app (as in, 4-5 tables with > 99% being simple CRUD), would you use a framework (Django, > CodeIgniter, whatever...) or would you do it using maybe mod_python > and Python code? pylons + SQLAlchemy http://pylonshq.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing Python in a path that contains a blank
Konrad Hinsen schrieb: > I am trying to install Python from sources in my home directory on a > Mac cluster (running MacOS X 10.4.8). The path to my home directory > contains a blank, and since the installation procedure insists on > getting an absolute path for the prefix, I cannot avoid installing to a > path whose name contains a blank. Python does not seem to be prepared > for this, as it uses only the part before the blank, resulting in > numerous error messages. > > Does anyone know a workaround? > > Thanks, > Konrad. > You could give /foo/bar\ baz/ham or "/foo/bar baz/ham" (either escaping the blanks or wrapping the path in quotation marks) a try. I can't verify it either, just guess from other terminals' behaviour. HTH, Stargaming -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWBIE: Extending a For Statement.
> > Perhaps you meant that second one to be: > > (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == > > 3) > > > Clearly not! Its called *list*-comprehension, not tuple-comprehension. ;) With () instead of [], it is a generator expression. http://docs.python.org/ref/genexpr.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
Hello, My 2 cents contribution: To me all toolkits offer nice features. It's just a matter of choice depending on your needs. I've personally chosen pyGTK and I use it successfully on Linux/windows/MacOsX for my home grown softs. The reasons of my choice: - It looks the same on all platform (actualy I want to use the softs on different platform and I definitly prefer that it look the same on all of them!) - It's easy to develop with (Glade3,...) - It works perfectly on all platform and it's no difficult to install (even compile!) on all of them. - It looks nice (GTK is the Gimp ToolKit) Let me say that I also tried TkInter (ugly :-( ), pyQt (a mess to understand what kind of license you are allowed to use for you soft), wxpython (it's GTK on Linux but not on other platform and thus not looking the same on all platform...) Just a personal view... David 21 May 2007 08:39:44 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: > > Just wondering on what peoples opinions are of the GUIs avaiable for > Python? > > All I am doing is prompting users for some data (listbox, radio > buttons, text box, ect...). Then I will have some text output, maybe > a scrolling text message as things are happening. > > I have some minor things I need to do, for example, if Checkbutton X > is clicked, I need to disable TextBox Y, and I would like to display > the scrolling text (output) > > Ultimately, is it worth downloading and learning some of the packages > avaiable for Python, or should I just stick to the Tkinter stuff that > is included. > > More specifically, has anyone used the Qt stuff for python, easy to > use? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: alternative to eclipse [ python ide AND cvs ]
as you said, I re-installed java properly and it solved the problem. thanks. thanks for everybody else for responding yomgui Nathan Harmston wrote: > I have had very few problems with eclipse on ubuntu with pydev > installed. Is it still running under the gnu jvm, not the sun one? It > was crashing on me until I changed them around, detials about changing > it around on ubuntu anyway > > http://ubuntuguide.org/wiki/Ubuntu_Edgy#How_to_install_Java_Integrated_Development_Environment_.28Eclipse.29 > > > > Hope this helps, > > Nathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
Kevin Walzer wrote: > 2. wxPython is big, harder to learn than Tkinter, but looks good on Mac, > Windows, and *Nix. It will require users to install a lot of extra stuff > (or you'll have to bundle the extra stuff). PyInstaller builds binaries beautifully from raw py source. No need to bundle the wx stuff. I develop on Linux, build on Windows (with PyInstaller) and it works great. The source runs on any platform, the Windows binaries is neat for the point and click users. Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
[EMAIL PROTECTED] wrote: > Ultimately, is it worth downloading and learning some of the packages > avaiable for Python, or should I just stick to the Tkinter stuff that > is included. It depends. Are you selling your application commercially/closed-source or is it freeware/open-source? Are you deploying on several platforms, or just one? Here are a few things to consider: 1. Tkinter is simple to code and easy to deploy. It's a bit bare-bones without additional packages. 2. wxPython is big, harder to learn than Tkinter, but looks good on Mac, Windows, and *Nix. It will require users to install a lot of extra stuff (or you'll have to bundle the extra stuff). 3. PyQt is also nice, and works well on Mac/Windows/*Nix but the free version requires your app to be released under the GPL. That may or may not be an issue for you. PyQt is also a large package to install. 4. PyGTK is popular on*Nix and works OK on Windows. But it doesn't run natively on the Mac. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-URL! - weekly Python news and links (May 21)
On May 21, 1:48 pm, "Gabriel Genelli" <[EMAIL PROTECTED]> wrote: > John Nagle captures Python in a single taxonomic paragraph, and > Alex Martelli details his GUI preferences, in a thread valuable > for more than just the beginners its original poster might have > imagined: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/... ... But you need to check Christopher Arndt's immediate reply to John for the corrections! - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: doctest environment question
[EMAIL PROTECTED] wrote: > I'm not making progress with the following and would appreciate any > help. > > Here's an interpreted Python session. > import sys def f(): pass > ... this_module = sys.modules[__name__] delattr(this_module, 'f') f() > Traceback (most recent call last): > File "", line 1, in > NameError: name 'f' is not defined > > Suppose I want to doctest this behaviour. I cut and paste the above > into a file "test.txt" then run: > > python -c "import doctest; doctest.testfile('test.txt')" > > This gives me unexpected test failures: > > python -c "import doctest; doctest.testfile('test.txt')" > ** > File "test.txt", line 5, in test.txt > Failed example: > delattr(this_module, 'f') > Exception raised: > Traceback (most recent call last): > File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ > python2.5/doctest.py", line 1212, in __run > compileflags, 1) in test.globs > File "", line 1, in > delattr(this_module, 'f') > AttributeError: f > ** > File "test.txt", line 6, in test.txt > Failed example: > f() > Expected: > Traceback (most recent call last): > File "", line 1, in > NameError: name 'f' is not defined > Got nothing > ** > 1 items had failures: >2 of 5 in test.txt > ***Test Failed*** 2 failures. The doctest code is executed in a module without a __name__, it seems. Unfortunately (in this case) the builtin module serves as a fallback helping out with its own name: >>> __name__ '__main__' >>> del __name__ >>> __name__ '__builtin__' What to do about it? doctest could be changed to execute code snippets in a module with a name and a sys.modules entry though I don't see much benefit here. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: pyExcelerator bug?
John, I'd be delighted to try xlwt (does it work under Python 2.4 and 2.5?) I followed the link to ...svn/xlwt/trunk and found a collection of files, but no Windows installer. How do I install xlwt? Thanks in advance Thomas Philips -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Web Programming - looking for examples of solid high-traffic sites
Use php. I am lead programmer/maintainer of big website with a lot of interactive stuff in user's backoffice and with a lot of interraction to our non-web apps. PHP is a crap, but programming for web in python is a pain in the ass. And php programmers are cheaper. Especialy avoid mod_python. IMHO. -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
jay wrote: > 3. Currently, I write most of my code with Xcode (on the Mac platform) > using Applescript. This gives me GUI capabilities. Is there anything > you'd recommend that I could use for Python that would give me a GUI > interface? PyObjC allows you to write Cocoa GUI's from Python using Xcode and Interface Builder, much as AppleScript Studio does. However, that's not a cross-platform solution. Tkinter runs on Windows as well as OS X. Out-of-the-box, however, Tkinter is somewhat limited. To build rich GUI's with Tkinter, you will need to install several additional Tk libraries and their associated Python wrappers. Tkinter is my toolkit of choice, and I've released a Python shareware application on OS X that uses it: see http://www.codebykevin.com/phynchronicity-running.png for a screenshot. wxPython is also a very reasonable solution, and will probably give you more out of the box than Tkinter. My main reason for using Tk is that I already know it well. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
I have a few quibles with your summary of Python's properties: On 21 Mai, 08:16, John Nagle <[EMAIL PROTECTED]> wrote: > If you have a computer science background, here's all you need > to know: Python is a byte-code interpreted untyped Python is strongly but dynamically typed. The fact that you don't have to declare which type a variable is, doesn't mean it's untyped. > procedural In Python you can programm in imperative/procedural, object-oriented and functional style. It can thus be called a multi-paradigm language. IMO it is best suited for the object-oriented paradigm. > dynamic language with implicit declaration. Syntax is vaguely C-like. It shares many syntax rules with C (variable names, literals, functions, ...) but it doesn't look at all like C (no braces, semicolons, assignment expressions, pointers, ...). > Block structure is determined by indentation. Objects use a class > definition/ > explicit instantiation/multiple inheritance model. Most important, classes are defined at run-time, not compile time, which makes them highly dynamic. Furthermore, classes, functions and methods are first-class data- types, i.e you can pass them (or more correctly, references to them) around as arguments or assign them to variables. > Memory management > is safe and managed by reference counts backed by a garbage collector. > Weak references are supported. Built in data types are numerics, ASCII > and Unicode strings, dynamic arrays, fixed size tuples, and hashes. Python lists are much more than arrays. More like a linked list. You forgot sets. And functions, classes, methods, instances (see above) > Implementation speed is typically 2% of C. Execution speed is approx. 2% - 150% of C :-) Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On 2007-05-21, Cameron Laird <[EMAIL PROTECTED]> wrote: > While PyQt is plenty wonderful, Tkinter's more than adequate, > given the requirements you've described. Tkinter is easier to use for simple things. You just have to try not to think about the fact that it's pulling a complete Tcl interpreter into your app. It also seems to come only in various flavors of ugly. ;) wxPython (based on wxWidgets) is cross-platform, industrial-strength and has native look-and-feel. It is, however, more complex to use. In some places it's not very "Pythonic" and shows it's C/C++ heritage (this has improved a bit in the past couple years). There are also a couple more Pythonic wrappers on top of wxWidgets. pyGTK isn't a bad choice if Linux/Unix is what you care about. GTK for Windows was still a bit sketchy the last time I looked into it. PyQt I haven't tried, but both Linux/Unix and Windows support is reported to be solid. -- Grant Edwards grante Yow! My polyvinyl cowboy at wallet was made in Hong visi.comKong by Montgomery Clift! -- http://mail.python.org/mailman/listinfo/python-list
managed lists?
Hi all, I have been slowly progressing with my application written in wxPython. I love the freedom, speed and lack of the compiling run. I still have to get used to the lack of (strong) types, and it sometimes frustates me to no end that a wrongly given argument explodes somewhere deep inside my application without giving any clue why it blew up in the first place.. Right now i have a list in a class that I export as a member variable to the outside world, it is a standard list (e.g. [] ) but I wish to have a stronger type checking when adding objects, that only some objects are allowed and others are not. It was quite easy to create it, but I wonder if there is already a standard solution for lists that carry only objects of a single type? I solved it now, by using isinstance() and giving the class name as argument to the list (thank god that everything in Python is an object ;-) ) where I check against when adding, but re-inventing the wheel is silly ofcourse - Jorgen -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
[EMAIL PROTECTED] wrote: > Just wondering on what peoples opinions are of the GUIs avaiable for > Python? Python has, I believe, 4 compelling choices for GUI library: Tkinter, wxPython, PyQt, and PyGTK. Like everything in life, each has their relative merits and downsides. Briefly, here are my feelings on each, but I'm mostly versed in wxPython. Tkinter: Pros: comes with Python out of the box; terse; easy Cons: owner-drawn (not-native OS widgets); limited in out-of box functionality; kind of ugly wxPython: Pros: easy to install binary on all platforms, active development, active friendly community of contributors, native os base widgets on all platforms. Cons: hard to build from source on all platforms, everything but the kitchen sink comes with it, and some things are pretty buggy still or abandoned. PyQt: Pros: looks good on all platforms, easy to install and use. Cons: licensing issues require you to understand lots of specifics; owner-drawn widgets. PyGTK: Can't comment because I haven't used it. The major con in my mind is that (I think) you need the Gtk library to be installed on all platforms, so on OS X / Windows the widgets won't look platform-native. > All I am doing is prompting users for some data (listbox, radio > buttons, text box, ect...). Then I will have some text output, maybe > a scrolling text message as things are happening. I think each of the GUI libraries would be able to handle this easily. > I have some minor things I need to do, for example, if Checkbutton X > is clicked, I need to disable TextBox Y, and I would like to display > the scrolling text (output) Again, this is simply responding to events as they happen. You set up a callback function with your reactive code, and tell the GUI library to call that function when the event occurs. > Ultimately, is it worth downloading and learning some of the packages > avaiable for Python, or should I just stick to the Tkinter stuff that > is included. I think everyone should use wxPython, but I'm biased. > More specifically, has anyone used the Qt stuff for python, easy to > use? I've used it and it is easy, yes. Relative ease I can't answer though, because I find wxPython extremely easy due to depth of use over the years. Shameless plug: consider using Dabo on top of wxPython - we feel it makes wxPython even easier and more pythonic, but admittedly there's a bit of a learning curve there too. Even though Dabo is a full application framework originally meant for desktop database applications, it is modular and you can choose to only use the UI bits... http://dabodev.com -- pkm ~ http://paulmcnett.com -- http://mail.python.org/mailman/listinfo/python-list
Re: customary way of keeping your own Python and module directory in $HOME
On 15 Mai, 02:55, [EMAIL PROTECTED] wrote: > My issues have been with keeping a ~/pylib directory for extra > modules, and reconciling that with setuptools / Easy Install. I'm > curious to hear how other folks manage their own local module > directory. For Python libraries, I use the workingenv.py (search Cheeseshop) for keeping a separate environment for every application with all the libraries it needs. This is great to dodge problems with two apps requiring different, uncompatible versions of the same library, for having different staging and production environments, and so on. Once you activate an environment (in a shell or in your Python script), the PYTHONPATH and the installation directories for distutils and easy_install will be adapted automatically. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > >Just wondering on what peoples opinions are of the GUIs avaiable for >Python? > >All I am doing is prompting users for some data (listbox, radio >buttons, text box, ect...). Then I will have some text output, maybe >a scrolling text message as things are happening. > >I have some minor things I need to do, for example, if Checkbutton X >is clicked, I need to disable TextBox Y, and I would like to display >the scrolling text (output) > >Ultimately, is it worth downloading and learning some of the packages >avaiable for Python, or should I just stick to the Tkinter stuff that >is included. > >More specifically, has anyone used the Qt stuff for python, easy to >use? > While PyQt is plenty wonderful, Tkinter's more than adequate, given the requirements you've described. -- http://mail.python.org/mailman/listinfo/python-list
Re: help - python can't find file
quoth the enquiring mind: > - but now I get a error message 21 saying file or directory doesn't > exist. You must be in the same directory (in konsole) as the python script for this to work, else enter the relative path to the file: Assuming you are in your home directory (this is where a new konsole will start you), and the py scripts are in a directory 'pythondir': $ cd pythondir $ python myscript.py or: $ python pythondir/myscript.py You could also chmod the script to be executable and run it as a regular command ...however... I don't mean this to sound like RTFM but I do think that you could use some reading on Linux CLI usage. You say you have some Linux books? I say this as my reading of your message indicates your problems lie with misunderstanding the shell/paths etc, not with Python itself... -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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Help required with Python App
On May 21, 8:11 pm, Trevor Hennion <[EMAIL PROTECTED]> wrote: > Hi, > > I am producing a Web based database application for a customer and could > do with some help producing pdf documents from the data. > > The project uses Apache. Postgresql and Python CGI scripts on a Linux > server for a company with 20-25 users. > > I have been looking at thehttp://www.reportlab.org- ReportLab Toolkit, > but am rather busy with the other parts of the project, so if any one > located in the UK - Reading/Basingstoke area has the right > skills and time available now, please contact me. > > I have a small budget available for this work. > > Regards > > Trevor > > PS UK/Reading/Basingstoke area is essential. I don't have the time right now, though I'd be free for some work after a week or two; but I'm not in your area. ReportLab is quite good and has many features. I used it to build my xtopdf toolkit, a toolkit for conversion of other file formats to PDF. You could try using it (ReportLab) directly from the Python scripts in your app. If your needs are only for text to PDF conversion (of the textual data - numbers, strings and dates from the database), then you might want to take a look at xtopdf - see http://www.dancingbison.com/products.html. It may be a bit easier to use than ReportLab itself (it has a small and simple to use API), but only for text to PDF conversion - it doesn't support images as of now. It's released under the same license as ReportLab, the BSD license. xtopdf has sample programs that show you how to use it. It supports setting the font (anywhere in the output, but only one font at a time, headers and footers for each page, and automatic pagination). You can also read this article about it: http://www.packtpub.com/article/Using_xtopdf The article above shows how to use xtopdf to create PDF from various input formats - CSV, text, TDV, XLS, etc. All done very simply with just a few lines of code. You could try using either Reportlab or xtopdf or getting someone to help with using one of them. HTH Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help required with Python App
On May 21, 8:11 pm, Trevor Hennion <[EMAIL PROTECTED]> wrote: > Hi, > > I am producing a Web based database application for a customer and could > do with some help producing pdf documents from the data. > > The project uses Apache. Postgresql and Python CGI scripts on a Linux > server for a company with 20-25 users. > > I have been looking at thehttp://www.reportlab.org- ReportLab Toolkit, > but am rather busy with the other parts of the project, so if any one > located in the UK - Reading/Basingstoke area has the right > skills and time available now, please contact me. > > I have a small budget available for this work. > > Regards > > Trevor > > PS UK/Reading/Basingstoke area is essential. I don't have the time right now, though I'd be free for some work after a week or two; but I'm not in your area. ReportLab is quite good and has many features. I used it to build my xtopdf toolkit, a toolkit for conversion of other file formats to PDF. You could try using it (ReportLab) directly from the Python scripts in your app. If your needs are only for text to PDF conversion (of the textual data - numbers, strings and dates from the database), then you might want to take a look at xtopdf - see http://www.dancingbison.com/products.html. It may be a bit easier to use than ReportLab itself (it has a small and simple to use API), but only for text to PDF conversion - it doesn't support images as of now. It's released under the same license as ReportLab, the BSD license. xtopdf has sample programs that show you how to use it. It supports setting the font (anywhere in the output, but only one font at a time, headers and footers for each page, and automatic pagination). You can also read this article about it: http://www.packtpub.com/article/Using_xtopdf The article above shows how to use xtopdf to create PDF from various input formats - CSV, text, TDV, XLS, etc. All done very simply with just a few lines of code. You could try using either Reportlab or xtopdf or getting someone to help with using one of them. HTH Vasudev Ram Dancing Bison Enterprises http://www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
pyparsing actinos (WAS: Inverse of id()?)
Paul McGuire wrote: > For instance, Seo Sanghyeon (I believe the same one now working on > IronPython) uses the following technique in the EBNF parser/"compiler" > that he contributed to the pyparsing examples directory: > > # list of all the grammar variable names > all_names = ''' > integer > meta_identifier > terminal_string > ... > '''.split() > > # parse actions follow > def do_integer(str, loc, toks): > return int(toks[0]) FWIW, I find that my actions never use anything but the token list, so to avoid writing a bunch of functions like the one above, I typically write:: class ParseAction(object): def __init__(self, func): self.func = func def __call__(self, string, index, tokens): return self.func(*tokens) ... # parse an integer integer.addParseAction(ParseAction(int)) ... # parse a relation object, passing appropriate strings # (or parsed objects) to the constructor relation.setParseAction(ParseAction(Relation)) I guess the integer/int and relation/Relation is a little redundant, but it's never bothered me too much. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
[EMAIL PROTECTED] wrote: > Just wondering on what peoples opinions are of the GUIs avaiable for > Python? > > All I am doing is prompting users for some data (listbox, radio > buttons, text box, ect...). Then I will have some text output, maybe > a scrolling text message as things are happening. > > I have some minor things I need to do, for example, if Checkbutton X > is clicked, I need to disable TextBox Y, and I would like to display > the scrolling text (output) > > Ultimately, is it worth downloading and learning some of the packages > avaiable for Python, or should I just stick to the Tkinter stuff that > is included. > > More specifically, has anyone used the Qt stuff for python, easy to > use? > There's PyQt thingy, imho very good and easy to learn/use, but still powerful. I've used it for a small gui-oriented project with almost no problems and it worked like a charm. However, sometimes I had troubles finding useful documentation for it. I've also tried to play with PyGTK, it's quite nice and easy (and you have the advantage of Glade), but I don't like GTK way of creating GUI. I haven't used Tkinter a lot, only looked at it. And I didn't like it much. I would really suggest PyQt. (with a big IMHO :) Petr -- http://mail.python.org/mailman/listinfo/python-list
Re: converting strings to most their efficient types '1' --> 1, 'A' ---> 'A', '1.2'---> 1.2
This is excellect advise, thank you gentelman. Paddy: We can't really, in this arena make assumtions about the data source. I fully agree with your point, but if we had the luxury of really knowing the source we wouldn't be having this conversation. Files we can deal with could be consumer data files, log files, financial files... all from different users BCP-ed out or cvs excell etc. However, I agree that we can make one basic assumtion, for each coll there is a correct and furthermore optimal format. In many cases we may have a supplied "data dictionary" with the data in which case you are right and we can override much of this process, except we still need to find the optimal format like int8 vs int16. James: Using a baysian method were my inital thoughts as well. The key to this method, I feel is getting a solid random sample of the entire file without having to load the whole beast into memory. What are your thoughts on other techniques? For example training a neural net and feeding it a sample, this might be nice and very fast since after training (we would have to create a good global training set) we could just do a quick transform on a coll sample and ave the probabilities of the output units (one output unit for each type). The question here would encoding, any ideas? A bin rep of the vars? Furthermore, niave bayes decision trees etc? John: > The approach that I've adopted is to test the values in a column for all > types, and choose the non-text type that has the highest success rate > (provided the rate is greater than some threshold e.g. 90%, otherwise > it's text). > For large files, taking a 1/N sample can save a lot of time with little > chance of misdiagnosis. I like your approach, this could be simple. Intially, I was thinking a loop that did exactly this, just test the sample colls for "hits" and take the best. Thanks for the sample code. George: Thank you for offering to share your transform function. I'm very interested. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On 21 May 2007 08:39:44 -0700, [EMAIL PROTECTED] wrote: >All I am doing is prompting users for some data (listbox, radio >buttons, text box, ect...). Then I will have some text output, maybe >a scrolling text message as things are happening. > >I have some minor things I need to do, for example, if Checkbutton X >is clicked, I need to disable TextBox Y, and I would like to display >the scrolling text (output) > You should be able to do all those things with TKInter (though I am not sure about the automatted scrolling text.). >Ultimately, is it worth downloading and learning some of the packages >avaiable for Python, or should I just stick to the Tkinter stuff that >is included. Like Brad, I would recommend trying wxPyhton (http://www.wxpython.org/). There is an installer for Windows. Best is to look at the wxPython-Demo first thing. It contains a lot of example-code to borrow from. You can both read and try the code within the Demo-Application. However, the documentation of the class-library is for C++ only. You have to apply it to the python-version yourself. I prefer wxPython to TKInter because it offers more complex widgets namely Grids and Tabular-Lists right out of the box. Best wishes, Thomas -- http://mail.python.org/mailman/listinfo/python-list
doctest environment question
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. >>> import sys >>> def f(): pass ... >>> this_module = sys.modules[__name__] >>> delattr(this_module, 'f') >>> f() Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined Suppose I want to doctest this behaviour. I cut and paste the above into a file "test.txt" then run: python -c "import doctest; doctest.testfile('test.txt')" This gives me unexpected test failures: python -c "import doctest; doctest.testfile('test.txt')" ** File "test.txt", line 5, in test.txt Failed example: delattr(this_module, 'f') Exception raised: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/doctest.py", line 1212, in __run compileflags, 1) in test.globs File "", line 1, in delattr(this_module, 'f') AttributeError: f ** File "test.txt", line 6, in test.txt Failed example: f() Expected: Traceback (most recent call last): File "", line 1, in NameError: name 'f' is not defined Got nothing ** 1 items had failures: 2 of 5 in test.txt ***Test Failed*** 2 failures. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
[EMAIL PROTECTED] wrote: > Just wondering on what peoples opinions are of the GUIs avaiable for > Python? We have used wxPython with great results. It's cross platform. Can use native OS widgets and is easy to program. Compiles easily to exe binaries for Windows users as well. Best of luck, Brad -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
Alex Martelli wrote: > Most popular, however, is no doubt wxWindows -- > mostly because you can freely use it to develop SW which you plan to > distribute under closed-source licenses, while Qt &c force you to choose > -- either pay, or, if you even distribute your code, it will have to be > under the GPL. I'm not sure how well wxWindows works on Mac nowadays... wx Works great on Macs (10.4 at least, maybe others), Linux and Windows. We've used it for several cross-platform apps that needed GUIs. -- http://mail.python.org/mailman/listinfo/python-list
Python and GUI
Just wondering on what peoples opinions are of the GUIs avaiable for Python? All I am doing is prompting users for some data (listbox, radio buttons, text box, ect...). Then I will have some text output, maybe a scrolling text message as things are happening. I have some minor things I need to do, for example, if Checkbutton X is clicked, I need to disable TextBox Y, and I would like to display the scrolling text (output) Ultimately, is it worth downloading and learning some of the packages avaiable for Python, or should I just stick to the Tkinter stuff that is included. More specifically, has anyone used the Qt stuff for python, easy to use? -- http://mail.python.org/mailman/listinfo/python-list
Re: full screen graphics
On May 21, 8:39 am, myheartinamerica <[EMAIL PROTECTED]> wrote: > Hello, > > I need to run a particular graphics application over and over again > with a different command line to get benchmarks on the applications > performance (frame rates and similar data). I am running the following > within a while loop that parses out a different command line from a > configuration file. > > > def runCommand(command): > """runCommand(command) > > Parameters: > command -- the full string of the command to execute > > """ > print command > try: > childProcess = subprocess.Popen(command) > > done = False > while not done: > returnCode = childProcess.poll() > if (returnCode != None): > done = True > else: > # sleep for 10 seconds before checking again > time.sleep(10) > except KeyboardInterrupt: > print 'KeyboardInterrupt received. Trying to kill Wolf2.exe' > print '>TASKKILL /F /T /PID ', childProcess.pid > killCommand = ''.join(('TASKKILL /F /T /PID ', > str(childProcess.pid))) > killSubProcess = subprocess.Popen(killCommand) > killSubProcess.wait() > sys.exit(0) > except OSError, (errno, strerror): > print 'OS Error (%s): %s' % (errno, strerror) > print 'Above error occurred while executing the following:' > print command > except WindowsError, (errno, strerror): > print 'MS Windows Error (%s): %s' % (errno, strerror) > print 'Above error occurred while executing the following:' > print command > ## > > The problem lies in that the second time the application is run, it > doesn't grab focus and go full screen, but sits paused. It will not > continue running until I click on the minimized application in the > taskbar. Is there any way to force it to grab focus? > > I am running on Win32 with Python 2.5.1. > > Your help in this matter is greatly appreciated, > Mick Charles Beaver If your graphics program uses COM you may be able to do something like what's done in the following post: http://mail.python.org/pipermail/python-list/2005-June/327261.html I found this too, but I haven't tested it myself: http://downgra.de/articles/python-wmii/ You may be able to use Tim Golden's WMI module too. I would think you could use his "enumerate all running processes" and combine it with the "run a process minimized", except you'd change the flag so that it maximized instead. See link below: http://tgolden.sc.sabren.com/python/wmi_cookbook.html Hopefully that'll help you some. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Python compared to other language
On Mon, 2007-05-21 at 16:00 +0200, Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] wrote: > > >> Python is a strongly typed but dynamic language ... > > > > In the "A few questions" thread, John Nagle's summary of Python begins > > "Python is a byte-code interpreted untyped procedural dynamic > > language with implicit declaration. " > > > > Is Python strongly typed or untyped? > > Strongly typed. Most people think of statically typed, like Java, when they think of "Strongly typed." Python is strongly, dynamically typed. Some people refer to Python as "duck typed" meaning that python cares more about what the object appears to be, rather than it's actual type. If it looks like a duck, quacks like a duck, it must be a duck. Thus python is more concerned with the protocol of an object than the actual type. This is a powerful concept. I've also found, though, that duck-typing can be a real weakness when you're working with a complicated third-party library with weak documentation. You can't always infer what the method call is expecting, even if you have the source code in front of you. Figuring out the python twisted I/O library, is fraught with such challenges, despite the documentation. > > Ciao, > Marc 'BlackJack' Rintsch > -- http://mail.python.org/mailman/listinfo/python-list
Help required with Python App
Hi, I am producing a Web based database application for a customer and could do with some help producing pdf documents from the data. The project uses Apache. Postgresql and Python CGI scripts on a Linux server for a company with 20-25 users. I have been looking at the http://www.reportlab.org - ReportLab Toolkit, but am rather busy with the other parts of the project, so if any one located in the UK - Reading/Basingstoke area has the right skills and time available now, please contact me. I have a small budget available for this work. Regards Trevor PS UK/Reading/Basingstoke area is essential. -- http://mail.python.org/mailman/listinfo/python-list
Re: List Moderator
On Mon, 2007-05-21 at 14:24 +, Grant Edwards wrote: > > To quantify things for curiosity's sake, I just scanned through > the last 1000 postings in c.l.p. There was exactly 1 spam > message and two replies to spam messages complaining about > them. I'm seeing 2 messages a day, lately, to c.l.p that are blatant and a bit rude spam (and some would argue this thread is spam), out of about 200-400 messages per day. I just barely deleted one a moment ago, in fact. While that's not bad at all, my other mailing lists (gtk-list, openldap, etc) all get 0 spam per day. Also they are getting annoying mainly because they seem so preventable. They all have the same "from" address. If this was a normal mailinst list, the moderators could unsubscribe that address and prevent it from subscribing again. I'm not at all sure how moderation is working here. I am subscribed to c.l.p exclusively through the mailman mailing list, so I don't ever use the nntp part. -- http://mail.python.org/mailman/listinfo/python-list
Re: howto get function from module, known by string names?
On Mon, 2007-05-21 at 06:13 -0700, dmitrey wrote: > And howto check does module 'asdf' exist (is available for import) or > no? (without try/cache of course) Why would you need to do that? What are you planning to do when you have determined that the module doesn't exist? Surely you're not planning on swallowing the error silently, because that would make your program very hard to debug. The Pythonic response is to raise an exception, but then you might as well just propagate the exception that __import__ already raises: >>> def myfunc(module_string1, func_string2, *args): ... func = getattr(__import__(module_string1), func_string2) ... return func(*args) ... >>> myfunc("asdf", "spam") Traceback (most recent call last): File "", line 1, in ? File "", line 2, in myfunc ImportError: No module named asdf Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: TIFF to PDF
Gabriel Genellina said unto the world upon 05/21/2007 10:12 AM: > En Mon, 21 May 2007 10:53:08 -0300, Brian van den Broek > <[EMAIL PROTECTED]> escribió: > >> Gabriel Genellina said unto the world upon 05/21/2007 07:01 AM: >>> En Mon, 21 May 2007 07:42:21 -0300, revuesbio <[EMAIL PROTECTED]> >>> escribió: >>> os.system('"C:\Program Files\GnuWin32\bin\tiff2pdf.exe" -o C:\test.pdf C:\test.TIF') >>> \ is used as a escape character in strings. >>> Use either \\ or a raw string, that is: >>> >> Better still, use / as the path separator. That works fine on both >> windows and *nixes. > > But unfortunately / does not always work, specially for arguments to > internal commands: > > py> os.system("type c:/windows/win.ini") > La sintaxis del comando no es correcta. [invalid syntax] > 1 > py> os.system(r"type c:\windows\win.ini") > [Compatibility] > _3DPC=0x0040 > _BNOTES=0x224000 > ... Thanks for the catch then, Gabriel. Windows is but a bitter memory for me, and / worked in every context in which I ever used it---I didn't know that the support was only partial. Best, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Leo 4.4.3 beta 1 released
Leo 4.4.3 beta 1 is available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.4.3: - Added support for chapters in Leo's core. Chapters are disabled by default. To enable, set @bool use_chapters=True. - Added support for zipped .leo files. - Added a leoBridge module that allows full access to all of Leo's capabilities from programs running outside of Leo. - Removed all gui-dependent code from Leo's core. - Better support for the winpdb debugger. - Added support for @enabled-plugins nodes in settings files. - Added support for @open-with nodes in settings files. - The__wx_gui plugin is now functional. - Many minor improvements, new settings, commands and bug fixes. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Home: http://sourceforge.net/projects/leo/ Download: http://sourceforge.net/project/showfiles.php?group_id=3458 CVS: http://leo.tigris.org/source/browse/leo/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: [EMAIL PROTECTED] Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWBIE: Extending a For Statement.
Dustan wrote: (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == 3] > File "", line 1 > (key, mydict[key] for key in mydict if key in xrange(60, 69) or > key == 3] > ^ > SyntaxError: invalid syntax > > Perhaps you meant that second one to be: > (key, mydict[key] for key in mydict if key in xrange(60, 69) or key == > 3) > Clearly not! Its called *list*-comprehension, not tuple-comprehension. ;) This works: [(key, mydict[key]) for key in mydict if key in xrange(60, 69) or key ==3] (Note the parenthesis around (key, mydict[key]), they are MENDATORY.) regards W -- http://mail.python.org/mailman/listinfo/python-list
Executing Python interpreter from Java
Hello, I'm trying to write some Java code that will launch a python interpreter shell and pipe input/output back and forth from the interpreter's i/o streams and the Java program. The code posted below seems to work just fine under Mac OS X; however, under Windows XP (Java 1.6 and Python 2.5 installed) the program hangs when I give a command to import the Tkinter (Python GUI library) and create a top- level frame window. Specifically, run the program as: % java PythonShell (loads Python and displays welcome message) >>> from Tkinter import * >>> t = Tk() >>> After this point a frame window pops up but anything you type further doesn't evoke any further response from the shell. There is a little hiccup that occurs when the Tkinter library is actually loaded (on both the Mac or Windows OS) and the window in which the java program is running loses the focus-- I guess that has something to do with the way the Tk windowing library is loading. I know on the Java documentation for Process it says that it may not work correctly with native windowing libraries on some OSs. If this is what is happening here, does anyone have any suggestions? (Btw, I know about Jython and I do not want to use that for a whole lot of reasons.) Thanks a whole lot! nadeem import java.io.*; import java.util.*; public class PythonShell { // these are out here so the inner class can access them... static BufferedReader in = null; static boolean ok = true; public static void main(String[] args) throws InterruptedException { ProcessBuilder pb = new ProcessBuilder("python", "-i"); // force interactive pb.redirectErrorStream(true); // combine stdout and stderr Process p = null; PrintStream out = null; boolean started = false; try { p = pb.start(); started = true; in = new BufferedReader(new InputStreamReader(p.getInputStream())); out = new PrintStream(p.getOutputStream(), true); } catch (IOException exc) { exc.printStackTrace(); if (started) p.destroy(); return; } final Scanner userIn = new Scanner(System.in); final Thread mainthread = Thread.currentThread(); class ReaderThread implements Runnable { public void run() { try { while (true) { int c = in.read(); if (c == -1) { ok = false; break; } System.out.print((char)c); } } catch (IOException exc) { ok = false; } // try to interrupt the other thread userIn.close(); try { System.in.close(); } catch (IOException exc) {} mainthread.interrupt(); } } Thread rt = new Thread(new ReaderThread()); rt.start(); while (ok) { try { String input = userIn.nextLine(); out.println(input); System.out.println(ok); } catch (NoSuchElementException exc) { ok = false; } } p.destroy(); p.waitFor(); } } /* Input: from Tkinter import * t = Tk() print 'hi' */ -- http://mail.python.org/mailman/listinfo/python-list
Re: List Moderator
On 2007-05-21, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2007-05-20, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > >>> It doesn't all go through a central point - users like me who use a news >>> server to access the list submit articles through a local news server >>> using NNTP. While there *is* a single point of access for articles >>> pulled from python.org's news server and gatewayed out as email (and for >>> which the filters you mention probably ought to help), articles I see >>> have never been processed by this interface. >>> >> Which doesn't explain why only comp.lang.python, of the several >> newsgroups I read, seems to be so spam-filled... > > Maybe I've got a better news server, but I don't see much spam > at all in c.l.p. To quantify things for curiosity's sake, I just scanned through the last 1000 postings in c.l.p. There was exactly 1 spam message and two replies to spam messages complaining about them. -- Grant Edwards grante Yow! Everybody is going at somewhere!! It's probably visi.coma garage sale or a disaster Movie!! -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWBIE: Extending a For Statement.
On 21 May, 15:02, [EMAIL PROTECTED] wrote: > mosscliffe: > > > if key in xrange (60,69) or key == 3: > > I keep seeing again and again code like this, mostly from people not > much expert of Python, but the PEP 260 shows the fast in was removed, > so it's O(n). Maybe removing the fast __contains__ was bad for > necomers (or just the casual Python users, that I belive is really > large). > > Bye, > bearophile Being a non-expert in python in fact just a beginner / casual user, can you expand on how 0(n) relates to if key in xrange (60,69) or key == 3: My mind tends to go blank at the mention of __xxx__. R -- http://mail.python.org/mailman/listinfo/python-list