Re: Python tools for managing static websites?
I haven't seen mention of HTMLgen, another python package. Check it out at: http://starship.python.net/crew/friedrich/HTMLgen/html/main.html Glenn -- http://mail.python.org/mailman/listinfo/python-list
Thread priority or keeping a (wx)GUI responsive
I need to do some intense calculations in my application. Those are done by a third party Python library and consume 100% CPU time for some seconds. The computations take place in their own thread to keep my GUI responsive (wxPython in my case). Everything works fine on a dual core machine. On a single CPU machine, the computation slows down the whole GUI (better, the whole machine). The ideal solution in my case would be to give the computation thread a very low priority. But I fear that is not possible? Moving the computations to a different process look quite complex since the result is a large Python data structure. And I fear it would not solve the problem since I can only influence the priority of a subprocess on the windows plattform (I refer to the documentation of the subprocess module). Another possible solution is to include some idle times (time.sleep(0.05) or wxYield() or even better with python yields?) in the algorithm of the computations. Ugly, since I would have to manipulate a third party library. Could sys.setcheckinterval() help? Do I miss something? Any help, tips or advice would be appreciated. Best regards, Noel -- http://mail.python.org/mailman/listinfo/python-list
splitter control
Is anybody know splitter control implementaion in c... -- http://mail.python.org/mailman/listinfo/python-list
module for calculations involving radioactive decay?
does anybody know of a package/module which will facilitate/simplify calculations with radioactive samples? as a minimum spec: - user definable list of radionuclides + names + halflives (expressable in time units like sec min etc as appropriate) - choice of units (Bq or Ci, with appropriate modifiers kGM etc - initial activity at given time (sample calibration) - activity calculation at other times, taking into account timezones - operators: add, subtract to simulate adding or removing activity (needs an "history" mechanism, so that activity at time T is always correctly calculated) any help kindly appreciated Frederik -- http://mail.python.org/mailman/listinfo/python-list
where the hell is the run command of PyPe editor?
daniel <[EMAIL PROTECTED]> wrote: > I'm trying to use PyPe, but I just got so frustrated when attempting to > run a script, this is the very first feature I would use for an editor, > OMG. I browsed through every single menu item and gave up... > > any help would be appreciated, (the most silly question ever, sounds > like a new computer user. ;--() I don't normally troll python-list, so sorry if this gets to you late, but to answer your question; there are sample macros in the macros/samples directory with recent PyPE distributions which include both "run current script" and "run selected code" example macros. If you have questions about PyPE in the future, feel free to email me directly, including PyPE in the subject will make sure it gets past my spam filter. - Josiah -- http://mail.python.org/mailman/listinfo/python-list
Re: report progress from C function
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Michael S wrote: > > > I downloaded Pyrex and ran it through their own > > example. The code looks quite messy, and I even saw a > > few "goto"s. > > looked at the assembler output from your C compiler lately? > > LOL! - is it even possible to code an if else without conditional jumps? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Listbox string formatting question - how to kill a dancingsnake ?
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: In the meantime, I have produced this evil hack, that takes advantage of the difference in pixel widths between the space, and either the fullstop or the single quote... It will only work if you have quite a lot of space to waste between columns, and I have only tested it for two sizes of Lucida and Helvetica - and for a fixed font like courier it seems to do no harm other than the cpu time it wastes... If the difference in width is one pixel, it lines up the next thing to be added to the string exactly, else it almost gets it right... I find the few (up to one less than there are pixels in a space) characters it adds into the line less visually disturbing than the dancing snake column caused by the full space width variation. anyway for what its worth, here it is: # this does some text padding to try to line variable font stuff up def pad_text(txt,pixlen,fontp): """This does padding up to a pixel value exploiting differences between space, fullstop or single quote widths. txt is a text string pixlen is an int - the number of pixels to "tab" to fontp is the font parameter """ a = fontp.measure(txt) diff = pixlen - a if diff < 0: return "string too long too fit in pixels" spsize = fontp.measure(' ') fssize = fontp.measure('.') sqsize = fontp.measure("'") repchr = ' ' rpsize = spsize numr = 0 rpdiff = 0 if spsize != fssize: repchr = '.' rpsize = fssize rpdiff = abs(fssize - spsize) elif spsize != sqsize: repchr = "'" rpsize = sqsize rpdiff = abs(spsize - sqsize) numspace, rem = divmod(diff,spsize) if rem == 0: numr = 0 else: if spsize < rpsize: numspace -= rem/rpdiff numr = rem/rpdiff elif spsize > rpsize: numr = (spsize - rem)/rpdiff numspace = numspace - numr + 1 numspace -= 2 txt = txt + ' ' while numr > 0: txt = txt + repchr numr -= 1 while numspace > 0: txt = txt + ' ' numspace -= 1 return txt Feel free to play the critic... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
other ways to check for ?
Hi there, are there other ways than the ones below to check for in a python script? (partly inspired by wrapping Tkinter :P) def f(): print "This is f(). Godspeed!" 1.: --> sort of clumsy and discouraged by the docs as far as I read import types type(f) is types.FunctionType 2.: --> I don't like this one at all def null(): pass type(f) is type(null) Basically I'm searching for something like: "type(f) is func" like in: "type(x) is int" Any ideas? =) -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic wrote: > are there other ways than the ones below to check for > in a python script? callable(f) -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Thx =) Fredrik Lundh schrieb: > elderic wrote: > > > are there other ways than the ones below to check for > > in a python script? > > callable(f) > > -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic enlightened us with: > are there other ways than the ones below to check for 'function'> in a python script? First of all, why would you want to? If you want to call the object as a function, just do so. Handle the exception that is raised when it's raised. Sybren -- Sybren Stüvel Stüvel IT - http://www.stuvel.eu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Event driven server that wastes CPU when threaded doesn't
Jean-Paul Calderone wrote: > On Tue, 31 Oct 2006 07:33:59 GMT, Bryan Olson <[EMAIL PROTECTED]> > wrote: >> Snor wrote: >>> I'm attempting to create a lobby & game server for a multiplayer game, >>> and have hit a problem early on with the server design. I am stuck >>> between using a threaded server, and using an event driven server. I've >>> been told time and time again that I should use an event driven server >>> design (that is, use twisted). >> >> I didn't hear the specifics of how you got that advice, so I >> can't comment specifically. I will say that I've have heard a >> lot of advice against threads that struck me as simply naive. > > Much of it is quite well informed. Could be; I didn't see it all. A lot was naive; I'd even say that the majority was naive. The most sophisticated software -- DBMS's, modern operating systems, avionics -- deals with multiple lines of control. I'm not saying that playing at that level is easy. The difficult problems are fundamental, and single-tasking merely takes away important capabilities. >>> There is a lot of interaction between the clients and they would often >>> need to write to the same list of values, which of course becomes a >>> problem with a threaded server - so event driven solves that problem, >>> and I assumed it would solve all my problems. [...] >> >> The purely event-driven style solves some problems, but creates >> others. You're forced to structure your code around the blocking >> behavior, and that's not the structure anyone would choose for >> clarity or maintainability. > > This is not the case. What I claimed is the case is the case. > However, much event-driven code is written > this way anyway, intentionally, for clarity. If you _want_ opaque > code, or for some reason think it is not opaque to write code in this > manner, then there you can use a library which supports this. Read the greats on the subject: modules should exhibit loose coupling and tight cohesion. But the purely event-driven style imposes a rule that must trump the principles of elegant design: no procedure, no method, may include and encapsulate an operation that might block. That's not for clarity; it's a limitation; it's broken. >> Suppose we're enhancing an event-driven system, and decide to >> relocate some datum from a variable to the database. Suppose in >> one or more places, accessing the data happens in a call chain >> several function down from the event loop. We can't just change >> the function that accesses the data because a synchronous >> database call could block and stop event processing. Every >> interface on the call chain is broken. > > As it must be, because you have changed the atomicity of an > operation. That's just naive. A thread switch and a return to the event loop both have the chance to break atomicity, as do other things. > Transparently propagating this up a call stack leads to bugs which are > similar to those found in a system based on pre-emptive multithreading. Yet "system based on pre-emptive multithreading" are taking over. Might as well get with the modern world. The competitive operating systems are multi-threaded and multi-core hardware is now at the local Best-Buy. I'm not saying threads are trivial to master. I did not start out at an advocate for programming with multiple threads and/or processes. But I think the race is over, and even those that think it's still on should be able to see that multiple lines of control are both in lead and moving faster. >> [...] >>> I will want the server to support as many users as is possible on any >>> given machine - and so wasted CPU cycles is something I am trying to >>> avoid. >> >> Python is a great scripting language, but squeezing out machine >> performance is not where scripting languages shine. That said, you >> might start in Python, to see if your system is successful and the >> performance of your server really is a limiting factor. >> >> >>> Is the only solution to use a threaded server to let my clients make >>> their requests and receive a response in the fastest possible time? >> >> Maybe. Probably not. It's all good -- multi-threading is your friend. > > Multithreading is _someone's_ friend. Probably not the OP's, whose > original post made it sound very strongly like he just needed network > concurrency, which is a perfectly fine use-case for event-driven style > rather than pre-emptive threading. I suggested he might start in Python (which has a global interpreter lock) to see if his system gets the traction it needs. But obviously no one is going to build a /World of Warcraft/ without learning to deal with multiple simultaneous lines of execution. It's all good. Multi-threading can be your friend too. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Sybren Stuvel a écrit : > elderic enlightened us with: >> are there other ways than the ones below to check for > 'function'> in a python script? > > First of all, why would you want to? If you want to call the object > as a function, just do so. Handle the exception that is raised when > it's raised. I don't think it's a good idea because when you place a try catch block around a function call, you'll catch any exception thrown by the function itself and not only the "cannot be called" exception. -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Sybren Stuvel schrieb: > elderic enlightened us with: >> are there other ways than the ones below to check for > 'function'> in a python script? > > First of all, why would you want to? If you want to call the object > as a function, just do so. Handle the exception that is raised when > it's raised. That's an advice I've heard a few times to often. I'm totally buying duck-typing. Yet the advice of simply calling a function to determine that it is one isn't sound in a lot of cases where you want to use it as callback later on. E.g. the turbogears DataGrid can get either a string or a callable passed as column-data-provider. But which of these two options is used must be known at construction time, not at later calling time. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Christophe wrote: > Sybren Stuvel a écrit : > > elderic enlightened us with: > >> are there other ways than the ones below to check for >> 'function'> in a python script? > > > > First of all, why would you want to? If you want to call the object > > as a function, just do so. Handle the exception that is raised when > > it's raised. > > I don't think it's a good idea because when you place a try catch block > around a function call, you'll catch any exception thrown by the > function itself and not only the "cannot be called" exception. A little experimentation shows that when something is not callable always a TypeError which evaluates to "'' object is not callable", so you can refine the try/catch with this information py> x = 1 py> x() Traceback (most recent call last): File "", line 1, in ? py> x = '' py> x() Traceback (most recent call last): File "", line 1, in ? TypeError: 'str' object is not callable py> class x: ... pass ... py> x() <__main__.x instance at 0x1002eef38> py> def x(): py. pass py. py> x() -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
[EMAIL PROTECTED] wrote: > A little experimentation shows that when something is not callable > always a TypeError which evaluates to "'' object is not > callable" that's not defined by the language specification, though, so your code won't be portable, and may break in future releases. and even if you can live with that, you still cannot distinguish between non-callable objects and bugs *inside* the callables, unless you add traceback analysis to the exception handler. -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Christophe enlightened us with: > I don't think it's a good idea because when you place a try catch > block around a function call, you'll catch any exception thrown by > the function itself and not only the "cannot be called" exception. That depends on the exception you're catching, doesn't it? Sybren -- Sybren Stüvel Stüvel IT - http://www.stuvel.eu/ -- http://mail.python.org/mailman/listinfo/python-list
__div__ not recognized automatically
Hello! I wrote a class class NumX: ... def __add__(self,other): ... def __div__(self,other): if not isinstance(other,NumX): other=NumX(other) ... Somewhere else I use a=(b+c)/2 where all variables are of NumX Type. When I execute the program it complains that it can't find an operator "/" for "instance" and "integer". However if I use pdb the same command works when started on the prompt. Also the manual execution a=(b+c).__div__(2) works. Any suggestions what goes wrong? Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: wxPython 2.7.1.3
robert wrote: > John Salerno wrote: >> You want Python 2.3 for Windows? > > yes. > (I know no other big libs which already stops support of py2.3-win) The general policy for Python is to support version 2.n-1 when 2.n is the current version, but not older versions than that. There was recently a 2.3.6 release with a security fix, but this is really an exception. Since Python 2.5 was released, Python 2.4 is the oldest supported Python version. I was about to give a reference to the appropriate PEP, but right now I can't for my life figure out where I read this... I'm just a bit more brain dead than usual today, due to some virus. -- http://mail.python.org/mailman/listinfo/python-list
Image creation
I need to generate wx.Bitmap with a hole in them, i.e. the whole bitmap is one colour, greyish with alpha = 255*.6, except for one rectangle that has alpha = 0 . Currently I'm doing this with PIL, thus: def _init_mask( self ): mask = Image.new( 'RGBA', self.size, color=options['mask_colour'] ) draw = ImageDraw.Draw( mask ) draw.rectangle( self.clip_area.box, fill=( 255, 255, 255, 0) ) self._mask = pilToBitmap( mask, alpha=True ) Obviously this is inefficient, but I couldn't find any way to give alpha values with wxPython's image objects and premature optimization etcetera... Well, now the program works, but is a bit sluggish so I'm asking if anyone can give me some pointers to speeding this up. /Odalrick -- http://mail.python.org/mailman/listinfo/python-list
Re: unescape HTML entities
Rares Vernica wrote: > Hi, > > Nice module! > > I downloaded 2.3 and I started to play with it. The file names have > funny names, they are all caps, including extension. > > For example the main module file is "SE.PY". Is you try "import SE" it > will not work as Python expects the file extension to be "py". > > Thanks, > Ray > > Frederic Rentsch wrote: > >> Rares Vernica wrote: >> >>> Hi, >>> >>> How can I unescape HTML entities like " "? >>> >>> I know about xml.sax.saxutils.unescape() but it only deals with "&", >>> "<", and ">". >>> >>> Also, I know about htmlentitydefs.entitydefs, but not only this >>> dictionary is the opposite of what I need, it does not have " ". >>> >>> It has to be in python 2.4. >>> >>> Thanks a lot, >>> Ray >>> >>> >> One way is this: >> >> >>> import SE # >> Download from http://cheeseshop.python.org/pypi/SE/2.2%20beta >> >>> SE.SE ('HTM2ISO.se')('input_file_name', 'output_file_name')# >> HTM2ISO.se is included >> 'output_file_name' >> >> For repeated translations the SE object would be assigned to a variable: >> >> >>> HTM_Decoder = SE.SE ('HTM2ISO.se') >> >> SE objects take and return strings as well as file names which is useful >> for translating string variables, doing line-by-line translations and >> for interactive development or verification. A simple way to check a >> substitution set is to use its definitions as test data. The following >> is a section of the definition file HTM2ISO.se: >> >> test_string = ''' >> ø=(xf8) # 248 f8 >> ù=(xf9) # 249 f9 >> ú=(xfa) # 250 fa >> û=(xfb)# 251 fb >> ü=(xfc) # 252 fc >> ý=(xfd) # 253 fd >> þ=(xfe)# 254 fe >> é=(xe9) >> ê=(xea) >> ë=(xeb) >> ì=(xec) >> í=(xed) >> î=(xee) >> ï=(xef) >> ''' >> >> >>> print HTM_Decoder (test_string) >> >> ø=(xf8) # 248 f8 >> ù=(xf9) # 249 f9 >> ú=(xfa) # 250 fa >> û=(xfb)# 251 fb >> ü=(xfc) # 252 fc >> ý=(xfd) # 253 fd >> þ=(xfe)# 254 fe >> é=(xe9) >> ê=(xea) >> ë=(xeb) >> ì=(xec) >> í=(xed) >> î=(xee) >> ï=(xef) >> >> Another feature of SE is modularity. >> >> >>> strip_tags = ''' >>~<(.|\x0a)*?>~=(9) # one tag to one tab >>~~=(9) # one comment to one tab >> | # run >>"~\x0a[ \x09\x0d\x0a]*~=(x0a)" # delete empty lines >>~\t+~=(32) # one or more tabs to one space >>~\x20\t+~=(32) # one space and one or more tabs to >> one space >>~\t+\x20~=(32) # one or more tab and one space to >> one space >> ''' >> >> >>> HTM_Stripper_Decoder = SE.SE (strip_tags + ' HTM2ISO.se ') # >> Order doesn't matter >> >> If you write 'strip_tags' to a file, say 'STRIP_TAGS.se' you'd name it >> together with HTM2ISO.se: >> >> >>> HTM_Stripper_Decoder = SE.SE ('STRIP_TAGS.se HTM2ISO.se') # >> Order doesn't matter >> >> Or, if you have two SE objects, one for stripping tags and one for >> decoding the ampersands, you can nest them like this: >> >> >>> test_string = "> style='line-height:110%'>René est un garçon qui >> paraît plus âgé. " >> >> >>> print Tag_Stripper (HTM_Decoder (test_string)) >> René est un garçon qui paraît plus âgé. >> >> Nesting works with file names too, because file names are returned: >> >> >>> Tag_Stripper (HTM_Decoder ('input_file_name'), 'output_file_name') >> 'output_file_name' >> >> >> Frederic >> >> >> >> > > Arrrgh! Did it again capitalizing extensions. We had solved this problem and here we have it again. I am so sorry. Fortunately it isn't hard to solve, renaming the files once one identifies the problem, which you did. I shall change the upload within the next sixty seconds. Frederic I'm glad you find it useful. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: wxPython 2.7.1.3
Magnus Lycka wrote: > The general policy for Python is to support version 2.n-1 when 2.n is > the current version, but not older versions than that. That's the policy for python-dev. Library providers that care about the users should, if they possibly can, support older versions than that. (especially if they *used* to support it; there's seldom any need to immediately remove *existing* support for a given Python version when a new Python release arrives..) -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic wrote: > Hi there, > > are there other ways than the ones below to check for > in a python script? > (partly inspired by wrapping Tkinter :P) > > def f(): >print "This is f(). Godspeed!" > > 1.: --> sort of clumsy and discouraged by the docs as far as I read > import types > type(f) is types.FunctionType > > 2.: --> I don't like this one at all > def null(): pass > type(f) is type(null) > > Basically I'm searching for something like: > "type(f) is func" like in: "type(x) is int" > > Any ideas? =) you could use assert. Like the one below assert inspect.isfunction(function_name) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python images processing -recap
Fredrik Lundh wrote: > alf wrote: > >> Are all supported, which is most mature, in which I could perform for >> instance 'Ken Burns effect' > > > that's a display effect, not an image effect. you need a display (or > animation) library for that. > In fact I want to generate a sequence of BMPs and feed mpeg decoder with it. A. -- http://mail.python.org/mailman/listinfo/python-list
Re: can I import the module twice (under differnet names)
alf wrote: > Hi, > > wonder if in the python I could treat modules imorts like classes > instances. It means I could import it twice or more times under > different names. > If you want to repeat the full import, and have each imported version get an independent namespace as well as independent code objects and so on then you will have to somehow persuade the interpreter that they come from different files, I believe. If you just want to be able to use several names to refer to the same module then you have already had a coupe of good answers. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
urllib2: HTTP Version not supported
I'm using urllib2 module to fetch a URL from a server which understands HTTP/1.1 only (no HTTP/1.0). urllib2.urlopen() results in "urllib2.HTTPError: HTTP Error 505: HTTP Version not supported". How do I force urllib2 to use HTTP v1.1? Regards, Nirnimesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Event driven server that wastes CPU when threaded doesn't
Snor wrote: > I'm attempting to create a lobby & game server for a multiplayer game, > and have hit a problem early on with the server design. I am stuck > between using a threaded server, and using an event driven server. I've > been told time and time again that I should use an event driven server > design (that is, use twisted). [snip] > Is the only solution to use a threaded server to let my clients make > their requests and receive a response in the fastest possible time? You got a lot of long-winded replies, but the short reply is that Twisted has packaged solutions for this. See http://twistedmatrix.com/projects/core/enterprise "Twisted provides an interface to any Python DB-API 2.0 compliant database through an asynchronous interface which allows database connections to be used, and multiplexed by multiple threads, while still remaining thread-safe for use with Twisted's event-based main loop. Twisted Enterprise provides these services by leveraging Twisted Internet's utilities for managing thread pools and asynchronous programming." -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to check if a file exists?
On Thu, 02 Nov 2006 01:44:25 +1100, Ben Finney wrote: > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > >> Ben Finney wrote: >> > "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: >> > > You could try to read the file, if that fails it doesn't exist: >> > >> > Except that there are other conditions than "File doesn't exist" >> > that can cause an 'open' to fail. >> >> Ok, true. You can test explicit on non existence as follows, and then >> decide to open the file > > Or you can simply use 'os.path.exists', as has been suggested several > times in this thread. But there can be a race condition between os.path.exists returning True and you trying to open the file, if some other process deletes or renames the file in the meantime. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Sybren Stuvel a écrit : > Christophe enlightened us with: >> I don't think it's a good idea because when you place a try catch >> block around a function call, you'll catch any exception thrown by >> the function itself and not only the "cannot be called" exception. > > That depends on the exception you're catching, doesn't it? And what if the function has an error and calls a non callable object ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python tools for managing static websites?
Glenn Hutchings wrote: > I haven't seen mention of HTMLgen, another python package. Check it > out at: > > http://starship.python.net/crew/friedrich/HTMLgen/html/main.html > > Glenn For whatever reason, the Starship (hence that link) has been down for a while. :-( But I do agree that HTMLgen is worthy of consideration (I use it myself). -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Fredrik Lundh wrote: > elderic wrote: > > > are there other ways than the ones below to check for > > in a python script? > > callable(f) > > PEP 3100 specifies that the callable builtin is to be removed in Python 3.0, together with what I presume is the underlying C support for the function. Unfortunately, there are cases where it's not advisable to call something to verify that it's callable - calling it will cause irreversable changes to the program state, while a verification function should make no changes to state. The advice is fundamentally bad design. On the other claw, I can understand Guido's point in wanting to get rid of it - it's got to be an ugly piece of code with the Inappropriate Intimacy code smell stinking up the place. So what to do? Frankly, I'd back up a few yards and consider the system design. Where is the callable coming from? If it's inside the team's scope of control, don't bother checking it - the team should have tests in place that verify that each site passing a callable is passing the correct object. If it's coming from outside, define what's allowable and check that case by case, preferably with consultation with your code's clients. John Roth -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to check if a file exists?
Steven D'Aprano wrote: > But there can be a race condition between os.path.exists returning True > and you trying to open the file, if some other process deletes or renames > the file in the meantime. if you'd used a threaded newsreader, you would have seen the code that "as follows" was referring to, and you would probably also have noticed that people have been pointing out the potential race problems several times already. -- http://mail.python.org/mailman/listinfo/python-list
Re: __div__ not recognized automatically
On Thu, 02 Nov 2006 12:59:32 +0100, Anton81 wrote: > When I execute the program it > complains that it can't find an operator "/" for "instance" and "integer". How about if you post the actual traceback you get, rather than paraphrasing? That way, we don't have to guess. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
John Roth wrote: > PEP 3100 specifies that the callable builtin is > to be removed in Python 3.0, together with what > I presume is the underlying C support for the > function. PEP 3100 is not even close to being finalized, and does not apply to Python 2.X. -- http://mail.python.org/mailman/listinfo/python-list
Re: __div__ not recognized automatically
Anton81 <[EMAIL PROTECTED]> wrote: > class NumX: >... >def __add__(self,other): > ... >def __div__(self,other): > if not isinstance(other,NumX): other=NumX(other) > ... > > Somewhere else I use > > a=(b+c)/2 > > where all variables are of NumX Type. When I execute the program it > complains that it can't find an operator "/" for "instance" and "integer". > However if I use pdb the same command works when started on the prompt. Also > the manual execution > > a=(b+c).__div__(2) > > works. Any suggestions what goes wrong? Post some code which actually demonstrates the problem. Eg, change this code until it does demonstrate the problem class NumX(object): def __init__(self, value): self.value = long(value) def __add__(self,other): if not isinstance(other,NumX): other=NumX(other) return NumX(self.value + other.value) def __div__(self,other): if not isinstance(other,NumX): other=NumX(other) return NumX(self.value / other.value) def __str__(self): return "%s(%s)" % (self.__class__.__name__, self.value) a = NumX(4) b = NumX(2) print a,b print a+b print (a+b)/2 This prints NumX(4) NumX(2) NumX(6) NumX(3) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python Journal
[EMAIL PROTECTED] wrote: ... > We'd love it if you could have a look at our first issue, and let us > know what you think! On the layout of the site: 1) I have to hit two separate Download buttons to get the PDF, and then the PDF must be viewed in an external reader rather than the browser plugin. 2) It appears that there are 3 publications to read, where in fact the third (The Python Journal itself) is an amalgam of the previous two documents. There should be some indication of this in the abstract (e.g. either a note in the Journal abstract that it consists of the previous articles, or a note in the article abstracts that it is a chapter in the journal) 3) I have to scan past two PDF pages to get to any actual content in the PDF's. 4) It would be nice to have an HTML view of these PDFs to save the irritation of waiting for the document to download and the PDF Reader from starting up. I realise that many of these issues could be limitations of the cgpublisher website, but those are my gripes with the site in any case. On the content of the first article: 1) There's a typo (well, indentation error) in the very first example (Text 2). 2) The title of the first article seems to promise more than it delivers. There are stacks of Python idioms, and this is merely one of them. If this is the first of many 'Idiom ' articles, it would be better to have a subtitle as to the nature of this specific idiom, something like "Access control in Python" or similar, with a mention of the actual name-mangling that goes on on 'private' attributes. HTH. Is the intention that this will be a free or non-free (or somewhere in between) journal BTW? -- http://mail.python.org/mailman/listinfo/python-list
Re: The Python Journal
Ant wrote: > [EMAIL PROTECTED] wrote: > ... > > We'd love it if you could have a look at our first issue, and let us > > know what you think! > > On the layout of the site: > [snip..] > 4) It would be nice to have an HTML view of these PDFs to save the > irritation of waiting for the document to download and the PDF Reader > from starting up. > > I realise that many of these issues could be limitations of the > cgpublisher website, but those are my gripes with the site in any case. > +1 for HTML content if this is intended to be a free journal. Fuzzyman http://www.voidspace.org.uk -- http://mail.python.org/mailman/listinfo/python-list
idle with ipython
Hello, I was wondering if there is a way to configure idle to call ipython instead of python? I am working with the Enthought edition of Python (Enthon 1.0.0). I use ipython in Linux all the time, but in windows I like the "Run Module" button in Idle, and would like to have both. thanks, Brian Blais -- - [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Make all files extension lower by a given directory name
>> can you post an example of a filename that misbehaves on >> your machine? >> >> > > To Fredrik Lundh and Tim Chase: > > My task was read all tga file names and generate a config xml > file, then pass this xml file to a utility, but this utillity > only read files with extension 'tga' than 'TGA'. > > I tried name + ext first but I got two dots between them, so I > wrote code that way (the strip thing), and it worked. Today it > does not work (the strip code cut last character from file > name, like you said :) ), and I changed it back, now > everything is OK. I really don't know what happened yesterday. Having a win32 program take case-sensitive filenames is a bit odd, given that the OS is case-agnostic...however, that doesn't preclude bad programming on the part of your tool-maker. Alas. Thus, to accomodate the lousy programming of your tool's maker, I proffer this: I've found that Win32 doesn't often take a rename if the origin and destination differ only in case[*]. Thus, to change the case, I've had to do *two* renames...one to, say, prefix with an underscore and change the case to my desired case, and then one to strip off the leading underscore. You might try a similar song-and-dance to strong-arm Windows into specifying the case of the file. Something like this (untested) code: filename = "Spanish Inquisition.TGA" name, ext = splitext(filename) intermediate = "_" + name + ext.lower() rename(filename, intermediate) rename(intermediate, intermediate[1:]) And then I'd wrap this contrived abomination in plenty of comments so that folks coming back to it understand why you're using three lines to do what "should" be just rename(filename, name + ext.lower()) as would be the "right" way to rename the file with a lowercase version of its extension. Yes, it's an odd filename choice there which you might not have expected...nobody expects the Spanish Inquisition... -tkc [*] Have had problems with this both in Explorer and at the command prompt. -- http://mail.python.org/mailman/listinfo/python-list
SE 2.3 temporarily unavailable. Cheese shop defeats upload with erratic behavior. Urgently requesting help.
Some time ago I had managed to upload a small package to the Cheese Shop using the data entry template. Uploading is in two steps: first the text then the package file. When I had a new version it went like this: The new text made a new page, but the new file went to the old page. The old page then had both files and all attempts at uploading the new file to the new page failed with the error message that a file could not be uploaded if it was already there. So I let it go and handed out the url of the old page, figuring that given the choice of two versions, picking the latest one was well within the capabilities of anyone. One downloader just now made me aware that the new version had misspelled extensions 'PY'. They should be lower case. So I fixed it an tried to exchange the file. One hour later I have three text pages, headed V2,2beta, V2,2beta/V2.3 and V2.3. The first (oldest) page has the old package file. The two other pages have no files. The new version package is gone, because, prior to re-uploading I was asked to delete it. The re-upload fails on all three pages with the message: 'Error processing form, invalid distribution file'. The file is a zip file made exactly the way I had made and uploaded the ones before. I am banging my real head against the proverbial wall. This thing definitely behaves erratically and I see no alternative other than to stop banging and go to the gym to take my anger out at machines and when I come back in an hour, I wish a kind, knowledgeable soul will have posted some good advice on how to vanquish such stubborn obstinacy. I have disseminated the url and the thought that someone might show up there and not find the promised goods make me really unhappy. Until such time as this upload is made, I will be happy to send SE-2.3 out off list by request. Infinite thanks Frederic -- http://mail.python.org/mailman/listinfo/python-list
Re: Style for modules with lots of constants
On 2006-11-01, Paddy <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: >> The Glk API (which I'm implementing in native Python code) >> defines 120 or so constants that users must use. The constants >> already have fairly long names, e.g., gestalt_Version, >> evtype_Timer, keycode_PageDown. >> >> Calls to Glk functions are thus ugly and tedious. >> >> scriptref = glk.fileref_create_by_prompt( >> glk.fileusage_Transcript | glk.fileusage_TextMode, >> glk.filemode_WriteAppend, 0) >> >> Please give me some good style advice for this situation. >> >> I know some modules are designed to be used as 'from XXX import >> *'. Since the Glk API is heavily influenced by its inception in >> C this might not be a huge problem. All the functions in the API >> have glk_ prepended, since C has no namespaces. I think it makes >> sense to stick the glk_'s back on the functions and instruct >> users to 'from Glk import *', but I know it doesn't conform with >> Python practice, and Python has plenty of modules that were >> originally designed in C, but don't insist on polluting the >> global namespace. >> >> Would it better to use strings instead? Some Python builtins use >> them as a way to avoid creating of global constants. >> >> scriptref = glk.fileref_create_by_prompt('Transcript+TextMode', >> 'WriteAppend', 0) >> >> Parsing the combinable bitfield contants might be slowish, >> though. >> >> Thanks for taking the time to consider my question. > > I'd check the C code to first see if I could extract the C > constant definitions and automatically convert them into > Python names vvia a short program. That way, I'd remove any > transcription errors. That's an excellent idea. I've moved all the constants to a seperate file; it should be possible to write a Python script to generate it from glk.h. If I ultimately decide to use strings instead of identifiers, the program would generate a big dictionary declaration instead of the Constants() instances. > I favour the constants class mentioned by others , but would > not mess with any of the long constant names as it helps those > who know the original C, and also helps when users need to rely > on original C documentation. I have the luxury of stylistically modifying the C API to suit Python and Python programmer's needs. I will have to take on the burden of documenting the Python GLK API. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic: > 1.: --> sort of clumsy and discouraged by the docs as far as I read > import types > type(f) is types.FunctionType What's the problem with this? from types import FunctionType if isinstance(f, FunctionType): ... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: unescape HTML entities
Rares Vernica wrote: > Hi, > > I downloades 2.2 beta, just to be sure I have the same version as you > specify. (The file names are no longer funny.) Anyway, it does not seem > to do as you said: > > In [14]: import SE > > In [15]: SE.version > ---> SE.version() > Out[15]: 'SE 2.2 beta - SEL 2.2 beta' > > In [16]: HTM_Decoder = SE.SE ('HTM2ISO.se') > > In [17]: test_string = ''' > : ø=(xf8) # 248 f8 > : ù=(xf9) # 249 f9 > : ú=(xfa) # 250 fa > : û=(xfb)# 251 fb > : ü=(xfc) # 252 fc > : ý=(xfd) # 253 fd > : þ=(xfe)# 254 fe > : é=(xe9) > : ê=(xea) > : ë=(xeb) > : ì=(xec) > : í=(xed) > : î=(xee) > : ï=(xef) > : ''' > > In [18]: print HTM_Decoder (test_string) > > ø=(xf8) # 248 f8 > ù=(xf9) # 249 f9 > ú=(xfa) # 250 fa > û=(xfb)# 251 fb > ü=(xfc) # 252 fc > ý=(xfd) # 253 fd > þ=(xfe)# 254 fe > é=(xe9) > ê=(xea) > ë=(xeb) > ì=(xec) > í=(xed) > î=(xee) > ï=(xef) > > > In [19]: > > Thanks, > Ray > > > > Frederic Rentsch wrote: > >> Rares Vernica wrote: >> >>> Hi, >>> >>> How can I unescape HTML entities like " "? >>> >>> I know about xml.sax.saxutils.unescape() but it only deals with "&", >>> "<", and ">". >>> >>> Also, I know about htmlentitydefs.entitydefs, but not only this >>> dictionary is the opposite of what I need, it does not have " ". >>> >>> It has to be in python 2.4. >>> >>> Thanks a lot, >>> Ray >>> >>> >> One way is this: >> >> >>> import SE # >> Download from http://cheeseshop.python.org/pypi/SE/2.2%20beta >> >>> SE.SE ('HTM2ISO.se')('input_file_name', 'output_file_name')# >> HTM2ISO.se is included >> 'output_file_name' >> >> For repeated translations the SE object would be assigned to a variable: >> >> >>> HTM_Decoder = SE.SE ('HTM2ISO.se') >> >> SE objects take and return strings as well as file names which is useful >> for translating string variables, doing line-by-line translations and >> for interactive development or verification. A simple way to check a >> substitution set is to use its definitions as test data. The following >> is a section of the definition file HTM2ISO.se: >> >> test_string = ''' >> ø=(xf8) # 248 f8 >> ù=(xf9) # 249 f9 >> ú=(xfa) # 250 fa >> û=(xfb)# 251 fb >> ü=(xfc) # 252 fc >> ý=(xfd) # 253 fd >> þ=(xfe)# 254 fe >> é=(xe9) >> ê=(xea) >> ë=(xeb) >> ì=(xec) >> í=(xed) >> î=(xee) >> ï=(xef) >> ''' >> >> >>> print HTM_Decoder (test_string) >> >> ø=(xf8) # 248 f8 >> ù=(xf9) # 249 f9 >> ú=(xfa) # 250 fa >> û=(xfb)# 251 fb >> ü=(xfc) # 252 fc >> ý=(xfd) # 253 fd >> þ=(xfe)# 254 fe >> é=(xe9) >> ê=(xea) >> ë=(xeb) >> ì=(xec) >> í=(xed) >> î=(xee) >> ï=(xef) >> >> Another feature of SE is modularity. >> >> >>> strip_tags = ''' >>~<(.|\x0a)*?>~=(9) # one tag to one tab >>~~=(9) # one comment to one tab >> | # run >>"~\x0a[ \x09\x0d\x0a]*~=(x0a)" # delete empty lines >>~\t+~=(32) # one or more tabs to one space >>~\x20\t+~=(32) # one space and one or more tabs to >> one space >>~\t+\x20~=(32) # one or more tab and one space to >> one space >> ''' >> >> >>> HTM_Stripper_Decoder = SE.SE (strip_tags + ' HTM2ISO.se ') # >> Order doesn't matter >> >> If you write 'strip_tags' to a file, say 'STRIP_TAGS.se' you'd name it >> together with HTM2ISO.se: >> >> >>> HTM_Stripper_Decoder = SE.SE ('STRIP_TAGS.se HTM2ISO.se') # >> Order doesn't matter >> >> Or, if you have two SE objects, one for stripping tags and one for >> decoding the ampersands, you can nest them like this: >> >> >>> test_string = "> style='line-height:110%'>René est un garçon qui >> paraît plus âgé. " >> >> >>> print Tag_Stripper (HTM_Decoder (test_string)) >> René est un garçon qui paraît plus âgé. >> >> Nesting works with file names too, because file names are returned: >> >> >>> Tag_Stripper (HTM_Decoder ('input_file_name'), 'output_file_name') >> 'output_file_name' >> >> >> Frederic >> >> >> >> > > Ray, I am sorry you're having a problem. I cannot duplicate it. It works fine here. I suspect that SE.SE doesn't find your file HTM2ISO.SE. Do this: >>> HTM_Decoder = SE.SE ('HTM2ISO.SE') >>> HTM_Decoder.show_log () Thu Nov 02 15:15:39 2006 - Compiler - Ignoring single word 'HTM2ISO.SE'. Not an existing file 'HTM2ISO.SE'. If you see this, then you might have forgotten to include the path with the file name. Rather than getting an old version, you could just have renamed the to py-files. Version 2.3 has some minor bugs corrected. I fixed the names and tried to re-upload to the Cheese Shop and the damn thing stubbornly refuses the upload after having required that I delete the file I was going to replacing
Re: other ways to check for ?
> What's the problem with this? > > from types import FunctionType > if isinstance(f, FunctionType): > ... > > Bye, > bearophile Well... it's discouraged by the docs =) At least the use of module types. I was just wondering if there were some alternatives. Never thought I would start off a thread this long =) That was basically my reason for asking about something similar like the functions list(), dict(), int(), etc... when called without (), they return . I just wanted to know if there was a keyword for functions, too. Then u could've done: type(f) is function quite similar to: type(x) is int Didn't intent to be a Documentation-Nazi *G* -elderic Excuse my large paste from the Python 2.5 Documentation: --- 5.15 types -- Names for built-in types Typical use is for functions that do different things depending on their argument types, like the following: from types import * def delete(mylist, item): if type(item) is IntType: del mylist[item] else: mylist.remove(item) Starting in Python 2.2, built-in factory functions such as int() and str() are also names for the corresponding types. This is now the preferred way to access the type instead of using the types module. Accordingly, the example above should be written as follows: def delete(mylist, item): if isinstance(item, int): del mylist[item] else: mylist.remove(item) --- -- http://mail.python.org/mailman/listinfo/python-list
Using Python within a Python application.
Hello, everyone. I am doing some searching and winding up a little bit confused. I have a MUD client that I am writing using Python and wxWidgets, as some of you may remember. What I am looking to do now, is add "trigger" functionality to it. In essence, the application receives text from the game, and if it is in any of the trigger definitions, it acts on it by executing Python code that the user has associated with the action. So, the question is, what is the safe way to do this? I have found the 'compile' function, which returns a code object(?) which I would want to execute using 'exec'. Here is a hypothetical example: I want to have a trigger that, when the game sends the text "That really did HURT!", executes code to instruct the character to ingest a potion to fix that problem. In this situation, the user would provide 'That really did HURT!' as the regular expression, which the game would examine, find that there are no RE qualifiers in there (e.g., no $, ^, or similar to bind the string to something else) and turn it into '.*(That really did HURT!).*' to match it any time the game sends it (unless it breaks in the middle of a transmission, which I wouldn't be quite sure how to handle, yet). The associated code, let's say, would be something like: Tmud.Send('quaff red') Which would send the text to the game. Eventually, I would want to support complex things, like handling $1 or $2 which might be associated with saved portions of the regex, but I will get there later. The question is really two-fold: How can I safely permit the user to specify Python to be used as part of the game, and how can I create a module that is used for the user's required functions (e.g., Tmud.Send, as an example) without requiring each trigger to 'import' something? I seem to be able to find tons of information on embedding Python in C/C++/compiled language programs, but not much on safely executing it within a Python program. What I really want to do is prevent them from calling anything that would affect the game client's runtime environment -- at least from a trigger. I want to later have some sort of "plug in" mechanism that people could use to create graphs/charts/meters of in-game events, but not yet, and that would be separate. Any ideas? Thanks in advance! -- Mike -- http://mail.python.org/mailman/listinfo/python-list
Sanity check on use of dictionaries
I am manipulating lots of log files (about 500,000 files and about 30Gb in total) to get them into a little SQL db. Part of this process is "normalisation" and creating tables of common data. I am creating dictionaries for these in a simple {value,key} form. In terms of memory and performance what are the reasonable limits for a dictionary with a key and a 16 character string? eg; if I read in one of my tables from disk into a dictionary, what sizing is comfortable? 100,000 entries? 1,000,000 entries? Lookup times and memory requirements are my main worries. (Running Python 2.3.4 on RH Ent, dual-Xeon with 2GB memory) -- http://mail.python.org/mailman/listinfo/python-list
Re: create global variables?-the full story
> OK... > > from the start. > > im trying to develop a simple command line application for determining > the degree of substitution (DS) on a polymer backbone from elemental > analysis, i.e., the % weights of different elements in the > monomer-substituent compound ( i want each element to give a result and > heaviest atoms give the most accurate results). > > most basic comp chem programs use input files but i dont know anything > about file iteration yet and want the program to be as user friendly as > possible..i.e. command line prompt. GUI would be great but too much for > me at this stage > > at the start of the script i have 2 dictionaries 1) containing every > atom in the periodic table with associated isotopic average masses 2) > containing the molecular forumla of the monomer unit...eg for cellulose > AGU {'C': 6, 'H': 10, 'O': 5}. > > the basic steps are > > 1. calculate the weight percentage values for each atom in the monomer > 2. iterate into dictionaries from DS=0 - DS=15 (0.5 step) the > projected % values for the monomer plus substituent, for EACH atom in > the compound. > 3. find the (local) minimum from each dictionary/atom to give the > appropriate DS value. > > *Note* I have to iterate ALL the values as there is a non-linear > relationship between % values and DS due to the different atomic weights > The computer seems to cope with this in about 10 seconds with the above > parameters and about 8 elements for the iteration step > Since you have a parallel structure for each element, consider using a dictionary with the element names as keys: >>> atomicdata = {} >>> for element in 'C','H','U': ... atomicdata[element] = getAtomVars(element) ... >>> print atomicdata { 'C': (1, 2), 'H': (4, 5), 'U': (78, 20) } The first value of each tuple will be your Xaa, and the second value will be Xma. Do you really need to keep the names Caa, Cma, Haa, Hma around? Instead of Caa, you have atomicdata['C'][0] and Cma becomes atomicdata['C'][1]. Completely unambiguous. A bit more verbose, perhaps, but you don't have to try to sneak around the back side of the language to find the data you are looking for. That's very much against the tao. If you really want the names, nest dicts, but don't try to get the element name into the keys, because you already have that: >>> atomicdata = { 'C': { 'aa': 1, ... 'ma': 2}, ...'H': { 'aa': 4 ... 'ma': 5}, ...'U': { 'aa': 78 ... 'ma': 20} } and to get from there to storing all your data for all however many steps, change the value of each entry in atomic data from a tuple (or dict) to a list of tuples (or dicts). >>> atomicdata = { 'C': [ (1,2), (4,6), (7,8), (20,19) ], ...'H': [ (5,7), (2,986), (3,4) ] } >>> atomicdata['H'].append((5,9)) >>> atomicdata { 'C': [ (1, 2), (4, 6), (7, 8), (20, 19) ], 'H': [ (5, 7), (2, 986), (3, 4), (5, 9) ] } You can build up those lists with nested for loops. (one tells you which element you're working on, the other which iteration). The indexes of your lists, of course, will not correspond to the DS values, but to the step number. To get back to the DS number, of course, let the index number be i, and calculate DS = i * 0.5 That should get you off and running now. Happy pythoning! Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Python in sci/tech applications
I've discovered Python and have been trying it out lately as a possible replacement for computations that would ordinarily be done with a commercial package like Matlab or IDL. I'd like to mention a few things I've run across that have either surprised me or kept me from doing things the way I'd like to. 1) -There's a large and active sci/tech Python community out there.- This was something of a surprise. If you look at the python.org site and click down a couple of levels past the front page, there's a rather brief mention of scientific and numeric applications-- but I don't think this does justice to the current levels of activity and accomplishment. 2) -There's a very impressive set of libraries out there- NumPy, SciPy, Enthought. It's really kind of stunning how mature these libraries are and how much I had to poke around to figure that out. 3) -There's a problem with development under Windows. A typical task will entail writing a 'pure python' prototype to get the 'data in, data out' part of a problem straightened out, then writing a module in C to get adequate performance in production runs. But the C compiler that my employer provides (the current version of MSVS) doesn't produce libraries that work with the current version of Python. Ooops. This, in the real world, is a big problem. I -love- Python. And I think I could convince other people to use it. But I've got to have a way to produce compiled modules painlessly, i.e., without installing a new operating system. -- http://mail.python.org/mailman/listinfo/python-list
Re: __div__ not recognized automatically
Anton81 wrote: > Hello! > > I wrote a class > > class NumX: > ... > def __add__(self,other): > ... > def __div__(self,other): > if not isinstance(other,NumX): other=NumX(other) > ... > > Somewhere else I use > > a=(b+c)/2 > > where all variables are of NumX Type. When I execute the program it > complains that it can't find an operator "/" for "instance" and "integer". > However if I use pdb the same command works when started on the prompt. > Also the manual execution > > a=(b+c).__div__(2) > > works. Any suggestions what goes wrong? If you have the from __future__ import division statement, you need to override __truediv__(), not __div__() Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: SE 2.3 temporarily unavailable. Cheese shop defeats upload with erratic behavior. Urgently requesting help.
Frederic, I've been trying to get back into my package in the Cheese Shop for over a year. The phone company changed my e:mail address and to make a long and frustrating story short I can't get back into the Cheese Shop to make changes to my file. Time is money. At some time you have to consider if it is worth it. At least you have the name of your program listed. I wish I could be more helpfull. I'll watch the responses you get from others. Good Luck, jim-on-linux http://www.inqvista.com On Thursday 02 November 2006 09:00, you wrote: > Some time ago I had managed to upload a small > package to the Cheese Shop using the data entry > template. Uploading is in two steps: first the > text then the package file. When I had a new > version it went like this: The new text made a > new page, but the new file went to the old > page. The old page then had both files and all > attempts at uploading the new file to the new > page failed with the error message that a file > could not be uploaded if it was already there. > So I let it go and handed out the url of the > old page, figuring that given the choice of two > versions, picking the latest one was well > within the capabilities of anyone. One > downloader just now made me aware that the new > version had misspelled extensions 'PY'. They > should be lower case. So I fixed it an tried to > exchange the file. One hour later I have three > text pages, headed V2,2beta, V2,2beta/V2.3 and > V2.3. The first (oldest) page has the old > package file. The two other pages have no > files. The new version package is gone, > because, prior to re-uploading I was asked to > delete it. The re-upload fails on all three > pages with the message: 'Error processing form, > invalid distribution file'. The file is a zip > file made exactly the way I had made and > uploaded the ones before. I am banging my real > head against the proverbial wall. This thing > definitely behaves erratically and I see no > alternative other than to stop banging and go > to the gym to take my anger out at machines and > when I come back in an hour, I wish a kind, > knowledgeable soul will have posted some good > advice on how to vanquish such stubborn > obstinacy. I have disseminated the url and the > thought that someone might show up there and > not find the promised goods make me really > unhappy. Until such time as this upload is > made, I will be happy to send SE-2.3 out off > list by request. > > Infinite thanks > > Frederic -- http://mail.python.org/mailman/listinfo/python-list
is mod_python borked?
I am considering python, instead of php, for web-application development. I often see mod_python.criticisized as being borked, broken, or just plain sucking. Any truth to any of that? -- http://mail.python.org/mailman/listinfo/python-list
creating new objects with references to them
It seems like what I want to do is something that programmers deal with everyday, but I just can't think of a way to do it. Basically, I am writing a DB front-end and I want a new "Researcher" object to be created whenever the user presses the "New Record" button. He can open as many new records at a time as he wants and fill in the information. What I don't know how to do is handle this arbitrary number of objects. When it comes time to save the data to the DB, how do I access each object (to get the text fields associated with each)? Won't I have to have given each instance some name? Or is there some other way to do this? Simply creating a new instance each time the user presses "New Record" won't be good enough, because how do I retain a reference to that instance over the course of the program, even after a second or third instance has been created? Hope that makes sense. It seems like such a common task. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: is mod_python borked?
walterbyrd wrote: > I am considering python, instead of php, for web-application > development. I often see mod_python.criticisized as being borked, > broken, or just plain sucking. > > Any truth to any of that? > Why don't you ask the very active mod_python mailing list that? Like all systems mod_python has its limitations, but it has an active development community who are extremely responsive to user and developer input. Follow-ups set to gmane.comp.python.mod_python. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: is mod_python borked?
walterbyrd wrote: > I am considering python, instead of php, for web-application > development. I often see mod_python.criticisized as being borked, > broken, or just plain sucking. > > Any truth to any of that? No, I've been using mod_python for a long time, and I haven't run in to any problems. In fact I use python server pages for my web development, which is much faster than python cgi scripts. http://vsbabu.org/webdev/pydev/python10.html Once you set up your server for psp pages, it's so easy. Very similar to php pages. Just give it a go and you'll like it. http://www.modpython.org/ for setting up server with mod_python. -- http://mail.python.org/mailman/listinfo/python-list
string formatter for tuple
I have the following in my code a = (1,2,3) print "a = %s" %a But when I run this, I get: TypeError: not all arguments converted during string formatting Now I realize why this happens, a is actually 3 elements when the print statement is only expecting to print one value. I tried print "a = %s" %(a) but I got the same error. How can I print a tuple with a single string format? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
mattf wrote: > I'd like to mention a few things I've run across that have either surprised > me or kept me > from doing things the way I'd like to. > > 1) -There's a large and active sci/tech Python community out there.- > This was something of a surprise. If you look at the python.org site > and click down a couple of levels past the front page, there's a rather > brief mention of scientific and numeric applications-- but I don't > think this does justice to the current levels of activity and > accomplishment. If you want an in-depth impression of how widely Python is used, python.org is not really the place that manages to provide it. Sure, "NASA uses Python" (appropriate response: dressed in a flight suit, leap up and punch the air?) but isn't OLPC (One Laptop per Child: http://www.laptop.org/) worth a mention, given the central role of Python in a device that will potentially reach millions? To the site's credit, the link to scientific and numeric applications does yield a lot of information, and I suppose it's hard to focus the site on any one thing that any given group considers of utmost importance. However, I think you're going to find that the python.org worldview can be somewhat alien, especially if your primary interest isn't Python (the language). To take another domain as an example, if you do desktop development, the treatment of graphical user interface programming on the site is quite possibly going to be completely disaligned with what you'd expect: Python is used extensively in various desktop environments (not that you'd get that impression from a cursory examination of python.org), but the python.org (or comp.lang.python) worldview mostly excludes such things as if the desktop is something you abstract away rather than take advantage of. And on the subject of how well "core Pythoneers" know of Python's successes: how many people knew that Python was used in the OLPC device before Alan Kay mentioned it at EuroPython? It's hard to promote Python when you don't know where it's being successfully used already. > 2) -There's a very impressive set of libraries out there- > NumPy, SciPy, Enthought. It's really kind of stunning how mature these > libraries are and how much I had to poke around to figure that out. I guess a lot of the poking around comes about because people are reluctant to provide any semi-official guide to the best libraries, and that the most promotion occurs for the most fashionable products in the most fashionable domains. Some of us have tried to provide better information about libraries for Python, but such details remain relatively hidden in the python.org Wiki: http://wiki.python.org/moin/UsefulModules With respect to content on python.org, I think all that remains is an acknowledgement that certain resources are never going to return to their original vitality, and that alternative mechanisms for publishing content are required. For example, the XML topic guide surely hasn't seen many updates in a very long time, and despite a reasonable level of maintenance, the database topic guide could surely be more actively maintained by aggregating package information from the package index. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
JohnJSal wrote: > It seems like what I want to do is something that programmers deal with > everyday, but I just can't think of a way to do it. Basically, I am > writing a DB front-end and I want a new "Researcher" object to be > created whenever the user presses the "New Record" button. He can open > as many new records at a time as he wants and fill in the information. > Seems straightforward. > What I don't know how to do is handle this arbitrary number of objects. > When it comes time to save the data to the DB, how do I access each > object (to get the text fields associated with each)? Won't I have to > have given each instance some name? Or is there some other way to do > this? Simply creating a new instance each time the user presses "New > Record" won't be good enough, because how do I retain a reference to > that instance over the course of the program, even after a second or > third instance has been created? > Start with an empty list, and append new instances to it. Then when the user indicated completion you can iterate over the list INSERTing them into the database (presumably INSERTing the new researcher's details first). To minimize consistency problems it would help to make all of these insertions as a single database transaction. > Hope that makes sense. It seems like such a common task. > regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
> a = (1,2,3) > print "a = %s" %a > > But when I run this, I get: > > TypeError: not all arguments converted during string formatting > > Now I realize why this happens, a is actually 3 elements when the print > statement is only expecting to print one value. I tried > > print "a = %s" %(a) > > but I got the same error. > > How can I print a tuple with a single string format? You can try print "a = %s" % str(a) or print "a = %s" % repr(a) which should both do the trick. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
jeremito wrote: > I have the following in my code > > a = (1,2,3) > print "a = %s" %a > > But when I run this, I get: > > TypeError: not all arguments converted during string formatting > > Now I realize why this happens, a is actually 3 elements when the print > statement is only expecting to print one value. I tried > > print "a = %s" %(a) > > but I got the same error. > > How can I print a tuple with a single string format? > Thanks, > Jeremy > Try print "a = %s" % (a, ) The exception to the "a single object can be formatted as a single argument rather than a tuple" rule is when that single object is itself a tuple! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
> "Tim" == Tim Chase <[EMAIL PROTECTED]> writes: >> How can I print a tuple with a single string format? Tim>print "a = %s" % str(a) Tim> or Tim>print "a = %s" % repr(a) Or wrap the tuple in a tuple: print "a = %s" % (a,) Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
Tim Chase wrote: > print "a = %s" % repr(a) or print "a = %r" % (a,) -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
In <[EMAIL PROTECTED]>, jeremito wrote: > I have the following in my code > > a = (1,2,3) > print "a = %s" %a > > But when I run this, I get: > > TypeError: not all arguments converted during string formatting > > Now I realize why this happens, a is actually 3 elements when the print > statement is only expecting to print one value. I tried > > print "a = %s" %(a) > > but I got the same error. > > How can I print a tuple with a single string format? Put the tuple in a tuple: print 'a = %s" % (a,) And remember: not the parenthesis create a tuple but the comma! Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
In <[EMAIL PROTECTED]>, JohnJSal wrote: > What I don't know how to do is handle this arbitrary number of objects. > When it comes time to save the data to the DB, how do I access each > object (to get the text fields associated with each)? Won't I have to > have given each instance some name? Or is there some other way to do > this? Simply creating a new instance each time the user presses "New > Record" won't be good enough, because how do I retain a reference to > that instance over the course of the program, even after a second or > third instance has been created? Put your objects into a list. Each time the user presses the `New` Button append a new researcher object to it. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
On Nov 2, 3:15 pm, "JohnJSal" <[EMAIL PROTECTED]> wrote: > It seems like what I want to do is something that programmers deal with > everyday, but I just can't think of a way to do it. Basically, I am > writing a DB front-end and I want a new "Researcher" object to be > created whenever the user presses the "New Record" button. He can open > as many new records at a time as he wants and fill in the information. > > What I don't know how to do is handle this arbitrary number of objects. > When it comes time to save the data to the DB, how do I access each > object (to get the text fields associated with each)? Won't I have to > have given each instance some name? It all depends on what UI you are using (Web frontend? GUI such as Tkinter?) and what your use case is. What is it exactly that you want to do? Create a bunch of Researcher objects and then save them in a single hit? Create a list of Researchers and then choose which to save to the db? Populate a list of researchers from the db, and have the option of editing or adding new ones? Should the new Researcher objects be committed to the db as soon as they are saved? Anyway, a simple list of Researchers should suffice for any of these purposes, and assuming you want to commit them all in one hit, you have a list of objects ready to iterate over. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sanity check on use of dictionaries
[EMAIL PROTECTED] wrote: > I am manipulating lots of log files (about 500,000 files and about 30Gb > in total) to get them into a little SQL db. Part of this process is > "normalisation" and creating tables of common data. I am creating > dictionaries for these in a simple {value,key} form. > > In terms of memory and performance what are the reasonable limits for a > dictionary with a key and a 16 character string? eg; if I read in one > of my tables from disk into a dictionary, what sizing is comfortable? > 100,000 entries? 1,000,000 entries? Lookup times and memory > requirements are my main worries. you don't specify what a "key" is, but the following piece of code took less than a minute to write, ran in roughly two seconds on my machine, and results in a CPython process that uses about 80 megabytes of memory. >>> d = {} >>> for i in range(100): ... k = str(i).zfill(16) ... d[k] = k ... >>> k '0099' since dictionaries use hash tables, the lookup time is usually independent of the dictionary size. also see: http://www.effbot.org/pyfaq/how-are-dictionaries-implemented.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
Christophe a écrit : > Sybren Stuvel a écrit : >> Christophe enlightened us with: >>> I don't think it's a good idea because when you place a try catch >>> block around a function call, you'll catch any exception thrown by >>> the function itself and not only the "cannot be called" exception. >> >> That depends on the exception you're catching, doesn't it? > > And what if the function has an error and calls a non callable object ? Or even worse. Since we have : >>> None() Traceback (most recent call last): File "", line 1, in ? TypeError: 'NoneType' object is not callable >>> 1+"" Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> ""+1 Traceback (most recent call last): File "", line 1, in ? TypeError: cannot concatenate 'str' and 'int' objects All of them are TypeError exceptions. It is extremly dangerous to put a try except TypeError clause around a function call to catch the case where the function object isn't a callable :/ -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic wrote: > I just wanted to know if there was a keyword for functions, too. > > Then u could've done: type(f) is function > quite similar to: type(x) is int but why do you think you need that, when you have callable() ? unless you're doing specialized stuff, there's really no reason to distinguish between function objects and other callables. -- http://mail.python.org/mailman/listinfo/python-list
Help on writing P2P Streaming client
I want to write a P2P streaming client where ine user broadcasts and many users receive the streaming content and forward like BitTorrent. Can anybody provide pointers for starting in Python. I have done couple of small projects in Python but I need to get this done. Every help is appreciated. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on writing P2P Streaming client
Daniel wrote: > I want to write a P2P streaming client where ine user broadcasts and > many users receive the streaming content and forward like BitTorrent. > > Can anybody provide pointers for starting in Python. I have done couple > of small projects in Python but I need to get this done. > > Every help is appreciated. > I take it you know BitTorrent is written in Python? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: is mod_python borked?
walterbyrd wrote: > I am considering python, instead of php, for web-application > development. I often see mod_python.criticisized as being borked, > broken, or just plain sucking. > > Any truth to any of that? Hi, mod_python is Apache/Python Integration. AFAIK you can't use it with a different webserver. I use quixote with plain old CGI. It is fast enough for my stuff. If there is heavy load, I would try SCGI. Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/ E-Mail: guettli (*) thomas-guettler + de Spam Catcher: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
Ant wrote: > It all depends on what UI you are using (Web frontend? GUI such as > Tkinter?) and what your use case is. Making it myself with wxPython. > > What is it exactly that you want to do? Create a bunch of Researcher > objects and then save them in a single hit? Create a list of > Researchers and then choose which to save to the db? Populate a list of > researchers from the db, and have the option of editing or adding new > ones? Should the new Researcher objects be committed to the db as soon > as they are saved? There are two options: save current record and save all records, both of which put the info in the DB immediately. > Anyway, a simple list of Researchers should suffice for any of these > purposes, and assuming you want to commit them all in one hit, you have > a list of objects ready to iterate over. Ok, so in making a list does this mean that I won't have a name for each instance? I just have to iterate over the list when I need them? I'm not sure how I would do this if the user chooses just to save a single record and not all of them. -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
> > I just wanted to know if there was a keyword for functions, too. > > > > Then u could've done: type(f) is function > > quite similar to: type(x) is int > > but why do you think you need that, when you have callable() ? unless > you're doing specialized stuff, there's really no reason to distinguish > between function objects and other callables. > > I never said that I need anything - I merely asked for alternatives. =) I'm pretty happy with the types-module or the callable() test. Basically it's just for wrapping the creation of Tk-Buttons, etc. They need a callback and in my process to learn I wanted to know about the possible options to test for that. peace of mind. =) elderic -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
JohnJSal wrote: > Ant wrote: > > >>It all depends on what UI you are using (Web frontend? GUI such as >>Tkinter?) and what your use case is. > > > Making it myself with wxPython. > > >>What is it exactly that you want to do? Create a bunch of Researcher >>objects and then save them in a single hit? Create a list of >>Researchers and then choose which to save to the db? Populate a list of >>researchers from the db, and have the option of editing or adding new >>ones? Should the new Researcher objects be committed to the db as soon >>as they are saved? > > > There are two options: save current record and save all records, both > of which put the info in the DB immediately. > > > >>Anyway, a simple list of Researchers should suffice for any of these >>purposes, and assuming you want to commit them all in one hit, you have >>a list of objects ready to iterate over. > > > Ok, so in making a list does this mean that I won't have a name for > each instance? I just have to iterate over the list when I need them? > I'm not sure how I would do this if the user chooses just to save a > single record and not all of them. > Suppose you have a function dBWrite(r), where r is (some representation of) a record you want to write into the database. Further suppose you currently have 10 records, stored in a list rec, with indices 0 through 9. To write record 7 only you could use dbWrite(rec[7]) conn.commit() # assuming dbWrite uses connection conn del rec[7] # you'd also want to kill the window containing this record To write them all you might try for r in rec: dbWrite(r) conn.commit() rec = [] # Close all record windows regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: string formatter for tuple
[EMAIL PROTECTED] wrote: > > "Tim" == Tim Chase <[EMAIL PROTECTED]> writes: > > >> How can I print a tuple with a single string format? > > Tim>print "a = %s" % str(a) > Tim> or > Tim>print "a = %s" % repr(a) > > Or wrap the tuple in a tuple: > > print "a = %s" % (a,) > > Skip Thank you all very much for your help. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
Steve Holden wrote: > del rec[7] Hmmm, but what if the record can remain open, changes can be made, and then saved again to the same object? I suppose it isn't necessary to delete them, right? Man, this stuff gets complicated -- http://mail.python.org/mailman/listinfo/python-list
Re: other ways to check for ?
elderic wrote: > I never said that I need anything - I merely asked for alternatives. =) > I'm pretty happy with the types-module or the callable() test. > > Basically it's just for wrapping the creation of Tk-Buttons, etc. > They need a callback and in my process to learn I wanted to know about > the possible options to test for that. the more reason not to even think about using anything but "callable". many things in Python are callable; an explicit function test would disallow several interesting alternatives: >>> def foo(): ... pass ... >>> class fum: ... def bar(self): ... pass ... def __call__(self): ... pass ... >>> type(foo) is type(fum) False >>> f = fum() >>> type(foo) is type(f) False >>> type(foo) is type(f.bar) False etc. (and I really shouldn't ask why you cannot just use Tkinter, and spend your time and energy on something more worthwhile ? if not else, there are plenty of Tk extensions that could need nice wrappers...) -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
JohnJSal wrote: > Hope that makes sense. It seems like such a common task. Ok, I'm thinking about the suggestion to make a list, but I'm still confused. Even with a list, how do I access each instance. Would I have to do it by index? I assume I'd do something like this: self.records = []# list for storing instances Then when "New Record" is clicked: def OnNewRecord(self, event): self.records.append(Researchers()) But now what? There is still no reference to that instance? The only thing I can think of is that each record will be a tab in a wxPython notebook control, and each tab can be referenced by index. So whichever tab I'm on, I can use that index to get that particular instance in the list. But this solution seems too tied to my particular implementation. How would you normally access these instances in the list? Let's say there are three objects in the list. Someone fills out the text fields for the second one and clicks "Save". I know how to read all the information in the fields, but how do I then associate it with that second instance? (Or I wonder if I really even need to, since upon saving, the information gets stored in the database immediately. Maybe I don't even need a Researcher class at all.) -- http://mail.python.org/mailman/listinfo/python-list
Forum written in Python?
Are there any forum or bulletin board systems written entirely in Python? I got sick of PhpBB, mostly because I can't tweak and fiddle with the code, since I really don't like PHP and don't know it that well. I thought of writting my own simple forum software, but if there are existing projects out there, I wouldn't mind contributing. So far I found out about Pocoo, but it seems to immature right now, I was looking for something comparable to PhpBB or IPB? -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
> >> Anyway, a simple list of Researchers should suffice for any of these >> purposes, and assuming you want to commit them all in one hit, you have >> a list of objects ready to iterate over. > > Ok, so in making a list does this mean that I won't have a name for > each instance? I just have to iterate over the list when I need them? > I'm not sure how I would do this if the user chooses just to save a > single record and not all of them. It means exactly that, and where is the problem? If the user choses to save just one record, she has to somehow select the one in question, hasn't she? So, she selects it from the list. And then you _know_ the index or even the record itself. If it helps you, think of the index of the list as the name of the record... Diez -- http://mail.python.org/mailman/listinfo/python-list
Converting a .dbf file to a CSV file
Is there a module/method in python to convert a file from .DBF format to .CSV format? Johanna Pfalz -- http://mail.python.org/mailman/listinfo/python-list
Re: is mod_python borked?
I used it for various projects. It's alright. The only problem I had, was that I was unable to get mod_python and pysqlite to work together. Other than that it was pretty good. --- walterbyrd <[EMAIL PROTECTED]> wrote: > I am considering python, instead of php, for > web-application > development. I often see mod_python.criticisized as > being borked, > broken, or just plain sucking. > > Any truth to any of that? > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a .dbf file to a CSV file
Johanna Pfalz <[EMAIL PROTECTED]> wrote: > Is there a module/method in python to convert a file from .DBF > format to .CSV format? > > Johanna Pfalz > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715 There is an example provided. max -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
mattf: > 3) -There's a problem with development under Windows. It's possibile to compile Python with MinGW, and to create extensions with it. So some site can host a single zip file that contains both MinGW and Python compiled with it, all ready and set. A person not much expert can then create compiled small extensions in a short time without too much complexities. (Or maybe the D language can be packed into that, instead of MinGW, to do similar things. D can be a good language used with Python) But then probably PIL, scipy, etc have to be compiled again for such alternative official or semi-official Python distribution. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a .dbf file to a CSV file
> Is there a module/method in python to convert a file from .DBF format to > .CSV format? Well, at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715 there's a recipe for reading DBF files...iterating over the returned data from the function declared there, it should be pretty easy to simply dump the results to a CSV file...something like this untested: outfile = file('out.txt', 'w') for i, row in enumerate(dbfreader(file('x.txt'))): if i == 1: continue # skip colinfo line outfile.write('"') outfile.write('","'.join(str(v) for v in row)) outfile.write('"\n') Escaping quotes becomes mildly hairier, but only because there are a number of ways to do it. You'd just modify the "str(v)" with your escaping function...something like doubling them str(v).replace('"', '""') or str(v).replace('\\', '').replace('"', '\\"') using backslashes (where standalone-backslashes get escaped too) Just a few idea, -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
JohnJSal wrote: > Steve Holden wrote: > > >> del rec[7] > > > Hmmm, but what if the record can remain open, changes can be made, and > then saved again to the same object? I suppose it isn't necessary to > delete them, right? Man, this stuff gets complicated > Right. Of course, once you've written a record to the database for the first time you need a flag to tell you it exists so that further changes are made with UPDATE statements. But ultimately it's just a matter of synchronizing the contents of an internal data structure with the contents of a set of windows (typically dialogs) and a database. Another option is to use an object-relational mapper like SQLObject or SQLalchemy to hide most of the database ferkling. The complexity is known as "real life". Get used to it ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: creating new objects with references to them
JohnJSal wrote: > JohnJSal wrote: > > >>Hope that makes sense. It seems like such a common task. > > > Ok, I'm thinking about the suggestion to make a list, but I'm still > confused. Even with a list, how do I access each instance. Would I have > to do it by index? I assume I'd do something like this: > > self.records = []# list for storing instances > > Then when "New Record" is clicked: > > def OnNewRecord(self, event): > self.records.append(Researchers()) > > But now what? There is still no reference to that instance? The only > thing I can think of is that each record will be a tab in a wxPython > notebook control, and each tab can be referenced by index. So whichever > tab I'm on, I can use that index to get that particular instance in the > list. > > But this solution seems too tied to my particular implementation. How > would you normally access these instances in the list? > > Let's say there are three objects in the list. Someone fills out the > text fields for the second one and clicks "Save". I know how to read > all the information in the fields, but how do I then associate it with > that second instance? > > (Or I wonder if I really even need to, since upon saving, the > information gets stored in the database immediately. Maybe I don't even > need a Researcher class at all.) > How about having a list of tuples: (record, window). Each window has to "know" which item it's editing. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
[EMAIL PROTECTED] wrote: > mattf: >> 3) -There's a problem with development under Windows. > > It's possibile to compile Python with MinGW, and to create extensions > with it. So some site can host a single zip file that contains both > MinGW and Python compiled with it, all ready and set. A person not much > expert can then create compiled small extensions in a short time > without too much complexities. (Or maybe the D language can be packed > into that, instead of MinGW, to do similar things. D can be a good > language used with Python) But then probably PIL, scipy, etc have to be > compiled again for such alternative official or semi-official Python > distribution. With a few caveats, mingw will simply work with the standard 2.4 (and presumably 2.5) interpreter. We distribute mingw set up to do this with our "Enthought Edition" Python distribution. http://code.enthought.com/enthon/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
[EMAIL PROTECTED] wrote: > mattf: >> 3) -There's a problem with development under Windows. > > It's possibile to compile Python with MinGW, and to create extensions > with it. So some site can host a single zip file that contains both > MinGW and Python compiled with it, all ready and set. A person not much > expert can then create compiled small extensions in a short time > without too much complexities. (Or maybe the D language can be packed > into that, instead of MinGW, to do similar things. D can be a good > language used with Python) But then probably PIL, scipy, etc have to be > compiled again for such alternative official or semi-official Python > distribution. > Is it really not possible to create extension libs with older MSVC or Mingw, which work with regular Python binaries version 2.4 and 2.5 ? Maybe with some special import libraries? (another option is to stay with Python2.3, which has a small memory footprint and compiles with crtl4.2 libs (VC6, ...) ) -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
robert wrote: > Is it really not possible to create extension libs with > older MSVC or Mingw, which work with regular Python binaries > version 2.4 and 2.5 ? last time I tried, it took me 20 minutes from that I typed "mingw" into google until I had built and tested my first non-trivial extension. your milage may vary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
Robert Kern: > We distribute mingw set up to do this with our "Enthought > Edition" Python distribution. > http://code.enthought.com/enthon/ Sorry, maybe I'm blind but I don't see MinGW listed in that page... Maybe it's included but not listed... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
refcounting errors???
Hi, I have a few problems with the C-API. I am trying to embed Python in a simulator that I am writing (I am replacing my previous Guile-based scripting system (mostly as pyrex is a lot nicer than swig and the fact that PyUnit is really nice)). Non the less, my problems come when dealing with callbacks from my C-code to python 2.4.4. This is the python code that is executed (through PyRun_SimpleFile): -- import io import config config.setScreenSize(800, 600) def foo(a, b, c): print a, b, c io.registerButtonHandler("foo", foo) # register foo as io-callback io.bindKeyUp("a", "foo") # bind the a-key to the foo function -- Where io and config are two pyrex generated modules. Now, when I start tapping the a-key foo is activated (and prints its arguments), but is only done so 8 times, on the 9th time the app crashes in the internal_print function invoked by the print-statement. The registration of the callback is done by Py_INCREF(f); ah->u.button.u.s = f; The invokation of the foo-function goes somewhere in the line of: PyObject *up = PyBool_FromLong(1L); if (! up) PyErr_Print(); PyObject *res = PyObject_CallFunction(action.u.button.u.s, "(NIH)", up, (unsigned int)key, (unsigned short)special); if (! res) PyErr_Print(); Py_XDECREF(res); Py_XDECREF(up); I would suppose that I have made a mistake somewhere, but cannot really figure out what. So I would appreciate any pointers on what I can have done wrong. Best regards and thanks in advance, Mattias -- http://mail.python.org/mailman/listinfo/python-list
Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?
I'd like to use multiple CPU cores for selected time consuming Python computations (incl. numpy/scipy) in a frictionless manner. Interprocess communication is tedious and out of question, so I thought about simply using a more Python interpreter instances (Py_NewInterpreter) with extra GIL in the same process. I expect to be able to directly push around Python Object-Trees between the 2 (or more) interpreters by doing some careful locking. Any hope to come through? If possible, what are the main dangers? Is there an example / guideline around for that task? - using ctypes or so. Or is there even a ready made Python module which makes it easy to setup and deal with extra Interpreter instances? If not, would it be an idea to create such thing in the Python std libs to make Python multi-processor-ready. I guess Python will always have a GIL - otherwise it would loose lots of comfort in threaded programming robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
[EMAIL PROTECTED] wrote: > Robert Kern: >> We distribute mingw set up to do this with our "Enthought >> Edition" Python distribution. >> http://code.enthought.com/enthon/ > > Sorry, maybe I'm blind but I don't see MinGW listed in that page... > Maybe it's included but not listed... It's there. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
Fredrik Lundh wrote: > robert wrote: > >> Is it really not possible to create extension libs with > > older MSVC or Mingw, which work with regular Python binaries > > version 2.4 and 2.5 ? > > last time I tried, it took me 20 minutes from that I typed "mingw" into > google until I had built and tested my first non-trivial extension. your > milage may vary. thats far beyond my dexterity. When one follows .. http://docs.python.org/inst/tweak-flags.html#SECTION000622000 http://www.zope.org/Members/als/tips/win32_mingw_modules ..this seems only to cover the immediate python dll issues. What happens with the C runtime libraries? You'll bind 2 different C-RTLs (DLLs) etc.? And what happens for example with heap objects created with one C-RTL and deleted/free'd with the other? -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Forum written in Python?
Karlo Lozovina пишет: > Are there any forum or bulletin board systems written entirely in Python? > I got sick of PhpBB, mostly because I can't tweak and fiddle with the > code, since I really don't like PHP and don't know it that well. > > I thought of writting my own simple forum software, but if there are > existing projects out there, I wouldn't mind contributing. So far I found > out about Pocoo, but it seems to immature right now, I was looking for > something comparable to PhpBB or IPB? > > Django-based: http://wiki.woodpecker.org.cn/moin/UliPad http://zyons.com --- http://python.com.ua -- http://mail.python.org/mailman/listinfo/python-list
problem with svd in numpy
Hello, I am having weird problem with svd routine in python. I am comparing eigenvector values from python and matlab. And they are giving different values. Actually, they are same but python gives negative values of these numbers. This is my test program (I am dealing with 100x100 matrices) with the array I used in matlab. from numpy import* a=zeros((10,10)) a=array([ [6,-1,-1,-1,-1,-1,-1,0,0,0], [-1,7,-1,-1,-1,-1,-1,-1,0,0], [-1,-1,7,-1,-1,-1,-1,-1,0,0], [-1,-1,-1,6,-1,-1,-1,0,0,0], [-1,-1,-1,-1,6,-1,-1,0,0,0], [-1,-1,-1,-1,-1,8,-1,-1,-1,0], [-1,-1,-1,-1,-1,-1,9,-1,-1,-1], [0,-1,-1,0,0,-1,-1,6,-1,-1], [0,0,0,0,0,-1,-1,-1,4,-1], [0,0,0,0,0,0,-1,-1,-1,3]]) u,w,vt = linalg.svd(a) print u Output: u array([[ -1.05409255e-01, 1.48045079e-01, -2.22322513e-01, 3.54544091e-15, 3.70413913e-01, -7.27640158e-01, 2.60327955e-01, 1.08243955e-01, -2.67189407e-01, 3.16227766e-01], [ -1.05409255e-01, 8.51968962e-02, 5.37745352e-01, 7.07106781e-01, 4.44089210e-16, 3.88578059e-15, -2.31331268e-01, 4.16676907e-02, -1.92898838e-01, 3.16227766e-01], [ -1.05409255e-01, 8.51968962e-02, 5.37745352e-01, -7.07106781e-01, -1.06858966e-15, -3.05311332e-15, -2.31331268e-01, 4.16676907e-02, -1.92898838e-01, 3.16227766e-01], [ -1.05409255e-01, 1.48045079e-01, -2.22322513e-01, -3.52416288e-15, 4.44947906e-01, 6.84607937e-01, 2.60327955e-01, 1.08243955e-01, -2.67189407e-01, 3.16227766e-01], [ -1.05409255e-01, 1.48045079e-01, -2.22322513e-01, 1.16652940e-15, -8.15361818e-01, 4.30322209e-02, 2.60327955e-01, 1.08243955e-01, -2.67189407e-01, 3.16227766e-01], [ -1.05409255e-01, -9.20330077e-01, -1.07260256e-01, 1.88817436e-15, 1.11022302e-16, -3.33066907e-16, -4.57953818e-02, -1.32746681e-01, -1.03236512e-01, 3.16227766e-01], [ 9.48683298e-01, 7.14706072e-16, -1.04777298e-15, 3.61617704e-16, -8.32667268e-17, -1.52655666e-16, -2.08166817e-16, -9.36750677e-17, 1.42247325e-16, 3.16227766e-01], [ -1.05409255e-01, 2.15015734e-01, -4.92200980e-01, -1.55431223e-15, 4.85722573e-16, -2.77555756e-16, -7.46027799e-01, -1.27670308e-01, 1.65946178e-01, 3.16227766e-01], [ -1.05409255e-01, 1.51153561e-01, 1.21762878e-01, 1.66533454e-15, 1.80411242e-16, 3.46944695e-16, 3.33969907e-01, -7.50787335e-01, 4.19520882e-01, 3.16227766e-01], [ -1.05409255e-01, -6.03682488e-02, 6.91751920e-02, -1.23512311e-15, -2.28983499e-16, 2.08166817e-17, 1.39531945e-01, 6.03137078e-01, 7.05135347e-01, 3.16227766e-01]]) Matlab output: u = 0.1054 -0.1480 0.2223 -0. 0. 0.8165 0.2603 0.1082 -0.2672 0.3162 0.1054 -0.0852 -0.5377 0.7071 -0. -0. -0.2313 0.0417 -0.1929 0.3162 0.1054 -0.0852 -0.5377 -0.7071 0. -0. -0.2313 0.0417 -0.1929 0.3162 0.1054 -0.1480 0.2223 -0. -0.7071 -0.4082 0.2603 0.1082 -0.2672 0.3162 0.1054 -0.1480 0.2223 0. 0.7071 -0.4082 0.2603 0.1082 -0.2672 0.3162 0.1054 0.9203 0.1073 0. 0. -0. -0.0458 -0.1327 -0.1032 0.3162 -0.9487 0. -0. 0. -0. -0. -0. 0. 0. 0.3162 0.1054 -0.2150 0.4922 0. 0. 0. -0.7460 -0.1277 0.1659 0.3162 0.1054 -0.1512 -0.1218 -0. -0. -0. 0.3340 -0.7508 0.4195 0.3162 0.1054 0.0604 -0.0692 0. 0. -0. 0.1395 0.6031 0.7051 0.3162 I am not sure if svd in numpy has a problem or not. When I test this matrix in matlab, eigenvector values are different, Any idea why I am not getting exact results from both program? Any input will be appreciated. Best, Nevin -- http://mail.python.org/mailman/listinfo/python-list
Creating db front end or middleware.
Let's say I want to write a new tool to do something to, or report on people in a database. Each tool is going to have to have all sorts of routines that know about the relationship between the data. The first thought is to write a library of routines that do things like, change_address(), or fire_employee() or whatever. Whoops, now we've decided to move to python. I have to write all of that again. So I thought, shouldn't there be a cloud that sits in front of the database to which I can ask these services of? Some process that awaits requests for information, or handles new incoming data. Now new apps written in any language should be able to use a basic protocol in order to get the work done. The question then, is what the best way to do this is. First I thought of using cherrypy to sit and listen to POST requests, but this would make passing complex structures extremely inconvenient. Then I thought about WSDL. Would this be the next logical step, or is this more for allowing different companies to communicate with each other when there needs to be a broadcast description of the interface? If it is to be WSDL, what is a good place to get concise information as to how to set this up? It would be written in python. Thanks, Tobiah -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python in sci/tech applications
Fredrik Lundh: > last time I tried, it took me 20 minutes from that I typed "mingw" into > google until I had built and tested my first non-trivial extension. your > milage may vary. But probably before those 20 minutes there is a lot of time of experience of yours with CPython sources, other compilers, and so on, so for most people this timing comparison just means "It can be done" :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Forum written in Python?
Hello, Look at Karrigell, it includes the base of a forum and a blog in is demo Karrigell is a wonderfull pythonic framework. It's simple and efficient. Thanks his author Regards slav0nic a écrit : > Karlo Lozovina ÐÉÛÅÔ: > > Are there any forum or bulletin board systems written entirely in Python? > > I got sick of PhpBB, mostly because I can't tweak and fiddle with the > > code, since I really don't like PHP and don't know it that well. > > > > I thought of writting my own simple forum software, but if there are > > existing projects out there, I wouldn't mind contributing. So far I found > > out about Pocoo, but it seems to immature right now, I was looking for > > something comparable to PhpBB or IPB? > > > > > Django-based: > http://wiki.woodpecker.org.cn/moin/UliPad > http://zyons.com > > --- > http://python.com.ua -- http://mail.python.org/mailman/listinfo/python-list
Re: Exploiting Dual Core's with Py_NewInterpreter's separated GIL ?
On Thu, 02 Nov 2006 19:32:54 +0100, robert <[EMAIL PROTECTED]> wrote: >I'd like to use multiple CPU cores for selected time consuming Python >computations (incl. numpy/scipy) in a frictionless manner. NumPy releases the GIL in quite a few places. I haven't used scipy much, but I would expect it does too. Are you certain you need this complexity? Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list