ANN: SciPy 2008 Conference
Greetings, The SciPy 2008 Conference website is now open: http://conference.scipy.org This year's conference will be at Caltech from August 19-24: Tutorials:August 19-20 (Tuesday and Wednesday) Conference: August 21-22 (Thursday and Friday) Sprints: August 23-24 (Saturday and Sunday) Exciting things are happening in the Python community, and the SciPy 2008 Conference is an excellent opportunity to exchange ideas, learn techniques, contribute code and affect the direction of scientific computing (or just to learn what all the fuss is about). We'll be announcing the Keynote Speaker and providing a detailed schedule in the coming weeks. This year we are asking presenters to submit short papers to be included in the conference proceedings: http://conference.scipy.org/call_for_papers Cheers, -- Jarrod Millman Computational Infrastructure for Research Labs 10 Giannini Hall, UC Berkeley phone: 510.643.4014 http://cirl.berkeley.edu/ -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Pyrex 0.9.8.4
Pyrex 0.9.8.4 is now available: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ This version fixes a bug introduced by the last change to unsigned integer indexing. What is Pyrex? -- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: How to kill a thread?
On Jun 10, 3:41 pm, Fuzzyman [EMAIL PROTECTED] wrote: On Jun 10, 2:03 am, Rhamphoryncus [EMAIL PROTECTED] wrote: So how does .NET deal with the sys.stdout corruption? Does it? That has never been an issue for us. Of course. It's far more likely to hit the underlying blocked I/O than the buffer management, unless it's doing a great deal of I/O. Or alternatively, they're using some other mechanism to prevent interruption during buffer management. If you've carefully written your code to use only safe primitives and local state (discarded if interrupted) then yes, it could be interruptible. At this point you could specially mark that block of code as safe, leaving the vast majority of other code unsafe by default. Then again, since you're going to the trouble of carefully designing and auditing your code you could just make it cancellable like blocking I/O should be - just by polling a flag at key points (and you're CPU-bound anyway, so it's not expensive.) The only place I know of that you *need* arbitrary interruption is hitting CTRL-C in the interactive interpreter. At this point it's a debugging tool though, so the risk of weirdness is acceptable. We use background threads for long running calculations that we know are safe to abort. Resources that need protecting we do with finally blocks which the thread abort honours. How does that protect code like this? f = open('somefile', 'w') # interruption here try: ... finally: ... The calculation is 'coarse grained' (it can call into .NET APIs that can take a relatively long time to return) - so polling for exit wouldn't work anyway. We also run user code and can't expect their code to poll for exit conditions. Do those .NET get interrupted at arbitrary points? Is this untrusted user code also audited for correctness? (Although I'd bet you simply document what you do and blame the user if something breaks.) I'm not saying it can't be made to work in your specific case - it likely does work well for you. I'm saying it can't work *in general*. Stretching it out for general use turns those little cracks into massive canyons. A language needs a general mechanism that does work - such as a polite cancellation API. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
Why not use a normal Queue, put a dummy value (such as None) in when you're producer has finished, and have the main thread use the normal Thread.join() method on all your child threads? -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
On Jun 10, 11:33 pm, George Sakkis [EMAIL PROTECTED] wrote: I'd like some feedback on a solution to a variant of the producer- consumer problem. My first few attempts turned out to deadlock occasionally; this one seems to be deadlock-free so far but I can't tell if it's provably correct, and if so, whether it can be simplified. The generic producer-consumer situation with unlimited buffer capacity is illustrated athttp://docs.python.org/lib/condition-objects.html. That approach assumes that the producer will keep producing items indefinitely, otherwise the consumer ends up waiting forever. The extension to the problem I am considering requires the consumer to be notified not only when there is a new produced item, but also when there is not going to be a new item so that it stops waiting. Sounds like a sentinel would work for this. The producer puts a specific object (say, None) in the queue and the consumer checks for this object and stops consuming when it sees it. But that seems so obvious I suspect there's something else up. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock() or Windows bug?
Nick Craig-Wood [EMAIL PROTECTED] wrote: Hmmm, 10,000,000 cycles (40 ms @2.5GHz) is nowhere near the ~90,000 second jump in time.clock() output reported by the OP. I wonder if there could be a different cause? Just wild theorizing, but it's possible that they are actually getting a negative delta, and some kind of signed/unsigned manipulation produces the 90,000 number. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On 6 Juni, 03:09, Russ P. [EMAIL PROTECTED] wrote: On Jun 5, 2:57 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote: Russ P. [EMAIL PROTECTED] writes: By the way, my recollection is that in C++ access defaults to private if nothing is declared explicity. So normally the private declaration is unnecessary. If it is left out, your little trick won't work. How about #define class struct I never thought of that one. I wonder what the C++ gurus would say about that. Let me guess. They'd probably say that the access restrictions are for your own good, and bypassing them is bound to do you more harm than good in the long run. And they'd probably be right. Just because you can break into a box labeled DANGER HIGH VOLTAGE, that doesn't make it a good idea. This just goes to show that the whole idea of using header files as simple text insertions is flaky to start with, and adding the preprocessor just compounds the flakiness. Needless to say, I'mnota big fan of C and C++. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On Jun 10, 11:58 am, Jonathan Gardner Who cares what the type of an object is? Only the machine. Being able to tell, in advance, what the type of a variable is is a premature optimization. Tools like psyco prove that computers (really, programmers) nowadays are smart enough to figure things out the right way without any hints from the developer. Static typing is no longer necessary in today's world. You couldn't be more wrong. Even Guido recognizes the potential value of static typing, which is why he is easing it into Python as on optional feature. He recognizes, correctly, that it can detect errors earlier and facilitate more efficient execution. But there's another, more significant potential benefit for safety-critical and mission- critical applications: static typing facilitates advanced static analysis of software. To get an idea of what that is about, take a look at http://www.sofcheck.com Here is an excerpt from their website: SofCheck’s advanced static error detection solutions find bugs in programs before programs are run. By mathematically analyzing every line of software, considering every possible input, and every path through the program, SofCheck’s solutions find any and all errors that cause a program to crash or produce an undefined result. Me again: static analysis does not replace traditional dynamic and unit testing, but it is far more advanced and finds many errors very quickly that might require weeks or months of dynamic testing -- or might not be found at all with dynamic testing until the product is in the field. With more and more automation of safety-critical systems these days, we need this more than ever. Your assertion that Static typing is no longer necessary in today's world, is just plain naive. Who cares about private declarations, or interface declarations at all? It is only a message to the developers. If you have a problem with your users doing the right thing, that is a social problem, not a technical one, and the solution is social, not technical. Yes, it is work, but it is not coding---it is explaining to other living, breathing human beings how to do a specific task, which is what you should have been doing from the start. You may be right to an extent for small or medium-sized non-critical projects, but you are certainly not right in general. I read something a while back about the flight software for the Boeing 777. I think it was something like 3,000,000 lines of Ada code. Normally, for a project of that magnitude the final integration would be expected to take something like three months. However, the precise interface specs and encapsulation methods in Ada allowed the integration to be completed in just three days. By your recommended method of social interaction, that would be one hell of a lot of talking! I realize that Python is not designed for such large projects, but don't you think certain general principles can be learned anyway? Perhaps the benefits of interface specs and encapsulation are not as obvious for smaller projects, but certainly they are not zero. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using ElementTree as backend for a chat web application issues
Well folks, I appreciate your help, but I've got the problem solved by re-implementing the chat backend (server) in Rails. It is working great now (persisting the data in a mysql database, instead of XML files). At least this has led me to search more about concurrent issues and programming. I'm still confused on why this doesn't happen with my Rails backend, but I will eventually find out. Living and learning. Thanks for the attention, Marcelo. On Wed, Jun 11, 2008 at 12:47 AM, Gabriel Genellina [EMAIL PROTECTED] wrote: En Mon, 09 Jun 2008 15:32:00 -0300, Marcelo de Moraes Serpa [EMAIL PROTECTED] escribió: I've built a chat with a front-end Ajax client and backend usign ElementTree to persist the data. In some circunstances I could not yet discover (it seems random) when I edit/save the structure, the structure gets corrupted, elementree seems to get lost in its internal cursor, usually something like this happens: backend chat_list chat id=1 chat id=2 /chat_list /backendid=3//backend Pretty strange, and it drives the whole application unusable. I don't know if the concurrent nature of the application (multiple users using the client at almost the same time and sending data to the server which in turn must save the data to the same global.xml file) has something to do with it - I don't know if ElementTree is suitable for this kind of thing. How to hanlde this concurrent issue? I don't think it's a problem with ElementTree. Perhaps you are writing the same (global) configuration file from several threads at the same time? You may need some locking mechanism in that case. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Cannot install python under Win32
Hi Martin, I checked the md5 checksum, it is the following: d806af2312a33a8d817a6cc3d2ee7bed *python-2.5.2.msi which doesn't match with the one on the website ( http://www.python.org/download/releases/2.5.2/ ) d71e45968fdc4e206bb69fbf4cb82b2d python-2.5.2.msi (11294720 bytes, signature) File size doesn't match either ( it is 11.292.672 bytes ) I downloaded it again and I have the same md5. We have one of those Panda GateDefender gateways which look at everything you download and surf. It must be corrupting the file somehow. Anyways, I have found a co-worker who had a copy of Python 2.5, and I have installed it without problems. Thank you very much Pedro -- http://mail.python.org/mailman/listinfo/python-list
Re: Python doesn't understand %userprofile%
[EMAIL PROTECTED] wrote: In xp when I try os.path.getmtime(%userprofile/dir/file%) Python bites back with cannot find the path specified Since my script has to run on machines where the username is unspecified I need a fix. For the record, the %PERCENT% syntax for looking up an environment variable is just a feature of the XP command shell. It has no meaning to any other part of Windows. os.environ is the right answer. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
Le Wednesday 11 June 2008 06:20:14 cirfu, vous avez écrit : pat = re.compile((\w* *)*) this matches all sentences. if fed the string are you crazy? i am it will return are you crazy. i want to find a in a big string a sentence containing Zlatan Ibrahimovic and some other text. ie return the first sentence containing the name Zlatan Ibrahimovic. patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) should do this according to regexcoach but it seems to send my computer into 100%CPU-power and not closable. This kind of regexp are quite often harmfull, while perfectly valid, if you take the time it will return, this check too many things to be practical. Read it, sequentially to make it sensible : for each sequence of word + space, trying with the longest first, does the string 'zlatan' follow ? this is zlatan example.' compare with 'this is zlatan example', 'z'=='.', false compare with 'this is zlatan ', 'z'=='e', false compare with 'this is zlatan', 'z'==' ', false compare with 'this is ', zlatan==zlatan, true compare with 'this is', 'z'==' ', false compare with 'this ', 'z'=='i', false compare with 'this', 'z'==' ', false ... ouch ! The most simple are your regex, better they are, two short regex are better then one big, etc... Don't do premature optimization (especially with regexp). In [161]: s=pat = re.compile((\w* *)*) this matches all sentences. if fed the string are you crazy? i am it will return are you crazy. i want to find a in a big string a sentence containing Zlatan Ibrahimovic and some other text. ie return the first sentence containing the name Zlatan Ibrahimovic. patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) should do this according to regexcoach but it seems to send my computer into 100%CPU-power and not closable. In [172]: list(e[0] for e in re.findall(((\w+\s*)+), s, re.M) if re.findall('zlatan\s+ibrahimovic', e[0], re.I)) Out[172]: ['i want to find a in a big string a sentence containing Zlatan\nIbrahimovic and some other text', 'ie return the first sentence containing the name Zlatan Ibrahimovic', 'zlatan ibrahimovic '] -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Thanks for help re: %userprofile%
[EMAIL PROTECTED] wrote: The python community is very helpful to newbies like me. I did however manage to solve my problem in the meantime. I needed the modification time of certain files on various computers, but I didn't know the usernames ahead of time, so I used windows %userprofile% method. Python likes forward slashes in file names, whereas windows likes back slashes. Your last sentence is not true at all. The Windows APIs accept forward slashes anywhere they accept backward slashes. It is only the command shell insists on back slashes. Here is my script. import os, re u = os.getenv(USERPROFILE) # python returns c:\\documents and Settings\\user # note the escaped backslashes which windows hates. What??? This is not only false, it is completely backwards from what you just said. The string does NOT actually contain any doubled backslashes. You only SEE that because of the way you are displaying them to your terminal. This string: x = \\\n contains exactly two characters: a backslash, and a newline. Try it and see. # let's repair that with re.sub u = re.sub( r\\, /, u) That doesn't do what you think it does. r\\ contains two characters, both backslashes. However, your source string doesn't CONTAIN any doubled backslashes. So, this statement does nothing. Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. x = \\\n len(x) 2 x = \\# contains one character: a backslash len(x) 1 x '\\' x = r\\ # contains two characters: both backslashes len(x) 2 x # but when Python displays it, it escapes them '' f = u+/dir1/file1 mod = os.path.getmtime(f) # success, now do something It would also have succeeded with all backslashes, or with mixed forward and backslashes. You're focussing on the wrong things here. c = copy '%userprofile%\dir1\file1' c:\dir2\file2 # note back slashes here which windows tolerates. That is WRONG, and it only worked by accident. If your directory names had been index or name, you would have found this out. The correct way to write that is either: c = copy '%USERPROFILE%\\dir1\\file1' c:\\dir2\\file2 or c = rcopy '%USERPROFILE%\dir1\file1' c:\dir2\file2 # In the os.system context, python delivers unescaped slashes. os.system(c) # success There is no reason to go to an external program for this at all. Just do this: import shutil shutil.copyfile( sourcefilename, destfilename ) I'm a retired old fart trying to learn python so I welcome criticism and advice. Tell us what you are really trying to do, and we can offer some simple scripts that you can use as an example. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
Le Wednesday 11 June 2008 09:08:53 Maric Michaud, vous avez écrit : this is zlatan example.' compare with 'this is zlatan example', 'z'=='.', false compare with 'this is zlatan ', 'z'=='e', false compare with 'this is zlatan', 'z'==' ', false compare with 'this is ', zlatan==zlatan, true Ah no ! it stops here, but would have continued on the entire string upto the empty string if it doesn't contain zlatan at all. compare with 'this is', 'z'==' ', false compare with 'this ', 'z'=='i', false compare with 'this', 'z'==' ', false -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: h2py.py bug?
Gabriel Genellina wrote: En Tue, 10 Jun 2008 09:44:13 -0300, Gabriel Rossetti [EMAIL PROTECTED] escribió: I wanted to use the h2py.py script (Tools/scripts/h2py.py) and it didn't like char litterals : Skipping: PC_ERROR = ord() where my *.h file contained : #define PC_ERROR '0' I searched the web and found a post with the same error : http://mail.python.org/pipermail/python-list/2005-September/340608.html but it got no replies, I tried the fix and it works. I have the following questions: 1) Why did it not get any attention, is something wrong with it? 2) If nothing is wrong, did the fix not get applied because a bug report wasn't filed? Very probably - bug reports outside the tracker are likely to go unnoticed or forgotten. Ok, I'll file one then. 3) Isn't turning a char literal into the ordinal value not contrary to what a C programmer had in mind when he/she defined it? I mean if you define a char literal then in python you would have used a string value : #define PC_ERROR '0' would become : PC_ERROR = '0' in python, and if you intended to use the char type for an 8 bit numerical value you would have done : #define PC_ERROR 0x30 where 0x30 is the '0' ascii hex value, so shouldn'it the line in the diff (see the post) be : body = p_char.sub('\\1', body) instead of : body = p_char.sub(ord('\\1'), body) It's not so clear what's the intended usage - chars are also integers in C. (I prefer the current behavior, but certainly it may be wrong in several places). Yes, true, but if you intend to use it as an integer, wouldn't you use a numeric value instead of a character literal? -- http://mail.python.org/mailman/listinfo/python-list
Asus F5RL 99D Notebook(Laptop)
This laptop comes with Intel 1.6GHz Dual Core Processor, 1GB RAM and 120GB HDD. It has a DVD Writer, 15.4-inch widescreen display with a resolution of 1280 x 800 dpi. The laptop also has an integrated ATI X300 video card, integrated modem and sound card, Wifi, Touchpad mouse, in-built speakers, 4 USB ports and 4 in 1 Digital Media Reader. The laptop comes with an inbuilt 1.3 megapixel camera powered by Lithium Ion battery. To buy this Asus F5RL 99D Notebook(Laptop) please visit: http://www.naaptol.com/buy-online/WO-best-deals-shopping-W12021O/computers_-_peripherals/laptops/asus_f5rl_99d_notebook.html4g.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On Jun 11, 8:11 am, Russ P. [EMAIL PROTECTED] wrote: On Jun 10, 11:58 am, Jonathan Gardner Who cares what the type of an object is? Only the machine. Being able to tell, in advance, what the type of a variable is is a premature optimization. Tools like psyco prove that computers (really, programmers) nowadays are smart enough to figure things out the right way without any hints from the developer. Static typing is no longer necessary in today's world. You couldn't be more wrong. Even Guido recognizes the potential value of static typing, which is why he is easing it into Python as on optional feature. He recognizes, correctly, that it can detect errors earlier and facilitate more efficient execution. But there's another, more significant potential benefit for safety-critical and mission- critical applications: static typing facilitates advanced static analysis of software. Can you provide me with any example of Guide wanting static typing to be optional? I haven't. Any why is it you keep going so abstract in this discussion. You may be right to an extent for small or medium-sized non-critical projects, but you are certainly not right in general. I read something a while back about the flight software for the Boeing 777. I think it was something like 3,000,000 lines of Ada code. Normally, for a project of that magnitude the final integration would be expected to take something like three months. However, the precise interface specs and encapsulation methods in Ada allowed the integration to be completed in just three days. Well, that isn't just because they used encapsulation, the likelihood is well thoughtout planning, constant system testing (that DOES require accessing of those more private methods to ensure there are no problems throughout), and re-testing. Again since I'm not sure how much I trust you and your statistics anymore, have you a link to anything discussing this? I realize that Python is not designed for such large projects, but don't you think certain general principles can be learned anyway? Perhaps the benefits of interface specs and encapsulation are not as obvious for smaller projects, but certainly they are not zero. Python is designed to be an efficient high level language for writing clear readable code at any level. Considering the amount of use it gets from Google, and the scope and size of many of their projects, I find it foolish to say it is not designed for large projects. However I do not myself have an example of a large python project, because I don't program python at work. I think the issue here is your want to have python perform exactly like OO built languages such as Java, but it isn't Java, and that, is a good thing. -- http://mail.python.org/mailman/listinfo/python-list
http client encoding
Hi everybody, I wrote a small http client I'm using to download and analyze some web pages.I used urllib and the examples on the doc to create the http client, but I have some problems with the encoding of the returned data. Where can I find a good example about how to manage encoding for http responses Lorenzo -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
On Jun 11, 6:20 am, cirfu [EMAIL PROTECTED] wrote: pat = re.compile((\w* *)*) this matches all sentences. if fed the string are you crazy? i am it will return are you crazy. i want to find a in a big string a sentence containing Zlatan Ibrahimovic and some other text. ie return the first sentence containing the name Zlatan Ibrahimovic. patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) should do this according to regexcoach but it seems to send my computer into 100%CPU-power and not closable. Maybe something like this would be of use... def sentence_locator(s, sub): cnt = s.upper().count(sub.upper()) if not cnt: return None tmp = [] idx = -1 while cnt: idx = s.upper().find(sub.upper(), (idx+1)) a = -1 while True: b = s.find('.', (a+1), idx) if b == -1: b = s.find('.', idx) if b == -1: tmp.append(s[a+1:]) break tmp.append(s[a+1:b+1]) break a = b cnt -= 1 return tmp -- http://mail.python.org/mailman/listinfo/python-list
How to view how much memory some process use in Windows?
How can I monitor with a Python script how much memory does a process use in Windows? I want to do statistics about memory consumption of processes like Firefox, Antivirus, etc. When I search in Google I only find information about how to monitor this in linux or how to reduce Python programs memory usage. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
Russ P. a écrit : On Jun 10, 1:04 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: If you hope to get a general agreement here in favor of a useless keyword that don't bring anything to the language, then yes, I'm afraid you're wasting your time. Actually, what I hope to do is to take something away from the language, and that is the need to clutter my identifiers with leading underscores. I find that I spend the vast majority of my programming time working on the private aspects of my code, and I just don't want to look at leading underscores everywhere. So I usually just leave them off and resort to a separate user guide to specify the public interface. I'll bet many Python programmers do the same. How many Python programmers do you think use leading underscores on every private data member or method, or even most of them for that matter? First point : please s/private/implementation/g. As long as you don't get why it's primary to make this conceptual shift, the whole discussion is hopeless. Second point : I've read millions of lines of (production) python code these last years, and I can assure you that everyone used this convention. And respected it. I'll bet not many. (See the original post on this thread.) That means that this particular aspect of Python is basically encouraging sloppy programming practices. Bullshit. Working experience is here to prove that it JustWork(tm). What I don't understand is your visceral hostility to the idea of a priv or private keyword. Because it's at best totally useless. If it offends you, you wouldn't need to use it in your own code. You would be perfectly free to continue using the leading-underscore convention (unless your employer tells you otherwise, of course). My employer doesn't tell me how to write code. I'm not a java-drone. My employer employ me because he is confident in my abilities, not because he needs some monkey to type the code. The point is not *my* code, but the whole free python codebase. I definitively do not want it to start looking anything like Java. Thanks. I get the impression that Python suits your own purposes and you really don't care much about what purpose others might have for it. Strange enough, every time I read something like this, it happens that it comes from someone who is going to ask for some fundamental change in a language used by millions of persons for the 15+ past years just because they think it would be better for their own current project. I am using it to develop a research prototype of a major safety-critical system. I chose Python because it enhances my productivity and has a clean syntax, but my prototype will eventually have to be re-written in another language. I took a risk in choosing Python, and I would feel better about it if Python would move up to the next level with more advanced features such as (optional) static typing and private declarations. I'm sorry, but I don't see any of this as being a move up to the next level. But every time I propose something like that, fundamental change in the language for your own (perceived, and mostly imaginary) needs, that is... I get all kinds of flak from people here who do their hacking and care little about anyone else's needs. No one needs another Java. Now what happens here is that *you* come here explaining everyone that they need to adapt to the way *you* think things should be. With a few relatively small improvements, Python could expand its domain considerably and make major inroads into territory that is now dominated by C++, Java, and other statically compiled languages. But that won't happen if reactionary hackers stand in the way. So anyone not agreeing with you - whatever his experience, reasons etc - is by definition a reactionnary hacker ? Nice to know. Side note: I've been looking at Scala, and I like what I see. It may actually be more appropriate for my needs, but I have so much invested in Python at this point that the switch will not be easy. So instead of taking time to learn the tool that would fit your needs, you ask for fundamental changes in a language that fits millions other persons needs ? Now let's talk about not caring about other's needs... -- http://mail.python.org/mailman/listinfo/python-list
Re: mysql to sqlite
Gandalf [EMAIL PROTECTED] wrote: I'm trying to convert mysql database to sqlite. is their any free tool that does that? I can convert my mysql db to XML file through phpmyadmin, will it be easier to convert from XML to SQlite then from Mysql? I'd probably create the sqlite tables first by editing the database schemas produced by mysqldump to make the acceptable to feed to sqlite. I would then write a script which connects to both databases at once and copies the table data across. (At least that is what I did last time I needed to do that which was from MSSQL-MySQL). You'll find that different databases have subtly different ways of doing things (eg autoincrement fields on mysql) so you'll most likely need a custom script anyway. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
Russ P. a écrit : On Jun 10, 11:58 am, Jonathan Gardner (snip) Who cares about private declarations, or interface declarations at all? It is only a message to the developers. If you have a problem with your users doing the right thing, that is a social problem, not a technical one, and the solution is social, not technical. Yes, it is work, but it is not coding---it is explaining to other living, breathing human beings how to do a specific task, which is what you should have been doing from the start. You may be right to an extent for small or medium-sized non-critical projects, but you are certainly not right in general. I read something a while back about the flight software for the Boeing 777. I think it was something like 3,000,000 lines of Ada code. I can't obviously back my claim, but you could probably have the same feature set implemented in 10 to 20 times less code in Python. Not that I suggest using Python here specifically, but just to remind you that kloc is not a very exact metric - it's relative to the design, the language and the programmer(s). The first project I worked on (professionaly) was about 100 000 locs when I took over it, and one year later it was about 50 000 locs, with way less bugs and way more features. FWIW, the bigger the project, the bigger the chances that you could cut it by half with a good refactoring. Normally, for a project of that magnitude the final integration would be expected to take something like three months. However, the precise interface specs and encapsulation methods in Ada allowed the integration to be completed in just three days. By your recommended method of social interaction, that would be one hell of a lot of talking! Or just writing and reading. I realize that Python is not designed for such large projects, Clueless again. Python is pretty good for large projects. Now the point is that it tends to make them way smaller than some other much more static languages. As an average, you can count on something between 5:1 to 10:1 ratio between Java (typical and well-known reference) and Python for a same feature set. And the larger the project, the greater the ratio. but don't you think certain general principles can be learned anyway? Do you really think you're talking to a bunch of clueless newbies ? You can bet there are quite a lot of talented *and experimented* programmers here. Perhaps the benefits of interface specs and encapsulation are not as obvious for smaller projects, Plain wrong. but certainly they are not zero. You still fail to get the point. Interface specifications and encapsulation are design principles. period. These principles are just as well expressed with documentation and naming conventions, and the cost is way lower. Russ, do yourself a favor : get out of your cargo-cult one minute and ask yourself whether all python users are really such a bunch of clueless newbies and cowboy hackers. You may not have noticed, but there are some *very* talented and *experimented* programmers here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code correctness, and testing strategies
Thanks again for an informative reply :-) I finished that small app I mentioned last time (before reading the the last reply to this thread). A few points (apologies for the length): I added a few integration tests, to test features which unit tests weren't appropriate for. The main thing they do is call my main object's 'run_once()' method (which iterates once) instead of 'run()' (which runs forever, calling run_once() endlessly), and then check that a few expected things took place during the iteration. Those integration tests helped me to find a few issues. There were a few 'integration' tests which were actually acceptance/functional tests because integration tests weren't good enough (eg: run script in unix daemon mode and check for pid/lock/etc files). I left those under integration because it's annoying to change to 3 different directories to run all of the tests. I should probably split those off and automate the testing a bit more. After doing all the automated tests, I did some manual testing (added 'raise UNTESTED' lines, etc), and found a few more things. eg, that one of my (important) functions was being unit tested but not ever being run by the main app. Fixed it with BDD, but it is something I need to be aware of when building bottom-up with BDD :-) Even better: develop top down also, and have acceptance tests from the start, like you mentioned before. Another thing I found, was that after installing on a test system there were more failures (as expected). Missing depedencies which had to be installed. Also Python import errors because the files get installed to and run from different directories than on my workstation. Not sure how I would use BDD to catch those. Finally - I didn't use BDD for the debianization (checking that all the shell scripts control files work correctly, that the debian package had all the files in the correct places etc). I figured it would be too much trouble to mock the Debian package management system, and all of the linux utilities. Should a BDD process also check 'production' (as opposed to 'under development') artifacts? (installation/removal/not being run under a version control checkout directory/missing dependancies/etc)? In the future I'll probably create 'production' acceptance tests (and supporting utilities) following BDD before debianization. Something automated like this: 1) Build the installer package from source 2) Inspect the package and check that files are in the expected places 3) Package should pass various lint tests 4) Install the package under a chroot (reset to clear out old deps, etc) 5) Check that files etc are in the expected locations 6) Run functional tests (installed with the package) under the chroot 7) Test package upgrades/removal/purges/etc under the chroot. There are a few existing Debian utilities that can help with this. On Wed, Jun 11, 2008 at 4:36 AM, Ben Finney [EMAIL PROTECTED] wrote: David [EMAIL PROTECTED] writes: [...] Does this mean that you leave out the formal 'integration' and 'systems' testing steps? By actually running the app you are doing those things more or less. I'm not sure why you think one would leave out those steps. The integration and systems tests should be automated, and part of some test suite that is run automatically on some trigger (such as every commit to the integration branch of the version control system). It sounded that way because when I asked about integration tests originally, you said to use approval testing. Which seems to completely skip the automated 'integration' and 'systems' testing steps I was expecting. A Python distutils 'setup.py' is a very common way to set up the build parameters for an application. I don't make setup.py, because my work projects are always installed via apt-get onto Debian servers. setup.py is a bit redundant and less functional for me :-) Might be a bad practice on my part. Usually you start with a non-Debian-specific install method. Which then gets run to install the files into a directory which gets packaged into a Debian installer. I cheat with Python apps because I'm both the upstream author and the Debian maintainer. I setup my Debian control files so they will copy the .py files directly into the packaged directory, without running any non-Debian-specific install logic. I should probably have a setup.py anyway... :-) But I will be making a Debian installer a bit later. That's an important part of the build process, but you should write (and test via your automated build process) a 'setup.py' before doing that. Should I have a setup.py if it won't ever be used in production? I've considered setting up a centralised build server at work, but currently I'm the only dev which actually builds packages software, so it wouldn't be very useful. It's extremely useful to ensure that the automated application build infrastructure is in place early, so that it is easy to set up and automate. This ensures that it
Re: can't assign to literal
On Jun 11, 10:32 am, MRAB [EMAIL PROTECTED] wrote: On Jun 10, 10:57 pm, Steven Clark [EMAIL PROTECTED] wrote: for 1 in oids, vals head_oids: SyntaxError: can't assign to literal -- 1 is a literal, you can't assign it to something. Are you trying to use it as a variable name? Slightly OT, but is there an editor that can display digits in a different colour to letters? SciTE and Notepad++ which are just 2 of the editors installed on my PC currently. -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On Jun 10, 10:57 pm, Steven Clark [EMAIL PROTECTED] wrote: for 1 in oids, vals head_oids: SyntaxError: can't assign to literal -- 1 is a literal, you can't assign it to something. Are you trying to use it as a variable name? Slightly OT, but is there an editor that can display digits in a different colour to letters? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
Le Wednesday 11 June 2008 08:11:02 Russ P., vous avez écrit : http://www.sofcheck.com Here is an excerpt from their website: SofCheck’s advanced static error detection solutions find bugs in programs before programs are run. By mathematically analyzing every line of software, considering every possible input, and every path through the program, SofCheck’s solutions find any and all errors that cause a program to crash or produce an undefined result. Don't mix commercial discourse with technical, it desserves your point. Theoretically, wether a program has bugs or not is not computable. Static analysis as they imply is just nonsense. AFAIK, the efforts needed to make good static analysis are proven, by experience, to be at least as time consuming than the efforts needed to make good unit and dynamic testing. -- _ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list
Re: How to view how much memory some process use in Windows?
Florencio Cano [EMAIL PROTECTED] wrote: How can I monitor with a Python script how much memory does a process use in Windows? I want to do statistics about memory consumption of processes like Firefox, Antivirus, etc. When I search in Google I only find information about how to monitor this in linux or how to reduce Python programs memory usage. Perhaps http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303339 -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Python regex question
Hi, I'm trying to create a regular expression for matching some particular XML strings. I want to extract the contents of a particular XML tag, only if it follows one tag, but not follows another tag. Complicating this, is that there can be any number of other tags in between. So basically, my regular expression should have 3 parts: - first match - any random text, that should not contain string 'Xds' - second match I have a problem figuring out how to do the second part: a random bit of text, that should _not_ contain the substring 'Xds' ('Xds' being the start of any tags which should not be in between my first and second match). Because of the variable length of the overal match, I cannot do this with a negative look-behind assertion, and a negative look-ahead assertion doesn't seem to work either. The regular expression that I have now is: r'(?s)Xds\w*Policy.*?ref(?Ppol_ref\d+)/ref' (hopefully without typos) Here 'Xds\w*Policy' is my first match, and 'ref(?Ppol_ref\d+)/ref' is my second match. In this expression, I want to change the generic '.*?', which matches everything, with something that matches every string that does not include the substring 'Xds'. I know that I could capture the text matched by '.*?' and manually check if it contains that string 'Xds', but that would be very hard to fit into the rest of the code, for a number of reasons. Does anyone have an idea how to do this within one regular expression? Regards, --Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does python not have a mechanism for data hiding?
On 11 Jun, 10:10, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Russ P. a écrit : You may be right to an extent for small or medium-sized non-critical projects, but you are certainly not right in general. I read something a while back about the flight software for the Boeing 777. I think it was something like 3,000,000 lines of Ada code. I can't obviously back my claim, but you could probably have the same feature set implemented in 10 to 20 times less code in Python. It's easy to make claims like this knowing that people aren't likely to try and write such a system in Python. Not that I suggest using Python here specifically, but just to remind you that kloc is not a very exact metric - it's relative to the design, the language and the programmer(s). The first project I worked on (professionaly) was about 100 000 locs when I took over it, and one year later it was about 50 000 locs, with way less bugs and way more features. FWIW, the bigger the project, the bigger the chances that you could cut it by half with a good refactoring. Perhaps you should get in touch with the advocacy-sig mailing list and provide them with the concrete details, because although you and I (and many others) recognise intuitively that Python code is typically shorter than, say, Java because the boilerplate of the latter is unnecessary, the last big discussion I recall about Python code being shorter than that of statically typed languages didn't really yield much in the way of actual projects to make the case. Normally, for a project of that magnitude the final integration would be expected to take something like three months. However, the precise interface specs and encapsulation methods in Ada allowed the integration to be completed in just three days. By your recommended method of social interaction, that would be one hell of a lot of talking! Or just writing and reading. Maybe, but I'd imagine that the project mentioned is a fairly large one with all the classic observations by Brooks highly applicable. Such things can incur huge costs in a large project. I realize that Python is not designed for such large projects, Clueless again. Python is pretty good for large projects. It might be good for large projects but is it good for large projects *such as the one mentioned*? Now the point is that it tends to make them way smaller than some other much more static languages. As an average, you can count on something between 5:1 to 10:1 ratio between Java (typical and well-known reference) and Python for a same feature set. And the larger the project, the greater the ratio. Again, I don't doubt this intuitively, but many people do doubt it. Citation needed! [...] Do you really think you're talking to a bunch of clueless newbies ? You can bet there are quite a lot of talented *and experimented* programmers here. Maybe, but with the style of discourse you've been using, you're not really speaking for them, are you? Perhaps the benefits of interface specs and encapsulation are not as obvious for smaller projects, Plain wrong. I'm not a big fan of lots of up-front declarations when the code is easy to understand intuitively, but what are you trying to say here? That interface specifications and encapsulation are as essential for a three line script as they are for a large project? but certainly they are not zero. You still fail to get the point. Interface specifications and encapsulation are design principles. period. These principles are just as well expressed with documentation and naming conventions, and the cost is way lower. I guess it depends on how the documentation gets written, because from what I've seen documentation is one of the more neglected areas of endeavour in software development, with many development organisations considering it a luxury which requires only a cursory treatment in order to get the code out of the door. Russ, do yourself a favor : get out of your cargo-cult one minute and ask yourself whether all python users are really such a bunch of clueless newbies and cowboy hackers. You may not have noticed, but there are some *very* talented and *experimented* programmers here. Maybe, but I'd hope that some of those programmers would be at least able to entertain what Russ has been saying rather than setting themselves up in an argumentative position where to concede any limitation in Python might be considered some kind of weakness that one should be unwilling to admit. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to Decimal type
Thanks to all for the various replies. They have all helped me to refine my ideas on the subject. These are my latest thoughts. Firstly, the Decimal type exists, it clearly works well, it is written by people much cleverer than me, so I would need a good reason not to use it. Speed could be a good reason, provided I am sure that any alternative is 100% accurate for my purposes. My approach is based on expressing a decimal number as a combination of an integer and a scale, where scale means the number of digits to the right of the decimal point. Therefore 0.04 is integer 4 with scale 2, 1.1 is integer 11 with scale 1, -123.456 is integer -123456 with scale 3. I am pretty sure that any decimal number can be accurately represented in this form. All arithmetic is carried out using integer arithmetic, so although there may be rounding differences, there will not be the spurious differences thrown up by trying to use floats for decimal arithmetic. I use a class called Number, with two attributes - an integer and a scale. My first attempt required these two to be provided every time an instance was created. Then I realised that this would cause loss of precision if I chain a series of instances together in a calculation. The constructor can now accept any of the following forms - 1. A digit (either integer or float) and a scale. It uses the scale factor to round up the digit to the appropriate integer. 2. Another Number instance. It takes the integer and scale from the other instance. 3. An integer, with no scale. It uses the integer, and assume a scale of zero. 4. A float in string format (e.g. '1.1') with no scale. It uses the number of digits to the right as the scale, and scales the number up to the appropriate integer. For addition, subtraction, multiplication and division, the 'other' number can be any of 2, 3, or 4 above. The result is a new Number instance. The scale of the new instance is based on the following rule - For addition and subtraction, the new scale is the greater of the two scales on the left and right hand sides. For multiplication, the new scale is the sum of the two scales on the left and right hand sides. For division, I could not think of an appropriate rule, so I just hard- coded a scale of 9. I am sure this will give sufficient precision for any calculation I am likely to encounter. My Number class is now a bit more complicated than before, so the performance is not as great, but I am still getting a four-fold improvement over the Decimal type, so I will continue running with my version for now. My main concern is that my approach may be naive, and that I will run into situations that I have not catered for, resulting in errors. If this is the case, I will drop this like a hot potato and stick to the Decimal type. Can anyone point out any pitfalls I might be unaware of? I will be happy to show the code for the new Number class if anyone is interested. Thanks Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill a thread?
On 2008-06-10, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 10, 1:55 am, Antoon Pardon [EMAIL PROTECTED] wrote: On 2008-06-09, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 9, 5:33 am, Antoon Pardon [EMAIL PROTECTED] wrote: On 2008-06-07, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 6, 12:44 pm, The Pythonista [EMAIL PROTECTED] wrote: It's always been my understanding that you can't forcibly kill a thread in Python (at least not in a portable way). The best you can do is politely ask it to die, IIRC. Inherently, the best you can do in most languages is ask them politely to die. Otherwise you'll leave locks and various other datastructures in an inconvenient state, which is too complex to handle correctly. The exception is certain functional languages, which aren't capable of having threads and complex state in the same sense. Well it would of course depend on what is considered asking politely? If one thread could cause an exception being thrown in an other thread, would this be considered a polite way to ask? Would it be considered an acceptable way? The exception must not be raised until a point explicitly designed as safe is hit. Otherwise, any function that manipulates data you'll still use will potentially be buggered. Consider sys.stdout: codecs, buffering, lots to go wrong. I don't see the point. Exceptions are raised now without the ability of an explicitly designed safe point. If something unexpected happens your code can raise an exception and leave your data buggered too if you didn't anticipate it propely. Although in theory you could get any exception at any point, in practise you shouldn't unless your program is broken. If it is broken the exceptions shouldn't be caught and should cause the program to terminate, so the harm is reduced. The exceptions that should happen (such as IOError) should be from predicted points, and anticipated. In pratice you can schedule an alarm and have the alarm handler raise an exception in your code. It is the resposibility of the developer to write his code in such a way that it can handle such an interruption as it should. Given that the above is already possible I don't see why we should protect the programmer from such an asynchronous exception merely because they can be raised from an other thread. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Dumb idea?
On 2008-06-10, Peter Hunt [EMAIL PROTECTED] wrote: Hi everyone - I like playing around with language syntax and semantics. I'm thinking about pulling down the PyPy code and messing around to see what I can accomplish. My first idea is most succinctly described by example: class IBlockProtocol: def __block__(self, func): # NO RETURN VALUES! pass You have lost me here. What is this supposed to be doing? To me you introduce a new magic __block__ function in a class that does nothing. And then you go on and on with implementation details and mappings of some BlockProtocol to other syntax without an explanation of what you are blocking (in English text), or what you aim to achieve by blocking. In other words, your post is to me the same as class A(object): def q(self, t): # do nothing pass and the question did anybody invent q_protocol already? Your guess is as good as mine (and probably better since you have a semantics for the blocking protocol in the back of your mind). Sincerely, Albert -- http://mail.python.org/mailman/listinfo/python-list
Parallel python + ??
Hi, I am running a program using Parallel Python and I wonder if there is a way/module to know in which CPU/core the process is running in. Is that possible? Ángel -- http://mail.python.org/mailman/listinfo/python-list
Re: Python regex question
Tim van der Leeuw wrote: Hi, I'm trying to create a regular expression for matching some particular XML strings. I want to extract the contents of a particular XML tag, only if it follows one tag, but not follows another tag. Complicating this, is that there can be any number of other tags in between. [...] Sounds like this would be easier to implement using Python's SAX API. Here's a short example that does something similar to what you want to achieve: import xml.sax test_str = xml ignore/ foo x=1 y=2/ noignore/ foo x=3 y=4/ /xml class MyHandler(xml.sax.handler.ContentHandler): def __init__(self): xml.sax.handler.ContentHandler.__init__(self) self.ignore_next = False def startElement(self, name, attrs): if name == ignore: self.ignore_next = True return elif name == foo: if not self.ignore_next: # handle the element you're interested in here print MY ELEMENT, name, with, dict(attrs) self.ignore_next = False xml.sax.parseString(test_str, MyHandler()) In this case, this looks much clearer and easier to understand to me than regular expressions. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Python doesn't understand %userprofile%
On Jun 11, 1:58 am, Tim Roberts [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: In xp when I try os.path.getmtime(%userprofile/dir/file%) Python bites back with cannot find the path specified Since my script has to run on machines where the username is unspecified I need a fix. For the record, the %PERCENT% syntax for looking up an environment variable is just a feature of the XP command shell. It has no meaning to any other part of Windows. os.environ is the right answer. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. You can use it at the Run command or in Explorer too. If I type %username% in either place, it opens the following on my XP machine: C: \Documents and Settings\Mike Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Parallel python + ??
Thor wrote: Hi, I am running a program using Parallel Python and I wonder if there is a way/module to know in which CPU/core the process is running in. Is that possible? This is of course OS-specific. On Linux, you can parse the proc filesystem: open(/proc/%i/stat % os.getpid()).read().split()[39] You can use the taskset utility to query or set CPU affinity on Linux. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
On Jun 11, 1:59 am, Rhamphoryncus [EMAIL PROTECTED] wrote: Why not use a normal Queue, put a dummy value (such as None) in when you're producer has finished, and have the main thread use the normal Thread.join() method on all your child threads? I just gave two reasons: - Concurrency / interactivity. The main thread shouldn't wait for all one million items to be produced to get to see even one of them. - Limiting resources. Just like iterating over the lines of a file is more memory efficient than reading the whole file in memory, getting each consumed item as it becomes available is more memory efficient than waiting for all of them to finish. George -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On Jun 11, 3:32 pm, MRAB [EMAIL PROTECTED] wrote: On Jun 10, 10:57 pm, Steven Clark [EMAIL PROTECTED] wrote: for 1 in oids, vals head_oids: SyntaxError: can't assign to literal -- 1 is a literal, you can't assign it to something. Are you trying to use it as a variable name? Slightly OT, but is there an editor that can display digits in a different colour to letters? Most programmer oriented editors could, some even have full syntax coloring, they would color keywords (like def, class, etc), literals (1, 'hello', etc), and commonly used built-in function (int, ord, iter, etc). It really helped if you have to read/write lots of codes -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
On Jun 11, 1:58 am, asdf [EMAIL PROTECTED] wrote: I have a python script whose output i want to dynamically display on a webpage which will be hosted using Apache. How do I do that? thanks def index(req): return Page u cant run it on lighttpd also, which is much faster then Apache :P -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Alexnb wrote: I don't think you understand it doesn't matter how the variable gets there But it *does* matter. Compare this: py filename = C:\Somewhere\01 - Some Song.mp3 py print filename C:\Somewhere - Some Song.mp3 To this: py filename = raw_input(Enter the filename: ) Enter the filename: C:\Somewhere\01 - Some Song.mp3 py print filename C:\Somewhere\01 - Some Song.mp3 Note that the \01 in the first case seems to have disappeared, whereas in the second case it's preserved. Now, if you want us to help you, please post your ACTUAL code with a description of the ACTUAL problem. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
python gui
Greetings, I want to make a dynamic dashboard, something like: http://examples.adobe.com/flex3/labs/dashboard/main.html# but using python. Is it possible ? Thanks in advance. Best regards, Gabriela Soares. -- http://mail.python.org/mailman/listinfo/python-list
Numpy array to gzip file
I have a set of numpy arrays which I would like to save to a gzip file. Here is an example without gzip: b=numpy.ones(100,dtype=numpy.uint8) a=numpy.zeros(100,dtype=numpy.uint8) fd = file('test.dat','wb') a.tofile(fd) b.tofile(fd) fd.close() This works fine. However, this does not: fd = gzip.open('test.dat','wb') a.tofile(fd) Traceback (most recent call last): File stdin, line 1, in module IOError: first argument must be a string or open file In the bigger picture, I want to be able to write multiple numpy arrays with some metadata to a binary file for very fast reading, and these arrays are pretty compressible (strings of small integers), so I can probably benefit in speed and file size by gzipping. Thanks, Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
I understand very well that a service is a software which is accessed through a network. And the description given on Wikipedia [1] is A 'Web service' (also Web Service) is defined by the W3C as a software system designed to support interoperable Machine to Machine interaction over a network. Now, to ending with this. I understand that (almos) everybody is pro Google (and anti Microsoft), thinking that they have given a lot of services for free. And it's very hard that people understand my thinking. All that free service has a great price, that are the rights about those data, and when Google want can to disable the free access to that information. People don't realize that it's one more a company and like so it has only an end, that is to obtain the greater number of benefits which will be distributed between his shareholders. Within any years Google will be as hated as Microsoft. At least I try to use the less possible those services than limit my freedoms about data that has been contributed by me and another users. [1] http://en.wikipedia.org/wiki/Web_service -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to Decimal type
Frank Millman wrote: Thanks to all for the various replies. They have all helped me to refine my ideas on the subject. These are my latest thoughts. Firstly, the Decimal type exists, it clearly works well, it is written by people much cleverer than me, so I would need a good reason not to use it. Speed could be a good reason, provided I am sure that any alternative is 100% accurate for my purposes. [snip] For addition, subtraction, multiplication and division, the 'other' number can be any of 2, 3, or 4 above. The result is a new Number instance. The scale of the new instance is based on the following rule For addition and subtraction . . . For multiplication . . . For division . . . Out of curiosity, what is the purpose of these numbers? Do they represent money, measurements, or something else? The reason I ask is way back in physics class (or maybe chemistry... it was way back :) I was introduced to the idea of significant digits -- that idea being that a measured number is only accurate to a certain degree, and calculations using that number therefore could not be more accurate. Sort of like a built-in error range. I'm thinking of developing the class in the direction of maintaining the significant digits through calculations... mostly as I think it would be fun, and it also seems like a good test case to get me in the habit of unit testing. I'll call it something besides Number, though. :) Is anybody aware of such a class already in existence? -- Ethan -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
On Jun 11, 10:07 am, Alexnb [EMAIL PROTECTED] wrote: I don't think you understand it doesn't matter how the variable gets there, the same code is run regardless, I have no problem with the GUI, but you asked, and so I told you. the code os.startfile( is run if there is a GUI or it is a console app. (snip) I think I know why you get confused by this, clearly, you have no idea of what an escape character and escape sequence is. Python (and C/C++ and some other languages) treats \ (the backspace character) inside a string specially, it makes the character after the backspace lose their special meaning OR get a special meaning, you might probably be used to seeing something like this: 'First line \nSecond Line', which when printed, would give: print 'First Line\nSecond Line' First Line Second Line The second behavior of the escape sequence is to make special character (generally the backspace itself), lose their special meaning: print 'path\\file.txt' path\file.txt In some cases, you might sometimes want a path like this: 'path \nick.txt' if you do this: print 'path\nick.txt' path ick.txt because the \n is considered as a newline. Instead, you should do this: print 'path\\nick.txt' path\nick.txt or print r'path\nick.txt' path\nick.txt the r'' string is raw string, most of the magics of a regular string '' is lost for an r'' string. It allows you to avoid the need to escape the special characters. Raw string is usually used for re (regular expressions) and paths in Windows both of which uses the backslash character regularly. you first case of: system(\C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody \Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\) is interpreted by python as this: C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody \Bryanbros\Weezer\(2001) - Island In The Sun.wma Notice that the '\0' is substituted into '', because \0 is the escape sequence for null character. (Personally I think python should raise errors if any escape character that isn't followed by a valid escape sequence is found (such as \D, \A, \M, \M, \R, \B, \W, \(), but perhaps they're trying not to be too mean for newbies.) that should be correctly written like this: system(r'C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody \Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma') or: system('C:\\Documents and Settings\\Alex\\My Documents\\My Music\ \Rhapsody\\Bryanbros\\Weezer\\(2001)\\04 - Island In The Sun.wma') Now, to the next question: How if I want the path to come from a variable: path = C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody \Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma os.startfile(path) I can see in a glance why it doesn't work, the string is escaped by python, it should be written like this. path = rC:\Documents and Settings\Alex\My Documents\My Music\Rhapsody \Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma os.startfile(path) OR: path = C:\\Documents and Settings\\Alex\\My Documents\\My Music\ \Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\\01 - I'm Yours.wma os.startfile(path) In most GUI toolkits (including Tkinter) and raw_input() function, when you input a string (using the textbox, a.k.a Entry widget) it would automatically be escaped for you, so when you input 'path\path \file.txt', the GUI toolkit would convert it into 'path\\path\ \file.txt'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
George Sakkis wrote: On Jun 10, 11:47 pm, Larry Bates [EMAIL PROTECTED] wrote: I had a little trouble understanding what exact problem it is that you are trying to solve but I'm pretty sure that you can do it with one of two methods: Ok, let me try again with a different example: I want to do what can be easily done with 2.5 Queues using Queue.task_done()/Queue.join() (see example at http://docs.python.org/lib/QueueObjects.html), but instead of having to first put all items and then wait until all are done, get each item as soon as it is done. 1) Write the producer as a generator using yield method that yields a result every time it is called (something like os.walk does). I guess you could yield None if there wasn't anything to consume to prevent blocking. Actually the way items are generated is not part of the problem; it can be abstracted away as an arbitrary iterable input. As with all iterables, there are no more items is communicated simply by a StopIteration. 2) Usw somethink like Twisted insted that uses callbacks instead to handle multiple asynchronous calls to produce. You could have callbacks that don't do anything if there is nothing to consume (sort of null objects I guess). Twisted is interesting and very powerful but requires a different way of thinking about the problem and designing a solution. More to the point, callbacks often provide a less flexible and simple API than an iterator that yields results (consumed items). For example, say that you want to store the results to a dictionary. Using callbacks, you would have to explicitly synchronize each access to the dictionary since they may fire independently. OTOH an iterator by definition yields items sequentially, so the client doesn't have to bother with synchronization. Note that with client I mean the user of an API/ framework/library; the implementation of the library itself may of course use callbacks under the hood (e.g. to put incoming results to a Queue) but expose the API as a simple iterator. George If you use a queue and the producer/collector are running in different threads you don't have to wait for to first put all items and then wait until all are done. Producer can push items on the queue and while the collector asynchronously pops them off. I'm virtually certain that I read on this forum that dictionary access is atomic if that helps. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Parallel python + ??
Gerhard Häring wrote: This is of course OS-specific. On Linux, you can parse the proc filesystem: open(/proc/%i/stat % os.getpid()).read().split()[39] You can use the taskset utility to query or set CPU affinity on Linux. It is going to be in Linux (mainly) I was thinking about something like this: import Module def process(self): print I am running on processor, Module.cpu,core, Module.core Checking the raskset right now...:) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
On Jun 11, 9:16 am, asdf [EMAIL PROTECTED] wrote: On Wed, 11 Jun 2008 11:20:48 +1000, Aidan wrote: asdf wrote: Well, there's a few ways you could approach it. You could create a cgi program from your script - this is probably the solution you're looking for. Output from the script does come up very often. There is a new output every 10 secs and it's possible that the script might be run indefinitely. Basically I want all that output displayed in a web browser Well, in that case you could simply append the new output to a static file every 10 seconds, or whenever there is new output. That way, you just need to refresh the static file in your browser to see updates... Given what I understand of your situation, that's how I'd do it. The problem with this is that browser would have to be refreshed manually every 10 seconds. Unless there is a way to set this in the script itself. Surely you don't think you can do that without Javascript don't you? You can't make the browser refresh automatically in the server side, it has to be done in the client side scripting or like Opera browser that have an option to make it refresh a page every few seconds. A constantly running CGI app is probably not the best idea, given timeouts and other such constraints you might run into. You could have the script run periodically and create a static html file in the webroot... this would be acceptable, maybe preferable, if the output from your script doesn't change frequently. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
On Wed, Jun 11, 2008 at 10:28 AM, Kless [EMAIL PROTECTED] wrote: I understand very well that a service is a software which is accessed through a network. And the description given on Wikipedia [1] is A 'Web service' (also Web Service) is defined by the W3C as a software system designed to support interoperable Machine to Machine interaction over a network. Now, to ending with this. I understand that (almos) everybody is pro Google (and anti Microsoft), thinking that they have given a lot of services for free. And it's very hard that people understand my thinking. All that free service has a great price, that are the rights about those data, and when Google want can to disable the free access to that information. People don't realize that it's one more a company and like so it has only an end, that is to obtain the greater number of benefits which will be distributed between his shareholders. Within any years Google will be as hated as Microsoft. At least I try to use the less possible those services than limit my freedoms about data that has been contributed by me and another users. [1] http://en.wikipedia.org/wiki/Web_service -- http://mail.python.org/mailman/listinfo/python-list It is not a pro-GOOG/anti-MSFT child-thing. Google is a for-profit company. They are in it for the money. There is nothing wrong with it in a capitalist world, if you play by the rules. Also, services like this are scarce resources, it demands storage space, processing power, bandwidth, and etc to provide it, so it makes absolute sense that one would want money to keep providing it. Software per-se isn't scarce resources - you can copy it infinite times (but the work of writing it is, that is why there are programmers payed to write Free Software). Now you seem to be saying that if Google doesn't provide a scarce resource to you for Free (as in Free Beer), they will be hated just as you seem to hate Microsoft. I would hate Google if, after proving so much good stuff as free software, they gonne bankrupt for providing services without restrictions, completely for free. http://en.wikipedia.org/wiki/Scarcity -- Eduardo de Oliveira Padoan http://www.advogato.org/person/eopadoan/ http://twitter.com/edcrypt Bookmarks: http://del.icio.us/edcrypt -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
On Wed, 11 Jun 2008 01:05:45 +, asdf wrote: Well, there's a few ways you could approach it. You could create a cgi program from your script - this is probably the solution you're looking for. Output from the script does come up very often. There is a new output every 10 secs and it's possible that the script might be run indefinitely. Basically I want all that output displayed in a web browser Here's a simplified Django and AJAX solution: 1. Install Django http://www.djangoproject.com/documentation/install/ and choose the place to strore your Django apps 2. Run 'python django-admin.py startproject YOURPROJECTNAME' 3. Create views.py file inside YOURPROJECTNAME directory with something like this: from datetime import datetime from django.http import HttpResponse # import your script here def myscript(request): output = \ html body script type=text/javascript function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject(Msxml2.XMLHTTP); } catch (e) { try { xmlHttp=new ActiveXObject(Microsoft.XMLHTTP); } catch (e) { alert(Your browser does not support AJAX!); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById(hello).innerHTML=xmlHttp.responseText; setTimeout('ajaxFunction();', 1000); } } xmlHttp.open(GET, ../ajax/, true); xmlHttp.send(null); } window.onload = ajaxFunction; /script div id=hello/div /body /html return HttpResponse(output) def ajax(request): output = pHello World from Django and AJAX/p pCurrent time is: %s/p % str(datetime.now())[11:19] return HttpResponse(output, mimetype=text/plain) Note, that refresh time is in 'setTimeout('ajaxFunction();', 1000);' in this example it is 1 second. 3. edit urls.py inside YOURPROJECTNAME directory to something like this: from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^myscript/$', 'YOURPROJECTNAME.views.myscript'), (r'^ajax/$', 'YOURPROJECTNAME.views.ajax'), ) 4. run 'python manage.py runserver' inside YOURPROJECTNAME directory 5. point your browser to 'http://127.0.0.1:8000/myscript/' and you'll see the result. 6. Deploy your app to Apache web server http://www.djangoproject.com/documentation/modpython/ http://www.djangoproject.com/documentation/fastcgi/ Hope this Django/AJAX introduction is helpfull Please note that this code is extremely simplified you probably need to learn more about Django and AJAX/Javascript by yourself Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill a thread?
On Jun 11, 6:56 am, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 10, 3:41 pm, Fuzzyman [EMAIL PROTECTED] wrote: On Jun 10, 2:03 am, Rhamphoryncus [EMAIL PROTECTED] wrote: So how does .NET deal with the sys.stdout corruption? Does it? That has never been an issue for us. Of course. It's far more likely to hit the underlying blocked I/O than the buffer management, unless it's doing a great deal of I/O. Or alternatively, they're using some other mechanism to prevent interruption during buffer management. If you've carefully written your code to use only safe primitives and local state (discarded if interrupted) then yes, it could be interruptible. At this point you could specially mark that block of code as safe, leaving the vast majority of other code unsafe by default. Then again, since you're going to the trouble of carefully designing and auditing your code you could just make it cancellable like blocking I/O should be - just by polling a flag at key points (and you're CPU-bound anyway, so it's not expensive.) The only place I know of that you *need* arbitrary interruption is hitting CTRL-C in the interactive interpreter. At this point it's a debugging tool though, so the risk of weirdness is acceptable. We use background threads for long running calculations that we know are safe to abort. Resources that need protecting we do with finally blocks which the thread abort honours. How does that protect code like this? f = open('somefile', 'w') # interruption here try: ... finally: ... How does it *not* protect you if you write this instead: f = None try: f = open('somefile', 'w') ... finally: if f is not None: ... The calculation is 'coarse grained' (it can call into .NET APIs that can take a relatively long time to return) - so polling for exit wouldn't work anyway. We also run user code and can't expect their code to poll for exit conditions. Do those .NET get interrupted at arbitrary points? Is this untrusted user code also audited for correctness? (Although I'd bet you simply document what you do and blame the user if something breaks.) We don't audit our user code - of course. We do document and assist them as necessary. Changing to a more restrictive model still wouldn't meet our use case and put *more* of a burden on our users. Our situation is not the only one. In general there are situations where you may want to put a long running calulcation on a background thread and you *know* that it is safe to interrupt - but Python currently won't let you. I'm not saying it can't be made to work in your specific case - it likely does work well for you. I'm saying it can't work *in general*. Stretching it out for general use turns those little cracks into massive canyons. A language needs a general mechanism that does work - such as a polite cancellation API. Neither *works in general* - polite cancellation *doesn't* work for our us. That's my point - you probably want *both* for different use cases. :-) Michael Foord http://www.ironpythoninaction.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the python library of Google Data API is truly free?
I understand very well that a service is a software which is accessed through a network. No, you obviously don't understand. A service is something that is offered to you, for free or not, and that you might use on the terms the service provider lays down. Some examples? Pizza delivery service Shoe cleaning service Car wash service Online software store Google search engine/mail/groups/other services All these are services. You are free to use them, on their terms and conditions. Some require you to pay money. Some take your data, enrich/recombine or do whatever with it, and provide you added value - for the cost of you giving away the data for free and agreeing on using it, and for having to look at advertisements when using the service. And the description given on Wikipedia [1] is A 'Web service' (also Web Service) is defined by the W3C as a software system designed to support interoperable Machine to Machine interaction over a network. A webservice is a technical term for software interoperation. It has *nothing* to do with a service in the above sense. It defines an interface, it might come with a example implementation under a FOSS license. Now, to ending with this. I understand that (almos) everybody is pro Google (and anti Microsoft), thinking that they have given a lot of services for free. And it's very hard that people understand my thinking. because it is obviously skewed. Just because the term service is used in two meanings does not mean they are the same... All that free service has a great price, that are the rights about those data, and when Google want can to disable the free access to that information. Yes, they can. That are their conditions. But this has *NOTHING* to do with them offering a piece of software under a FOSS license. People don't realize that it's one more a company and like so it has only an end, that is to obtain the greater number of benefits which will be distributed between his shareholders. Within any years Google will be as hated as Microsoft. Maybe, maybe not. At least I try to use the less possible those services than limit my freedoms about data that has been contributed by me and another users. You are free to do so, and I can't say a single word against it. But you say There is certain deceit because they have used a free license as Apache 2.0 so that people think that it is a free program, but it stops of being it when there are terms/conditions of this style. They use to the community to get information as data about geo- localization. You haven't any right about its *free software* but they get all rights about your content. And they could cancel the service when they want. In addition these terms are more restrictive that the owner software, because you could not duplicate any service. Please read well those terms and conditions before of use that library because *IT IS NOT FREE SOFTWARE*. It is FREE SOFTWARE. You can take the software ,manipulate it, redestribute it under the terms of the GPL and so forth. That has NOTHING to do with the service offered by google HOSTED AT THEIR SITE, PROGRAMMED AT THEIR EXPENSE, OPERATED AT THEIR COSTS to be something they put out for free. They do gather your data to make a richer experience for others, including yourself, and cashing in on advertisements or whatever business-model they like. If you don't like that, fine. But that has *nothing* to do with free software they might offer to access that service. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
Sounds like a sentinel would work for this. The producer puts a specific object (say, None) in the queue and the consumer checks for this object and stops consuming when it sees it. But that seems so obvious I suspect there's something else up. There's a decent implementation of this in the Python Cookbook, Second Edition (9.4: Working with a Thread Pool), available from Safari as a preview: http://my.safaribooksonline.com/0596007973/pythoncook2-CHP-9-SECT-4 Basically, there's a request_work function that adds (command, data) pairs to the input Queue. The command 'stop' is used to terminate each worker thread (there's the sentinel). stop_and_free_thread_pool() just puts N ('stop', None) pairs and join()s each thread. The threadpool put()s the consumed items in an output Queue; they can be retrieved concurrently using get(). You don't call join() until you want to stop producing; you can get() at any time. Geoff Gilmour-Taylor (I ended up using this recipe in my own code, but with a completely different stopping mechanism---I'm using the worker threads to control subprocesses; I want to terminate the subprocesses but keep the worker threads running---and a callback rather than an output queue.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
On Jun 11, 9:57 am, Aidan [EMAIL PROTECTED] wrote: asdf wrote: On Wed, 11 Jun 2008 11:20:48 +1000, Aidan wrote: asdf wrote: Well, there's a few ways you could approach it. You could create a cgi program from your script - this is probably the solution you're looking for. Output from the script does come up very often. There is a new output every 10 secs and it's possible that the script might be run indefinitely. Basically I want all that output displayed in a web browser Well, in that case you could simply append the new output to a static file every 10 seconds, or whenever there is new output. That way, you just need to refresh the static file in your browser to see updates... Given what I understand of your situation, that's how I'd do it. The problem with this is that browser would have to be refreshed manually every 10 seconds. Unless there is a way to set this in the script itself. You should be able to do that with just: meta http-equiv=refresh content=10/ in the head section of your page (you can adjust the value of content from 5 to however many seconds you want between refreshes). That's an alternative way although many older browser doesn't support it, it's probably a better way instead of using Javascript if you don't care about those that are using old browser. You could also look at adding some AJAX-yness to your page, and have it query your script for new output every 10 seconds, and then add that content to the existing page... it sounds like this behavior is what you're looking for, but it's slightly harder to pull off than the method mentioned above. FYI: AJAX is just a very fancy name for Javascript A constantly running CGI app is probably not the best idea, given timeouts and other such constraints you might run into. You could have the script run periodically and create a static html file in the webroot... this would be acceptable, maybe preferable, if the output from your script doesn't change frequently. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
On Tue, 10 Jun 2008 22:46:37 -0700 (PDT), George Sakkis [EMAIL PROTECTED] wrote: On Jun 10, 11:47 pm, Larry Bates [EMAIL PROTECTED] wrote: I had a little trouble understanding what exact problem it is that you are trying to solve but I'm pretty sure that you can do it with one of two methods: Ok, let me try again with a different example: I want to do what can be easily done with 2.5 Queues using Queue.task_done()/Queue.join() (see example at http://docs.python.org/lib/QueueObjects.html), but instead of having to first put all items and then wait until all are done, get each item as soon as it is done. 1) Write the producer as a generator using yield method that yields a result every time it is called (something like os.walk does). I guess you could yield None if there wasn't anything to consume to prevent blocking. Actually the way items are generated is not part of the problem; it can be abstracted away as an arbitrary iterable input. As with all iterables, there are no more items is communicated simply by a StopIteration. 2) Usw somethink like Twisted insted that uses callbacks instead to handle multiple asynchronous calls to produce. You could have callbacks that don't do anything if there is nothing to consume (sort of null objects I guess). Twisted is interesting and very powerful but requires a different way of thinking about the problem and designing a solution. More to the point, callbacks often provide a less flexible and simple API than an iterator that yields results (consumed items). For example, say that you want to store the results to a dictionary. Using callbacks, you would have to explicitly synchronize each access to the dictionary since they may fire independently. This isn't true. Access is synchronized automatically by virtue of the fact that there is no pre-emptive multithreading in operation. This is one of the many advantages of avoiding threads. :) There may be valid arguments against callbacks, but this isn't one of them. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to Decimal type
On Jun 11, 4:39 pm, Ethan Furman [EMAIL PROTECTED] wrote: Frank Millman wrote: Thanks to all for the various replies. They have all helped me to refine my ideas on the subject. These are my latest thoughts. Out of curiosity, what is the purpose of these numbers? Do they represent money, measurements, or something else? I am writing a business/accounting application. The numbers represent mostly, but not exclusively, money. Examples - Multiply a selling price (scale 2) by a product quantity (scale 4) to get an invoice value (scale 2), rounded half-up. Multiply an invoice value (scale 2) by a tax rate (scale 2) to get a tax value (scale 2), rounded down. Divide a currency value (scale 2) by an exchange rate (scale 6) to get a value in a different currency (scale 2). Divide a product quantity (scale 4) by a pack size (scale 2) to get an equivalent quantity in a different pack size. In my experience, the most important thing is to be consistent when rounding. If you leave the rounding until the presentation stage, you can end up with an invoice value plus a tax amount differing from the invoice total by +/- 0.01. Therefore I always round a result to the required scale before 'freezing' it, whether in a database or just in an object instance. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Lie wrote: In most GUI toolkits (including Tkinter) and raw_input() function, when you input a string (using the textbox, a.k.a Entry widget) it would automatically be escaped for you, so when you input 'path\path \file.txt', the GUI toolkit would convert it into 'path\\path\ \file.txt'. That's incorrect. If you enter text into a text box or in raw_input(), *no* conversion of backslashes is happening. A backslash entered in raw_input is just a backslash. A backslash entered in a textbox is just a backslash. A backslash read from a file is just a backslash. A conversion happens when you print the repr() of a string that was obtained from raw_input or from a text box, because repr() tries to show the string literal that would result in the contents, and in a string literal, a backslash is not (always) a backslash, so repr() escapes the backslashes: py text = raw_input(Enter some text: ) Enter some text: This is a backslash: \ py print text This is a backslash: \ py print repr(text) 'This is a backslash: \\' As you can see, I entered a single backslash, and the string ends up containing a single backslash. Only when I ask Python for the repr() of the string does the backslash get doubled up. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
My fight with classes :)
Hi, I'm very new with classes. I still reading something around ;) I got started to try a concatenation of 2 type of string, which have a particular property to start with A or D. My class here: Small class to join some strings according to the leading first letter def __init__(self): self.valueA= '' self.valueD= '' def __add__(self, value): if not isinstance(value, str): return if value.lower().startswith('a'): self.valueA += value if value.lower().startswith('d'): self.valueD += value return self.valueA ,self.valueD __call__= __add__ __iadd__= __add__ my test on the shell: from utilities import StrJoin as zx k= zx() k utilities.StrJoin instance at 0x9dc7ccc k +'aks' ('aks', '') k +'daks' ('aks', 'daks') k +'hdaks' ('aks', 'daks') k +'dhks' ('aks', 'daksdhks') j('boi') Traceback (most recent call last): File stdin, line 1, in module NameError: name 'j' is not defined k('boi') ('aks', 'daksdhks') k('aboi') ('aksaboi', 'daksdhks') k('duboi') ('aksaboi', 'daksdhksduboi') k += 'liu' k += 'aliu' Traceback (most recent call last): File stdin, line 1, in module TypeError: can only concatenate tuple (not str) to tuple k ('aksaboi', 'daksdhksduboi') Do I miss something? I'd rather like to avoid class, but a function won't allow me to store so easily data between several call. Mostly I'd expect to pass to the built instance in a more elaborated function. Then I mean call will be the primer goal. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
ANN: Pyrex 0.9.8.4
Pyrex 0.9.8.4 is now available: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ This version fixes a bug introduced by the last change to unsigned integer indexing. What is Pyrex? -- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On Jun 11, 2:53 am, maehhheeyy [EMAIL PROTECTED] wrote: this is stopping my program from running properly. is there something wrong in my code when that happens? That simply means you did something like this: 'hello' = 'another' 123 = 'kilo' [12, 'asd] = 123 Sometimes it's not that obvious (although they're obvious for a more experienced programmers): for 123 in xrange(10): pass I think you've realized what you've done. And there is a pretty obvious signal that hints that you didn't know the basic syntax of python (or at least the basic syntax of the for-loop). -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 16:47, mercoledì 11 giugno 2008 Chris wrote: SciTE and Notepad++ Pype, spe, just to point it out. Jedit, but rather a bloatware. I'd like to know which is the litest multi platform and indipendent. Pype is very good when compiled in exe, but not doing in Linux in that way. -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Object Manipulation and Frames
Hello people, I would like to get some advice on the method that i should use to develop a cyber billing wxpython app.I had started but i hit a snag when i realised i could not launch or fiddle with properties of a Frame object within another frame object, what i had intended to do was to first launch a login frame where members would login and after successful authentication , the frame would be hidden and another would be launched for billing...i had a LoginFrame and a BillingFrame but after successful auth i found it hard to switch the BillingFrame.Show(True), can this be done ...and would making use of MDI make it beter? ...and if not could anyone please suggest a better/ workable alternative..Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
On Jun 11, 7:59 am, Lie [EMAIL PROTECTED] wrote: You can't make the browser refresh automatically in the server side, Yes you can. I don't know how to do it in Python, but here's an example in Flaming Thunder of a small, fast, light compiled server side CGI that delivers dynamic content every 10 seconds. # Write out the HTTP headers, followed by a blank line. # Make sure to write CRLF and not just LF, as per HTTP # specs. Also, turn off caching using the no-cache and # expires options, so that caching doesn't conflict with # refreshes. Set CRLF to CarriageReturn+LineFeed. Write Refresh: 10; url=http://www.flamingthunder.com/cgi/ refresh.cgi,CRLF. Write Content-type: text/html,CRLF. Write Pragma: no-cache,CRLF. Write Expires: 0,CRLF. Write Cache-Control: no-cache,CRLF. Write CRLF. # Write out the dynamic information. In this # case, we'll just write out Greenwich mean time. Write GetGreenwichMeanTime. For this example, the dynamic content is just Greenwich mean time. You can see it in action at: http://www.flamingthunder.com/cgi/refresh.cgi To create the CGI script, I used Flaming Thunder's cross compiling ability to compile the script under Windows, targeting Linux: ft file refresh.ft output refresh.cgi target linux32 I then ftp'd refresh.cgi up to the cgi directory on my server, set the permissions to 700 to make it executable, and it works (without needing to install any bulky, plodding interpreter). On Jun 11, 7:59 am, Lie [EMAIL PROTECTED] wrote: On Jun 11, 9:16 am, asdf [EMAIL PROTECTED] wrote: On Wed, 11 Jun 2008 11:20:48 +1000, Aidan wrote: asdf wrote: Well, there's a few ways you could approach it. You could create a cgi program from your script - this is probably the solution you're looking for. Output from the script does come up very often. There is a new output every 10 secs and it's possible that the script might be run indefinitely. Basically I want all that output displayed in a web browser Well, in that case you could simply append the new output to a static file every 10 seconds, or whenever there is new output. That way, you just need to refresh the static file in your browser to see updates... Given what I understand of your situation, that's how I'd do it. The problem with this is that browser would have to be refreshed manually every 10 seconds. Unless there is a way to set this in the script itself. Surely you don't think you can do that without Javascript don't you? You can't make the browser refresh automatically in the server side, it has to be done in the client side scripting or like Opera browser that have an option to make it refresh a page every few seconds. A constantly running CGI app is probably not the best idea, given timeouts and other such constraints you might run into. You could have the script run periodically and create a static html file in the webroot... this would be acceptable, maybe preferable, if the output from your script doesn't change frequently.- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
On Jun 11, 9:14 pm, Carsten Haese [EMAIL PROTECTED] wrote: Lie wrote: In most GUI toolkits (including Tkinter) and raw_input() function, when you input a string (using the textbox, a.k.a Entry widget) it would automatically be escaped for you, so when you input 'path\path \file.txt', the GUI toolkit would convert it into 'path\\path\ \file.txt'. That's incorrect. If you enter text into a text box or in raw_input(), *no* conversion of backslashes is happening. A backslash entered in raw_input is just a backslash. A backslash entered in a textbox is just a backslash. A backslash read from a file is just a backslash. I know, but I thought it'd be easier for him to understand it like that and discover the real 'how-it-works' later. My guilt is that I forget to put a this is not how it actually works behind the scene, but you can think of it like this at least for now since this model is easier to grasp (although misleading). A conversion happens when you print the repr() of a string that was obtained from raw_input or from a text box, because repr() tries to show the string literal that would result in the contents, and in a string literal, a backslash is not (always) a backslash, so repr() escapes the backslashes: py text = raw_input(Enter some text: ) Enter some text: This is a backslash: \ py print text This is a backslash: \ py print repr(text) 'This is a backslash: \\' As you can see, I entered a single backslash, and the string ends up containing a single backslash. Only when I ask Python for the repr() of the string does the backslash get doubled up. -- Carsten Haesehttp://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic HTML from Python Script
Lie [EMAIL PROTECTED] at Mittwoch 11 Juni 2008 16:04: FYI: AJAX is just a very fancy name for Javascript AJAX is not just a name, it's a _religion_ SCNR -- Freedom is always the freedom of dissenters. (Rosa Luxemburg) -- http://mail.python.org/mailman/listinfo/python-list
Re: Object Manipulation and Frames
On Jun 11, 9:36 am, uo [EMAIL PROTECTED] wrote: Hello people, I would like to get some advice on the method that i should use to develop a cyber billing wxpython app.I had started but i hit a snag when i realised i could not launch or fiddle with properties of a Frame object within another frame object, what i had intended to do was to first launch a login frame where members would login and after successful authentication , the frame would be hidden and another would be launched for billing...i had a LoginFrame and a BillingFrame but after successful auth i found it hard to switch the BillingFrame.Show(True), can this be done ...and would making use of MDI make it beter? ...and if not could anyone please suggest a better/ workable alternative..Thank you. I do this sort of thing with a timesheet application I wrote. Here's what I do: code class Main(wx.App): ''' Create the main screen. ''' def __init__(self, redirect=False, filename=None): wx.App.__init__(self, redirect, filename) self.OnLogin() def OnLogin(self): dialog = loginDlg.LoginDlg() dialog.ShowModal() self.username = dialog.userTxt.GetValue() self.password = dialog.passwordTxt.GetValue() loggedIn = dialog.loggedIn if loggedIn != True: sys.exit(0) dialog.Destroy() /code As you can see, I call a wx.Dialog right after initializing my wx.App. The dialog is modal, which keeps my wx.App from continuing to load. In my dialog class, I have some authentication code that loops. The loop allows the user to retry logging in. If the user hits Cancel, then I exit the application using the sys.exit(0) command. Hopefully this code snippet gives you the general idea. Either way, I highly recommend subscribing to the wxPython user's group. You'll learn a lot and there are a lot of helpful (and knowledgeable) people on there, including a couple of core developers. You will find the means to join here: http://wxpython.org/maillist.php --- Mike Driscoll Blog: http://blog.pythonlibrary.org Python Extension Building Network: http://www.pythonlibrary.org -- http://mail.python.org/mailman/listinfo/python-list
convert sqlite ANSI to UTF-8
I used sqliteadmin to manage my sqlite database and I copy past queries translated from mysql phpmyadmin output it worked (little slowly but worked...), the only problem now is that sqliteadmin stored my hebrew char as ANSI instead of UTF-8 and now I don't know how to search data from this table. How can I convert my database string from ANSI to UTF-8 Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
On 12:20, mercoledì 11 giugno 2008 cirfu wrote: patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) I think that I shouldn't put anything around the phrase you want to find. patzln = re.compile(r'.*(zlatan ibrahimovic){1,1}.*') this should do it for you. Unless searching into a special position. In the other hand, I'd like to understand how I can substitute a variable inside a pattern. if I do: import os, re EOL= os.linesep re_EOL= re.compile(r'[?PEOL\s+2\t]')) for line in open('myfile','r').readlines(): print re_EOL.sub('',line) Will it remove tabs, spaces and end-of-line ? It's doing but no EOL :( -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Python-URL! - weekly Python news and links (Jun 11)
QOTW: You could use exec. Probably if you find yourself doing this a lot, you're better off using a dictionary. - Erik Max Francis Python books for programmers: http://groups.google.com/group/comp.lang.python/browse_thread/thread/83d2bc376f6a5c69/ Determining in which class a method was actually defined: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b79b4564f6ec7e8e/ ClassName.attribute vs self.__class__.attribute: http://groups.google.com/group/comp.lang.python/browse_thread/thread/bf6b05758c82e8a2/ How to make 5*something work as well as something*5: http://groups.google.com/group/comp.lang.python/browse_thread/thread/f0f81b4167f1c2f5/ How to kill a running thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/82636f1bdd1d2d83/ time.clock() vs time.time(), and a Windows bug: http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3cfc5c82365203c/ The difference between os.path.walk and os.walk explained: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a68a90bd6d3fc760/ An rather old thread but still very active - Why doesn't Python have a data-hiding mechanism? http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/ Configuring distutils to compile C extensions using VC2005: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b58082980fbda814/ Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish the efforts of Python enthusiats: http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the Planet sites: http://planetpython.org http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djqas_ugroup=comp.lang.python.announce Python411 indexes podcasts ... to help people learn Python ... Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see
Re: can't assign to literal
MRAB wrote: On Jun 10, 10:57 pm, Steven Clark [EMAIL PROTECTED] wrote: for 1 in oids, vals head_oids: SyntaxError: can't assign to literal -- 1 is a literal, you can't assign it to something. Are you trying to use it as a variable name? Slightly OT, but is there an editor that can display digits in a different colour to letters? -- http://mail.python.org/mailman/listinfo/python-list I like Vim (Vi Improved) -- multi-platform, multi-lingual (both spoken and programmatic), and you can change the existing syntax/color/indent files or make your own. http://www.vim.org/ -- Ethan -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] python gui
How ? Any references ? On Wed, Jun 11, 2008 at 4:18 PM, W W [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 8:03 AM, Gabriela Soares [EMAIL PROTECTED] wrote: Greetings, I want to make a dynamic dashboard, something like: http://examples.adobe.com/flex3/labs/dashboard/main.html# but using python. Is it possible ? Yes. -Wayne -- Gabriela Soares I learned that courage was not the absence of fear, but the triumph over it. The brave man is not he who does not feel afraid, but he who conquers that fear. Nelson Mandela -- http://mail.python.org/mailman/listinfo/python-list
Re: catastrophic regexp, help!
On Tue, 10 Jun 2008 21:20:14 -0700 (PDT), cirfu [EMAIL PROTECTED] wrote: pat = re.compile((\w* *)*) this matches all sentences. if fed the string are you crazy? i am it will return are you crazy. i want to find a in a big string a sentence containing Zlatan Ibrahimovic and some other text. ie return the first sentence containing the name Zlatan Ibrahimovic. patzln = re.compile((\w* *)* zlatan ibrahimovic (\w* *)*) should do this according to regexcoach but it seems to send my computer into 100%CPU-power and not closable. Some regular expressions are exponentially expensive to evaluate. This web page http://www.cs.rice.edu/~scrosby/hash/ drew my attention to the (contrived) example (x+x+)+y, whose behavior (under Python 2.4.3) is this: seconds to scan ... --- # x's xxx...xyxxx...x - --- 10 0.00.0 11 0.00.0 12 0.00.0 13 0.00.01 14 0.00.0 15 0.00.01 16 0.00.03 17 0.00.04 18 0.00.09 19 0.00.16 20 0.00.33 21 0.00.65 22 0.01.3 23 0.02.58 24 0.05.18 25 0.010.27 26 0.020.41 I'm no regular-expression guru, but your (\w* *)*... example does bear a remarkable resemblance to (x+x+)+y. -- To email me, substitute nowhere-spamcop, invalid-net. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] python gui
On Wed, Jun 11, 2008 at 10:18 AM, Gabriela Soares [EMAIL PROTECTED] wrote: How ? That's an extremely broad question, and shows little initiative, and offers little information. Most of us are happy to help you solve problems for free, but few, if any, are willing to write your programs for free. Any references ? www.google.com Norman linked to a fairly interesting project. Hope this helps, Wayne On Wed, Jun 11, 2008 at 4:18 PM, W W [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 8:03 AM, Gabriela Soares [EMAIL PROTECTED] wrote: Greetings, I want to make a dynamic dashboard, something like: http://examples.adobe.com/flex3/labs/dashboard/main.html# but using python. Is it possible ? Yes. -Wayne -- Gabriela Soares I learned that courage was not the absence of fear, but the triumph over it. The brave man is not he who does not feel afraid, but he who conquers that fear. Nelson Mandela -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
On 00:15, giovedì 12 giugno 2008 Ethan Furman wrote: I like Vim (Vi Improved) What about justifying text ? -- Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: convert sqlite ANSI to UTF-8
On Jun 11, 10:04 am, Gandalf [EMAIL PROTECTED] wrote: I used sqliteadmin to manage my sqlite database and I copy past queries translated from mysql phpmyadmin output it worked (little slowly but worked...), the only problem now is that sqliteadmin stored my hebrew char as ANSI instead of UTF-8 and now I don't know how to search data from this table. How can I convert my database string from ANSI to UTF-8 Thanks! You'll want to look at how to do encoding. Google is amazing! See what it provided me: http://docs.python.org/tut/node5.html#SECTION00513 http://www.diveintopython.org/xml_processing/unicode.html http://evanjones.ca/python-utf8.html http://www.reportlab.com/i18n/python_unicode_tutorial.html Mike -- http://mail.python.org/mailman/listinfo/python-list
How to find duplicate 3d points?
I have a large data file of upto 1 million x,y,z coordinates of points. I want to identify which points are within 0.01 mm from each other. I can compare the distance from each point to every other point , but this takes 1 million * 1 million operations, or forever! Any quick way to do it, perhaps by inserting just the integer portion of the coordinates into an array, and checking if the integer has already been defined before inserting a new point? -- http://mail.python.org/mailman/listinfo/python-list
Re: My fight with classes :)
On Wed, 11 Jun 2008 22:16:56 +0800, TheSaint [EMAIL PROTECTED] wrote: Hi, I'm very new with classes. I still reading something around ;) I got started to try a concatenation of 2 type of string, which have a particular property to start with A or D. My class here: Small class to join some strings according to the leading first letter def __init__(self): self.valueA= '' self.valueD= '' def __add__(self, value): if not isinstance(value, str): return if value.lower().startswith('a'): self.valueA += value if value.lower().startswith('d'): self.valueD += value return self.valueA ,self.valueD __call__= __add__ __iadd__= __add__ my test on the shell: [snip] k +'aks' ('aks', '') k +'daks' ('aks', 'daks') [snip] k += 'liu' k += 'aliu' Traceback (most recent call last): File stdin, line 1, in module TypeError: can only concatenate tuple (not str) to tuple You have designed your class in a confusing way, and then you were confused by it. It was confusing to design your class in such a way that k+'aks' modifies k, because k+'aks' appears to be just an expression. Changing k as a side-effect of evaluating that expression is unnecessarily confusing. See if you can figure out how to design your class so that you modify k either by writing k.append( 'aks' ) or k += 'aks'. Speaking of which, you discovered that k += 'liu'; k += 'aliu' fails. It fails because k += 'liu' replaces k with a tuple (because you return a tuple from your __add__ function), so k is no longer an instance of your class. Do I miss something? I'd rather like to avoid class, but a function won't allow me to store so easily data between several call. Classes are wonderfully useful, and it would be sad for you to use Python while shunning classes. I strongly recommend looking at some good examples of simple class programming; I apologize for having no specific recommendations. -- To email me, substitute nowhere-spamcop, invalid-net. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] python gui
Hello, With all respect, I posed the question as a noob who has NO ideia how to solve the problem at hand. All I asked for were some references, such as known applications that use such technology to guide me to where I should focus. It never crossed my mind to ask for code. If I wanted to do so, I wouldn't use a mailing list and would go to search engines such as google code or krugle. I am sorry you got the wrong impression. If I didn't explain myself the most correct way, then I present my apologies. The link I gave was in flex, so redirecting me to a page about flex is useless. I was asking about how can I get a similar effect but using just python. There fits the python mailing list and the **possible** broad question. If you can't help me I surelly understand. But please do not take me for a fool kind sir/madam. Thank you, Gabriela Soares. On Wed, Jun 11, 2008 at 4:25 PM, W W [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 10:18 AM, Gabriela Soares [EMAIL PROTECTED] wrote: How ? That's an extremely broad question, and shows little initiative, and offers little information. Most of us are happy to help you solve problems for free, but few, if any, are willing to write your programs for free. Any references ? www.google.com Norman linked to a fairly interesting project. Hope this helps, Wayne On Wed, Jun 11, 2008 at 4:18 PM, W W [EMAIL PROTECTED] wrote: On Wed, Jun 11, 2008 at 8:03 AM, Gabriela Soares [EMAIL PROTECTED] wrote: Greetings, I want to make a dynamic dashboard, something like: http://examples.adobe.com/flex3/labs/dashboard/main.html# but using python. Is it possible ? Yes. -Wayne -- Gabriela Soares I learned that courage was not the absence of fear, but the triumph over it. The brave man is not he who does not feel afraid, but he who conquers that fear. Nelson Mandela -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi -- Gabriela Soares I learned that courage was not the absence of fear, but the triumph over it. The brave man is not he who does not feel afraid, but he who conquers that fear. Nelson Mandela -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find duplicate 3d points?
On Jun 11, 11:35 am, [EMAIL PROTECTED] wrote: I have a large data file of upto 1 million x,y,z coordinates of points. I want to identify which points are within 0.01 mm from each other. I can compare the distance from each point to every other point , but this takes 1 million * 1 million operations, or forever! Any quick way to do it, perhaps by inserting just the integer portion of the coordinates into an array, and checking if the integer has already been defined before inserting a new point? what many people do when doing collision detection in 3d games in instead of having one massive list of the vertices will break the field into bounding boxes. in the 2d situation that would look like this. ||||| |. . || .|| ||||| |. |. | . |. | ||||| || . | . || ||||| |||| . .| ||||| That so instead of comparing all points against all other points instead sort them into bounding cubes. that should make doing the comparisons more reasonable. now the only sticky bit will be comparing two vertices that are in two different boxes but so close to the edges that they are under .01mm from each other. in this situation if a point is less that .01mm from any edge of its bounding cube you must compare it against the points in the adjacent cubes. hope this helps a bit. cheers Tim Henderson -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find duplicate 3d points?
[EMAIL PROTECTED] wrote: I have a large data file of upto 1 million x,y,z coordinates of points. I want to identify which points are within 0.01 mm from each other. I can compare the distance from each point to every other point , but this takes 1 million * 1 million operations, or forever! Any quick way to do it, perhaps by inserting just the integer portion of the coordinates into an array, and checking if the integer has already been defined before inserting a new point? -- http://mail.python.org/mailman/listinfo/python-list There is a whole field of Math/CS research on problems like this called Computational Geometry. It provides many algorithms for many geometric problems, including things like this. In particular, to categorize a list of points and find the NearestNeighbor, I'd suggest a KD-tree. I believe this would turn your problem from O(N^2) to O(N log n) or so. Happy google-ing and good luck. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: Advice for a python newbie on parsing whois records?
On Jun 10, 8:21 pm, Miki [EMAIL PROTECTED] wrote: Hello, Hi. I'm stretching my boundaries in programming with a little python shell-script which is going to loop through a list of domain names, grab the whois record, parse it, and put the results into a csv. I've got the results coming back fine, but since I have *no* experience with python I'm wondering what would be the preferred pythonic way of parsing the whois string into a csv record. Tips/thoughts/examples more than welcome! from os import popen import re find_record = re.compile(\s+([^:]+): (.*)\s*).match for line in popen(whois google.com): match = find_record(line) if not match: continue print %s -- %s % (match.groups()[0], match.groups()[1]) HTH, -- Miki [EMAIL PROTECTED]http://pythonwise.blogspot.com OK, here's what I've got so far. I'm treating this as a learning exercise, so the resulting file isn't so important as understanding and thinking in python (although I believe the results are adequate for my needs). I'd appreciate the community's comments as this is my *first* attempt at python and has taken me a couple of hours (including googling). #!/usr/bin/env python import subprocess import re src = open('./domains.txt') dest = open('./whois.csv', 'w'); def trim( txt ): x = [] for line in txt.split(\n): if line.strip() == : continue if line.strip().startswith('WHOIS'): continue if line.strip().startswith(''): continue if line.strip().startswith('%'): continue if line.startswith(--): return ''.join(x) x.append( +line) return \n.join(x) def clean( txt ): x = [] isok = re.compile(^\s?([^:]+): ).match for line in txt.split(\n): match = isok(line) if not match: continue x.append(line) return \n.join(x); def clean_co_uk( rec ): rec = rec.replace('Company number:', 'Company number -') rec = rec.replace(\n\n, \n) rec = rec.replace(\n, ) rec = rec.replace(: , :\n) rec = re.sub(([^(][a-zA-Z']+\s?[a-zA-Z]*:\n), \n\g0, rec) rec = rec.replace(:\n, : ) rec = re.sub(^[ ]+\n, , rec) return rec def clean_net( rec ): rec = rec.replace(\n\n, \n) rec = rec.replace(\n, ) rec = rec.replace(: , :\n) rec = re.sub(([a-zA-Z']+\s?[a-zA-Z]*:\n), \n\g0, rec) rec = rec.replace(:\n, : ) return rec def clean_info( rec ): x = [] for line in rec.split(\n): x.append(re.sub(^([^:]+):, \g0 , line)) return \n.join(x) def record(domain, record): ## Records are as follows: [ domain, registrant, registrant's address registrar, type, registered, renewal, updated name servers ] details = ['','','','','','','','',''] for k, v in record.items(): try: details[0] = domain.lower() result = { registrant: lambda: 1, registrant name: lambda: 1, registrant type: lambda: 4, registrant's address: lambda: 2, registrant address1: lambda: 2, registrar: lambda: 3, sponsoring registrar: lambda: 3, registered on: lambda: 5, registered: lambda: 5, domain registeration date: lambda: 5, renewal date: lambda: 6, last updated: lambda: 7, domain last updated date: lambda: 7, name servers: lambda: 8, name server: lambda: 8, nameservers: lambda: 8, updated date: lambda: 7, creation date: lambda: 5, expiration date: lambda: 6, domain expiration date: lambda: 6, administrative contact: lambda: 2 }[k.lower()]() if v != '': details[result] = v except: continue dest.write('|'.join(details)+\n) ## Loop through domains for domain in src: domain = domain.strip() if domain == '': continue rec = subprocess.Popen([whois,domain], stdout=subprocess.PIPE).communicate()[0] if rec.startswith(No whois server) == True: continue
Re: Alternative to Decimal type
Frank Millman [EMAIL PROTECTED] wrote: Thanks to all for the various replies. They have all helped me to refine my ideas on the subject. These are my latest thoughts. Firstly, the Decimal type exists, it clearly works well, it is written by people much cleverer than me, so I would need a good reason not to use it. Speed could be a good reason, provided I am sure that any alternative is 100% accurate for my purposes. My approach is based on expressing a decimal number as a combination of an integer and a scale, where scale means the number of digits to the right of the decimal point. Therefore 0.04 is integer 4 with scale 2, 1.1 is integer 11 with scale 1, -123.456 is integer -123456 with scale 3. I am pretty sure that any decimal number can be accurately represented in this form. All arithmetic is carried out using integer arithmetic, so although there may be rounding differences, there will not be the spurious differences thrown up by trying to use floats for decimal arithmetic. I used an identical scheme in a product some time ago (written in C not python). It was useful because it modelled the problem domain exactly. You might want to investigate the rational class in gmpy which might satisfy your requirement for exact arithmetic :- import gmpy gmpy.mpq(123,1000) mpq(123,1000) a = gmpy.mpq(123,1000) b = gmpy.mpq(12,100) a+b mpq(243,1000) a*b mpq(369,25000) a/b mpq(41,40) It is also *very* fast being written in C. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill a thread?
On Jun 7, 6:30 am, Nick Craig-Wood [EMAIL PROTECTED] wrote: Here is an attempt at a killable thread http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960 and http://sebulba.wikispaces.com/recipe+thread2 I use this recipe in paste.httpserver to kill wedged threads, and it works okay. It seems to kill threads that are genuinely wedged, e.g., if you try to read past the end of a socket. It takes surprisingly long, up to a minute to actually send the exception to a thread. But it's just a normal exception and seems to act reasonably. Obviously this is not a great system, but it's better than having a background process hang because of problem code elsewhere in the system. It also isn't any worse than kill -9, which is ultimately what a multiprocess system has to do to misbehaving worker processes. Still, to try to mitigate problems with this I set up a supervisor process and if there is a lot of problems with worker threads I'll have the entire process self-destruct so it can be restarted by the supervisor. The code is rather... organic in its development. But you can see it in the ThreadPool here: http://svn.pythonpaste.org/Paste/trunk/paste/httpserver.py Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: can't assign to literal
TheSaint wrote: On 00:15, giovedì 12 giugno 2008 Ethan Furman wrote: I like Vim (Vi Improved) What about justifying text ? Do you mean indenting, or wrapping? Vim has excellent indenting support, and Python files already included that support proper indenting, syntax coloring, etc. I don't use the line-wrapping feature myself, so I have no experience with it. -- Ethan -- http://mail.python.org/mailman/listinfo/python-list
Reading info from an active file
I have a program that writes a log file as it is running to give status of the job. I would like to read that file, pull certain lines of text from it, and write to a new file. Because I am such a novice user, I was hoping someone had covered this before and could let me know of your methods. If I open and close the file repeatedly to get refreshed information, I assume it would slow the system down. Any thoughts? Keith Nation -- http://mail.python.org/mailman/listinfo/python-list
Re: Numpy array to gzip file
On Jun 11, 9:17 am, Sean Davis [EMAIL PROTECTED] wrote: I have a set of numpy arrays which I would like to save to a gzip file. Here is an example without gzip: b=numpy.ones(100,dtype=numpy.uint8) a=numpy.zeros(100,dtype=numpy.uint8) fd = file('test.dat','wb') a.tofile(fd) b.tofile(fd) fd.close() This works fine. However, this does not: fd = gzip.open('test.dat','wb') a.tofile(fd) Traceback (most recent call last): File stdin, line 1, in module IOError: first argument must be a string or open file In the bigger picture, I want to be able to write multiple numpy arrays with some metadata to a binary file for very fast reading, and these arrays are pretty compressible (strings of small integers), so I can probably benefit in speed and file size by gzipping. Thanks, Sean Use fd.write(a) The documentation says that gzip simulates most of the methods of a file object. Apparently that means it does not subclass it. numpy.tofile wants a file object Or something like that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Confusion with weakref, __del__ and threading
On Jun 11, 1:40 am, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 10, 8:15 pm, George Sakkis [EMAIL PROTECTED] wrote: I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the instance that is passed to the thread instead of 'self', to prevent a cyclic reference. This probably sounds like gibberish so here's a simplified example: == import time import weakref import threading num_main = num_other = 0 main_thread = threading.currentThread() class Mystery(object): def __init__(self): proxy = weakref.proxy(self) self._thread = threading.Thread(target=target, args=(proxy,)) self._thread.start() def __del__(self): global num_main, num_other if threading.currentThread() is main_thread: num_main += 1 else: num_other += 1 def sleep(self, t): time.sleep(t) def target(proxy): try: proxy.sleep(0.01) except weakref.ReferenceError: pass if __name__ == '__main__': for i in xrange(1000): Mystery() time.sleep(0.1) print '%d __del__ from main thread' % num_main print '%d __del__ from other threads' % num_other == When I run it, I get around 950 __del__ from the main thread and the rest from non-main threads. I discovered this accidentally when I noticed some ignored AssertionErrors caused by a __del__ that was doing self._thread.join(), assuming that the current thread is not self._thread, but as it turns out that's not always the case. So what is happening here for these ~50 minority cases ? Is __del__ invoked through the proxy ? The trick here is that calling proxy.sleep(0.01) first gets a strong reference to the Mystery instance, then holds that strong reference until it returns. Ah, that was the missing part; I thought that anything accessed through a proxy didn't create a strong reference. The good thing is that it seems you can get a proxy to a bounded method and then call it without creating a strong reference to 'self': num_main = num_other = 0 main_thread = threading.currentThread() class MysterySolved(object): def __init__(self): sleep = weakref.proxy(self.sleep) self._thread = threading.Thread(target=target, args=(sleep,)) self._thread.start() def __del__(self): global num_main, num_other if threading.currentThread() is main_thread: num_main += 1 else: num_other += 1 def sleep(self, t): time.sleep(t) def target(sleep): try: sleep(0.01) except weakref.ReferenceError: pass if __name__ == '__main__': for i in xrange(1000): MysterySolved() time.sleep(.1) print '%d __del__ from main thread' % num_main print '%d __del__ from other threads' % num_other == Output: 1000 __del__ from main thread 0 __del__ from other threads Thanks a lot, I learned something new :) George -- http://mail.python.org/mailman/listinfo/python-list
Reading info from an active file
I have a program that writes a log file as it is running to give status of the job. I would like to read that file, pull certain lines of text from it, and write to a new file. Because I am such a novice user, I was hoping someone had covered this before and could let me know of your methods. If I open and close the file repeatedly to get refreshed information, I assume it would slow the system down. Any thoughts? Keith Nation -- http://mail.python.org/mailman/listinfo/python-list
Finding a sense of word in a text
Dear all, This might be off group but I am looking for a python library that can help me to find a sense of a word in a text and eventually a list of synonyms of that term. I searched the web and found one but it is written in perl (http://www.d.umn.edu/~tpederse/senserelate.html) :( I appreciate any pointers. Thank you before hand. Kind regards, Sengly -- http://mail.python.org/mailman/listinfo/python-list
web2py forum or mailing list?
i cant find a web2py mailing list or forum, not by googling and not on the web2py homepage. (yes thats right im asking about web2py not webpy). this framework seems great and i installed and it seems like all i wished for. easy to install, easy to use, fast, etc. just an overall better, complete and more professional framework than anything else out there. do id like to discuss it somewhere, is there such a place? -- http://mail.python.org/mailman/listinfo/python-list
question about import
I'm a little unclear about import / __import__ I'm exploring dynamically importing modules for a project, and ran into this behavior works as expected: app = __import__( myapp ) appModel = __import__( myapp.model ) but... appname= 'myapp' app = __import__( %s % appname ) appModel = __import__( %s.model % appname ) In the latter example, app and appModel will always seem to be imported as 'myapp' , and I've yet to find a way to address the .model namespace I know 'dynamically importing modules' is cursed upon -- and I'm likely rewriting hundreds of line of codes so I can work around this with a registration system -- however I'd like to understand why this occurs and know if what i'm trying is even possible. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Okay, so as a response to all of you, I will be using the Entry() widget in Tkinter to get this path. and the repr() function just makes all my backslashes 4 instead of just 1, and it still screwes it up with the numbers and parenthesis is has been since the first post. Oh and I know all about escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough to know that I like python better. Anyway, so far I tried all of your stuff, and it didn't work. infact, it puts backslashes in front of the ' in some of the words, such as I'm goes to I\'m. So I posted the code I will be using if you want to see the Tkinter code I can post it, but I don't see how it will help. Lie Ryan wrote: On Jun 11, 9:14 pm, Carsten Haese [EMAIL PROTECTED] wrote: Lie wrote: In most GUI toolkits (including Tkinter) and raw_input() function, when you input a string (using the textbox, a.k.a Entry widget) it would automatically be escaped for you, so when you input 'path\path \file.txt', the GUI toolkit would convert it into 'path\\path\ \file.txt'. That's incorrect. If you enter text into a text box or in raw_input(), *no* conversion of backslashes is happening. A backslash entered in raw_input is just a backslash. A backslash entered in a textbox is just a backslash. A backslash read from a file is just a backslash. I know, but I thought it'd be easier for him to understand it like that and discover the real 'how-it-works' later. My guilt is that I forget to put a this is not how it actually works behind the scene, but you can think of it like this at least for now since this model is easier to grasp (although misleading). A conversion happens when you print the repr() of a string that was obtained from raw_input or from a text box, because repr() tries to show the string literal that would result in the contents, and in a string literal, a backslash is not (always) a backslash, so repr() escapes the backslashes: py text = raw_input(Enter some text: ) Enter some text: This is a backslash: \ py print text This is a backslash: \ py print repr(text) 'This is a backslash: \\' As you can see, I entered a single backslash, and the string ends up containing a single backslash. Only when I ask Python for the repr() of the string does the backslash get doubled up. -- Carsten Haesehttp://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17782866.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Instructions on how to build py2exe 0.6.8 (or an installer would be nice, too!)
On Jun 10, 8:50 pm, Mike Driscoll [EMAIL PROTECTED] wrote: Evan, snip I finally figured out how to check out the code. I'm at work now, where I only have VS2008 installed so I'll have to wait until I get home this evening to try compiling it. I'll let you know if I have any luck. - Mike Python Extension Building Network: Thanks, Mike. Hopefully you'll have more luck than I've had : ) Evan I got it compiled. They are up on my website: http://pythonlibrary.org/python_modules.htm I tested it on one of my simple programs and it ran. I used the 2.5 version for that test. However, it should be noted that I haven't been able to get the tests from CVS to run. The Traceback doesn't appear to be py2exe related though. I'll post the issue to their group and see if they have any idea why that would be. In the meantime, feel free to give it a try. At worst you'll have to delete the compiled binary and the py2exe folder. Mike Mike - Thank you VERY much! py2exe installed fine and I now have a working single-file executable that I can actually change the name of. Your website looks useful in general; I'll store it away for the next time I need to do Python programming on win32. Larry - I'm of the philosophy that very simple tools (as opposed to full applications) should not require installation, and if the tool is so simple as to not even require saving configuration/preference files (as mine is) it shouldn't even need its own directory. It should just be a simple, convenient, portable executable. I like the OS X .app file format (where the application file is merely a directory that behaves differently by executing the main program when you double- click it, instead of opening the directory) but it doesn't look like that will be adapted on Windows anytime soon, so short of making someone dump a bunch of inconvenient files someplace on their hard drive, a single executable is the most prudent choice, IMHO. Thanks, everyone, for your help! Cheers, Evan -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] python gui
W W wrote: On Wed, Jun 11, 2008 at 10:18 AM, Gabriela Soares [EMAIL PROTECTED] wrote: How ? That's an extremely broad question, and shows little initiative, and offers little information. Most of us are happy to help you solve problems for free, but few, if any, are willing to write your programs for free. Ah, come on, it's not that broad, and easy to answer!! With a lot of patience! -- http://mail.python.org/mailman/listinfo/python-list
Re: question about import
Jonathan Vanasco schrieb: I'm a little unclear about import / __import__ I'm exploring dynamically importing modules for a project, and ran into this behavior works as expected: app = __import__( myapp ) appModel = __import__( myapp.model ) but... appname= 'myapp' app = __import__( %s % appname ) appModel = __import__( %s.model % appname ) In the latter example, app and appModel will always seem to be imported as 'myapp' , and I've yet to find a way to address the .model namespace I know 'dynamically importing modules' is cursed upon -- and I'm likely rewriting hundreds of line of codes so I can work around this with a registration system -- however I'd like to understand why this occurs and know if what i'm trying is even possible. Is it cursed upon? Didn't know that. However, __import__ only gives you the topmost module - in your case myapp. So you need to do it like this (untested): name = a.b.c.d mod = __import__(name) for part in name.split(.)[1:]: mod = getattr(mod, part) print mod Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill a thread?
On Jun 11, 7:56 am, Fuzzyman [EMAIL PROTECTED] wrote: On Jun 11, 6:56 am, Rhamphoryncus [EMAIL PROTECTED] wrote: On Jun 10, 3:41 pm, Fuzzyman [EMAIL PROTECTED] wrote: On Jun 10, 2:03 am, Rhamphoryncus [EMAIL PROTECTED] wrote: How does that protect code like this? f = open('somefile', 'w') # interruption here try: ... finally: ... How does it *not* protect you if you write this instead: f = None try: f = open('somefile', 'w') ... finally: if f is not None: ... Yeah, that should be safe, so long as the open call itself is protected. The calculation is 'coarse grained' (it can call into .NET APIs that can take a relatively long time to return) - so polling for exit wouldn't work anyway. We also run user code and can't expect their code to poll for exit conditions. Do those .NET get interrupted at arbitrary points? Is this untrusted user code also audited for correctness? (Although I'd bet you simply document what you do and blame the user if something breaks.) We don't audit our user code - of course. We do document and assist them as necessary. Changing to a more restrictive model still wouldn't meet our use case and put *more* of a burden on our users. Our situation is not the only one. In general there are situations where you may want to put a long running calulcation on a background thread and you *know* that it is safe to interrupt - but Python currently won't let you. I'm not saying it can't be made to work in your specific case - it likely does work well for you. I'm saying it can't work *in general*. Stretching it out for general use turns those little cracks into massive canyons. A language needs a general mechanism that does work - such as a polite cancellation API. Neither *works in general* - polite cancellation *doesn't* work for our us. That's my point - you probably want *both* for different use cases. :-) Yeah, but mine's less icky. ;) I think the ideal for you would be a separate process. I'd also suggest a restricted VM only in a thread, but that probably wouldn't work for those long-running .NET APIs. Now, if those long- running .NET APIs did polite cancellation, then you could combine that with a restricted VM to get what you need. I think what bothers me is, even if those external APIs support polite cancellation properly, your forced interruptions will bleed over and mess them up. There needs to be a way of containing it better. Writing them in another language (as C is used for most of Python's builtins today) isn't a reasonable requirement. -- http://mail.python.org/mailman/listinfo/python-list
Re: Producer-consumer threading problem
On Jun 11, 6:00 am, George Sakkis [EMAIL PROTECTED] wrote: On Jun 11, 1:59 am, Rhamphoryncus [EMAIL PROTECTED] wrote: Why not use a normal Queue, put a dummy value (such as None) in when you're producer has finished, and have the main thread use the normal Thread.join() method on all your child threads? I just gave two reasons: - Concurrency / interactivity. The main thread shouldn't wait for all one million items to be produced to get to see even one of them. Then don't wait. The main thread can easily do other work while the producer and consumer threads go about their business. - Limiting resources. Just like iterating over the lines of a file is more memory efficient than reading the whole file in memory, getting each consumed item as it becomes available is more memory efficient than waiting for all of them to finish. That's why you give Queue a maxsize. Put it at maybe 5 or 10. Enough that the producer can operate in a burst (usually more efficient that switching threads after each item), then the consumer can grab them all in a burst. Then again, you may find it easier to use an event-driven architecture (like Twisted, as others have suggested.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Confusion with weakref, __del__ and threading
On Jun 11, 10:43 am, George Sakkis [EMAIL PROTECTED] wrote: On Jun 11, 1:40 am, Rhamphoryncus [EMAIL PROTECTED] wrote: The trick here is that calling proxy.sleep(0.01) first gets a strong reference to the Mystery instance, then holds that strong reference until it returns. Ah, that was the missing part; I thought that anything accessed through a proxy didn't create a strong reference. The good thing is that it seems you can get a proxy to a bounded method and then call it without creating a strong reference to 'self': That's not right. Of course a bound method has a strong reference to self, otherwise you'd never be able to call it. There must be something else going on here. Try using sys.setcheckinterval(1) to make threads switch more often. num_main = num_other = 0 main_thread = threading.currentThread() class MysterySolved(object): def __init__(self): sleep = weakref.proxy(self.sleep) self._thread = threading.Thread(target=target, args=(sleep,)) self._thread.start() def __del__(self): global num_main, num_other if threading.currentThread() is main_thread: num_main += 1 else: num_other += 1 def sleep(self, t): time.sleep(t) def target(sleep): try: sleep(0.01) except weakref.ReferenceError: pass if __name__ == '__main__': for i in xrange(1000): MysterySolved() time.sleep(.1) print '%d __del__ from main thread' % num_main print '%d __del__ from other threads' % num_other == Output: 1000 __del__ from main thread 0 __del__ from other threads Thanks a lot, I learned something new :) George -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Alexnb wrote: Okay, so as a response to all of you, I will be using the Entry() widget in Tkinter to get this path. and the repr() function just makes all my backslashes 4 instead of just 1, and it still screwes it up with the numbers and parenthesis is has been since the first post. Oh and I know all about escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough to know that I like python better. Anyway, so far I tried all of your stuff, and it didn't work. infact, it puts backslashes in front of the ' in some of the words, such as I'm goes to I\'m. So I posted the code I will be using if you want to see the Tkinter code I can post it, but I don't see how it will help. Your reluctance to post your code puzzles me. Several people have asked you several times to post your code. We're not doing this to waste your time. In fact, your reluctance to post your code wastes your time and our time by making us guess. Seeing your code should enable us to see exactly what the problem is. Your vague descriptions of what's going on are not useful because they are filtered through your inaccurate understanding of what's going on. I mean no offense by this, but if your understanding were accurate, you wouldn't be here asking for help. So, if you want us to help you, please humor us and post the actual code that gets the filename from the user and attempts to open the file. Also tell us what input you're entering and the output the code produces. -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list