Python Keyring Lib v0.2 Released
Hi all, We're proud to annouce that Python keyring lib 0.2 is released. Introduction = The Python keyring lib provides a easy way to access the system keyring service from python. It can be used in any application that needs safe password storage. Page on PyPI: http://pypi.python.org/pypi/keyring/ What's new in v0.2? === It's a bugfix-only version for v0.1, the major change is the support for Python 2.4+. So if you're using Python 2.6, it's not needed to upgrade. Regards, Kang -- Kang Zhang Computer Science Dept. Shanghai Jiao Tong University -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Announcing: Python Open Mike blog
A new blog, python-open-mike.posterous.com, has been created for open discussion in the Python community. *Anyone* can post to this blog, simply by emailing to p...@python-open-mike.posterous.com. Not everyone has, wants, or feels ready for a blog of their own; we want to make sure that everyone has a chance to speak out to the Python community. We hope to broaden discussion in the Python blogosphere by making it even easier for new participants to join in the conversation. Blog posts will be moderated, so there will be a delay in your posting until a moderator can review them. They should be relevant to the Python community. Please include your name in your post, unless you have a specific reason for wishing to remain anonymous. -- - Catherine http://catherinedevlin.blogspot.com/ *** PyOhio * July 25-26, 2009 * pyohio.org *** -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: unicode + xml
Can someone confirm that the issue here is I need to encode the xml data using: # encode as UTF-8 utf8_string = xml.encode( 'utf-8' ) and then post it to the server. Laurent - Original Message From: Laurent Luce laurentluc...@yahoo.com To: Mark Tolonen metolone+gm...@gmail.com; python-list@python.org Sent: Monday, September 7, 2009 10:50:22 PM Subject: Re: unicode + xml The xml data is generated on Windows (python 2.6.2) and sent using a post request to a Django server. The django server is running on Ubuntu server with python 2.6.2. The post data is passed to minidom for parsing. Laurent - Original Message From: Mark Tolonen metolone+gm...@gmail.com To: python-list@python.org Sent: Monday, September 7, 2009 9:15:15 PM Subject: Re: unicode + xml Laurent Luce laurentluc...@yahoo.com wrote in message news:255473.44957...@web54203.mail.re2.yahoo.com... Hello, I am trying to do the following: - read list of folders in a specific directory: os.listdir() - some folders have Japanese characters - post list of folders as xml to a web server: I used content-type 'text/xml' and I use '?xml version=1.0 encoding=utf-8?' to start the xml data. - on the server side (Django), I get the data using post_data and I use minidom.parseString() to parse it. I get an exception because of the following in the xml for one of the folder name: '/ufffdX/ufffd^/ufffd[/ufffdg /ufffd/ufffd/ufffdj/ufffd/ufffd/ufffd[' The weird thing is that I see 5 bytes for each unicode character: ie: /ufffdX Should I format the data differently inside the xml so minidom is happy ? You aren't seeing 5 bytes for each unicode character. You are seeing '\ufffd' (the code point REPLACEMENT_CHARACTER) intermixed with other characters. The wrong encoding was probably used to decode the filename byte strings to Unicode. We can give more specific help if you specify your operating system and version of Python used. -Mark -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
On 8 Sep, 05:39, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Mon, 07 Sep 2009 01:54:09 -0700, Niklas Norrthon wrote: Others have answered how to replace '\\n' with '\n'. For a more general approach which will handle all string escape sequences allowed in python (including '\xdd' and similar), python's eval can be used: eval can do so much more than handle escape sequences: Yes, eval is really cool :-) quoted_string = ') or __import__(os).system(echo \'Pwn3d\';#rm -rf /' print eval('str(%s)' % quoted_string) Every (bad) programmer should pass untrusted strings to eval as a quick and unsafe way to do trivial transformations. It all depends on the origin of the strings of course. I must admit that I didn't think of str.decode('string_escape') which of course is the correct way to solve the problem (after inspecting a sample of the input data to make sure it conforms to the specification, and isn't rtf or some such). I probably should decrease the volume of quick and dirty one time hacks I produce... /Niklas -- http://mail.python.org/mailman/listinfo/python-list
Re: zip a huge file into multiple small ones
On Mon, Sep 7, 2009 at 5:31 PM, Chris Rebert c...@rebertia.com wrote: On Mon, Sep 7, 2009 at 4:57 AM, Chris Withersch...@simplistix.co.uk wrote: krishna chaitanya wrote: I am new to dealing with zip files in python. I have a huge file which i need to zip and send as an attachment through email. My email restrictions are not allowing me to send it in one go. Is there a way to split this file into multiple zip files, so that i can mail them separately. All the individual zip files should be linked. I should be able to extract the original file by extracting the first of the small zip files. You're using the wrong medium. Upload the file to an http server somewhere and just include a link in the email... One such free service, among many others: http://drop.io/ On Mon, Sep 7, 2009 at 10:14 PM, krishna chaitanyachaitu.de...@gmail.com wrote: Can i automate this process of uploading the zip file into a http server and getting the public url for that? If you're using your own server, certainly. If you're using a third-party service, they need to have an API. Drop.io apparently does: http://api.drop.io/ Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Mon, 07 Sep 2009 19:22:17 -0700, ganesh wrote: My application is a TCP server having multiple client connectons. C++ PTHREADS are for each connected socket and the message received on the socket is evaluated by python functions. If I use only one process level Do you have to use threads? If you use a process per connection, rather than a thread, each process will have its own GIL. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode + xml
Laurent Luce wrote: Can someone confirm that the issue here is I need to encode the xml data using: # encode as UTF-8 utf8_string = xml.encode( 'utf-8' ) and then post it to the server. Well, since you declared it to be UTF-8, it must be UTF-8 encoded. However, your question seems to imply that you generate the XML manually using string concatenation, which is a rather bad idea. Python has great XML tools like ElementTree that help in generating and serialising XML correctly (besides parsing, searching and other things). Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On 8 sep 2009, at 02:25, Neil Hodgson wrote: PythonAB: I dont want to register with a google account, is there any way to use a non-gmail account? A Google account does not mean you have to use gmail. The Google account is used to handle your interaction with Google services and can be used in conjunction with arbitrary email accounts. Just create a Google account and set the email address to your preferred address. Neil No, but it means that more of my data goes into the same company. There's no way to use my own email accounts from my own domain, and I don't have a choice anymore. In other words, if i want to be able to get the wxPython list mail, I'm forced to use a google account, am I not? Is this the start of total control by google? Time to switch to QT then... gr Arno -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 8 Sep, 04:22, ganesh ganeshbo...@gmail.com wrote: My application is a TCP server having multiple client connectons. C++ PTHREADS are for each connected socket and the message received on the socket is evaluated by python functions. If I use only one process level python interpreter, then every thread has to lock the GIL so blocking the other threads from executing the python code even if it is not the same python function that locking thread is calling. Usually, TCP-servers are I/O bound. You can safely use a single Python process for this. A function evaluating a request will hold the GIL for a while (but not until it's done). But most other threads will be blocked waiting for I/O. Thus, there will be little contention for the GIL anyway, and it should not affect scalability much. Only when multiple requests are processed simultaneously will threre be contention for the GIL. You can create high-performance TCP servers in plain Python using e.g. Twisted. If you are in the strange situation that a TCP server is compute-bound, consider using multiple processes (os.fork or multiprocessing). I think there is no way that we can achieve this because of the GIL being a process level state. Least I can do is have one python interpreter initialized in main thread and lock the GIL in every thread for python calls. I think you will find out your server is indeed I/O bound, like 99.9% or all other TCP servers on this planet. Try to embed a single interpreter first. Use the simplified GIL API I showed you. Most likely you will find that it suffice. If you need something more scalable, associate each pthread with a separate Python process - e.g. using a named pipe on Windows or Unix domain socket on Linux. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 8, 2:46 pm, I V ivle...@gmail.com wrote: Do you have to use threads? If you use a process per connection, rather than a thread, each process will have its own GIL. No, i cannot change from threads to processes for handling connections. This will change the complete design of our application which is not feasilbe for python evaluation of the strings. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 8 Sep, 08:46, I V ivle...@gmail.com wrote: Do you have to use threads? If you use a process per connection, rather than a thread, each process will have its own GIL. If ganesh is using Linux or Unix (which pthreads indicate), fork() is just as efficient as threads. On Windows one would need to keep a farm of prespawned Python processes, connected with pipes to the main server. -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On 8 Sep, 09:14, ganesh ganeshbo...@gmail.com wrote: No, i cannot change from threads to processes for handling connections. This will change the complete design of our application which is not feasilbe for python evaluation of the strings. So the problem is actually bad design? -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
On Monday 07 September 2009 20:26:02 John Nagle wrote: Right. Tracking mutablity and ownership all the way down without making the language either restrictive or slow is tough. In multi-thread programs, though, somebody has to be clear on who owns what. I'm trying to figure out a way for the language, rather than the programmer, to do that job. It's a major source of trouble in threaded programs. I think that trying to make the language instead of the programmer responsible for this is a ball-buster. It is unlikely to be either easy or cheap. I would rather have the programmer responsible for the mental model, and give her the tools to do the job with. In any case - if you do not actually like juggling with knives, then you should not be mucking around with concurrency, and by making the language safe, you are taking the fun out. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: using python interpreters per thread in C++ program
On Sep 8, 9:28 am, Mark Hammond skippy.hamm...@gmail.com wrote: I was referring to the 'multiple interpreters in one process' feature of Python which is largely deprecated, ... Can you please point to where in the documentation for Python it says that support for multiple interpreters in one process is 'largely deprecated'. I know that various people would like the feature to go away, but I don't believe I have ever seen an official statement from Guido or other person in a position to make one, state that the official view was that the API was deprecated. Even in Python 3.1 the documentation for the APIs seems to merely state some of the limitations and that it is a hard problem, even still saying that problem would be addressed in future versions. Graham -- http://mail.python.org/mailman/listinfo/python-list
Migrate From PyQt3 to PyQt4
I want to migrate from qt,pyqt,pykde 3 to 4 and remove all *.py files to work with newer version, also after remove pyqt3support. How can I do it in easy way ? I've read here http://www.mail-archive.com/p...@riverbankcomputing.com/msg15009.html something about deprecation warning but can't see such warning anywhere. My python modules also produce a lot of output so I can easily overlook such information. Is there a way to stop execution after every old qt3 class/method? I know I can remove all qt3, qt3support libs, but I don't want to make whole system unstable because of one project. -- http://mail.python.org/mailman/listinfo/python-list
Re: First release of pyfsevents
On Sep 8, 6:19 am, a...@pythoncraft.com (Aahz) wrote: There's no direct equivalent to Linux inotify [...] pnotify ? ingo -- http://mail.python.org/mailman/listinfo/python-list
python web mail clients, are there any decent ones?
Hi, I've been looking but it seems I cannot find a decent web mail client on a python platform. I'm looking for something like roundcube or conjoon or thehorde, but I don't want to use a PHP solution mostly because the web app is python (django) and I want to continue using the apache worker mpm (php needs prefork, as it's not thread safe). Doesn't matter if imap or pop3, although I'd prefer direct maildir access. Has anyone come along anything nice? Thanks, BL -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
Hendrik van Rooyen hend...@microcorp.co.za writes: In any case - if you do not actually like juggling with knives, then you should not be mucking around with concurrency, and by making the language safe, you are taking the fun out. Oh come on, Erlang and Haskell both take care of it rather well. -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
On Tue, 08 Sep 2009 09:38:51 +0200, Hendrik van Rooyen wrote: On Monday 07 September 2009 20:26:02 John Nagle wrote: Right. Tracking mutablity and ownership all the way down without making the language either restrictive or slow is tough. In multi-thread programs, though, somebody has to be clear on who owns what. I'm trying to figure out a way for the language, rather than the programmer, to do that job. It's a major source of trouble in threaded programs. I think that trying to make the language instead of the programmer responsible for this is a ball-buster. It is unlikely to be either easy or cheap. I would rather have the programmer responsible for the mental model, and give her the tools to do the job with. That was the situation 20 years ago with memory management. I'm sure people back then thought that the Right Solution was to give the programmer tools to get the job done, and hope they can avoid dereferencing nil pointers and memory leaks and all the other cruft of hand-managing memory. Today, we have garbage collectors and high-level languages like Ruby, Python, Haskell etc that manage that for you, and even heavyweight garbage collectors are practical for the majority of userspace applications. In any case - if you do not actually like juggling with knives, then you should not be mucking around with concurrency, and by making the language safe, you are taking the fun out. If by fun you mean screaming horrors, I agree. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: logger module : Question about log message format
jorma kala jjkk73 at gmail.com writes: Hi,I've created a logger like this: LOG_FILENAME = 'test.txt' fh=logging.FileHandler(LOG_FILENAME,'w') logger1 = logging.getLogger('myLogger1') logger1.addHandler(fh) logger1.setLevel(logging.INFO)logger1.info('message from logger1') and was hoping to get log messages in this format in my log file: :INFO:myLogger1:message from logger1 instead I just get a plain message like this: message from logger1 Do you know why? Many thanks. If you use basicConfig() to configure the logging system, you get a format string of %(levelname)s:%(name)s:%(message)s, which gives you output like you say you're expecting. If you don't, the default format used is just %(message)s, which gives you only the message part. The format used by basicConfig is available as BASIC_FORMAT; if you want that format you can initialise a formatter and attach it to your handler: f = logging.Formatter(logging.BASIC_FORMAT) fh.setFormatter(f) -- http://mail.python.org/mailman/listinfo/python-list
Regular Expression problem
I have the following source code import re d = 'RTCB\r\nsignature:\xf1\x11 \xde\x10\xfe\x0f\x9c\x10\xf6\xc9_\x10\xf3\xeb\x10\xf2Zt\x10\xef\xd2\x91\x10\xe6\xe7\xfb\x10\xe5p\x99\x10\xe2\x1e\xdf\x10\xdb\x0e\x9f\x10\xd8p\x06\x10\xce\xb3_\x10\xcc\x8d\xe2\x10\xc8\x00\xa4\x10\xc5\x994\x10\xc2={\x10\xc0\xdf\xda\x10\xbb\x03\xa3\x1 0\xb6E\n\x10\xacM\x12\x10\xa5`\xaa\x10\xa0\xaa\x1b\x10\x9bwy\x10\x9a\xc4w\x10\x95\xb6\xde\x10\x93o \x10\x89N\xd3\x10\x86\xda=\x00\x00\x00\x00\x00\x00\x00\x00\r\ncef-ip:127.0.0.1\r\nsender-ip:152.100.123.77\r\n\r\n' m = re.search('signature:(.*?)\r\n',d) --- as you can see, there is signature:... in front of d but re.search can not find the match object, it return None object... i don't know why this happened?? (i have test other cases, but i met this string which can't be search for) could anyone have any suggestions? -- [1;36m※Post by [37mcommand [36mfrom [33m59-124-255-226.HINET-IP.[m [1;36m老鼠的香香乳酪洞[31m˙[33m電子佈告欄系統[31m˙[32malexbbs.twbbs.org[31m˙[37m140.113.166.7[m -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression problem
2009/9/8 找尋自己的一片天 command@alexbbs.twbbs.org: I have the following source code import re d = 'RTCB\r\nsignature:\xf1\x11 \xde\x10\xfe\x0f\x9c\x10\xf6\xc9_\x10\xf3\xeb\x10\xf2Zt\x10\xef\xd2\x91\x10\xe6\xe7\xfb\x10\xe5p\x99\x10\xe2\x1e\xdf\x10\xdb\x0e\x9f\x10\xd8p\x06\x10\xce\xb3_\x10\xcc\x8d\xe2\x10\xc8\x00\xa4\x10\xc5\x994\x10\xc2={\x10\xc0\xdf\xda\x10\xbb\x03\xa3\x1 0\xb6E\n\x10\xacM\x12\x10\xa5`\xaa\x10\xa0\xaa\x1b\x10\x9bwy\x10\x9a\xc4w\x10\x95\xb6\xde\x10\x93o \x10\x89N\xd3\x10\x86\xda=\x00\x00\x00\x00\x00\x00\x00\x00\r\ncef-ip:127.0.0.1\r\nsender-ip:152.100.123.77\r\n\r\n' m = re.search('signature:(.*?)\r\n',d) --- as you can see, there is signature:... in front of d but re.search can not find the match object, it return None object... i don't know why this happened?? (i have test other cases, but i met this string which can't be search for) could anyone have any suggestions? -- [1;36m※Post by [37mcommand[36mfrom [33m59-124-255-226.HINET-IP. [m [1;36m老鼠的香香乳酪洞 [31m˙ [33m電子佈告欄系統 [31m˙ [32malexbbs.twbbs.org [31m˙ [37m140.113.166.7 [m -- http://mail.python.org/mailman/listinfo/python-list I seems, that the problem is in the . [dot] not matching the newline character by default; there is a \n before the first next \r\n. If this is intentional (i.e.the mix of line endings in one string) and you want to make dot match any character, use e.g. the search pattern: (?s)signature:(.*?)\r\n hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on File Input and AST
On Sep 6, 1:49 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 06 Sep 2009 00:53:43 -0700,joy99wrote: Dear Group, I have a file test1.txt. Now, as I do the file handling, i try to do any one of the following operations. 1. open_file=open(/python26/test1.txt,r) # FOR READING 2. open_file=open(/python26/test1.txt,r+) # FOR READING AND WRITING BOTH [Either of 1 or 2 to open as the need be] 3. read_file=open_file.read() etc... But how to work with fileinput or ast. I tried to read python docs and some backlog question answer in the group but it did not help much. At the interactive interpreter, do this: import fileinput help(fileinput) and read the help text. It gives you an example: [quote] Typical use is: import fileinput for line in fileinput.input(): process(line) This iterates over the lines of all files listed in sys.argv[1:], defaulting to sys.stdin if the list is empty. If a filename is '-' it is also replaced by sys.stdin. To specify an alternative list of filenames, pass it as the argument to input(). A single file name is also allowed. [end quote] If there is something unclear about that, then please try to be specific about what you don't understand. Try some code, and report what errors you get. As far as ast, there's an example here: http://docs.python.org/dev/whatsnew/2.6.html#the-ast-module and a discussion here: http://stackoverflow.com/questions/768634/python-parse-a-py-file-read... ast-modify-it-then-write-back-the-modified If you explain what you want to do, perhaps there's somebody out there who knows the ast module and can answer. -- Steven- Hide quoted text - - Show quoted text - Dear Sir, Thank you for your kind reply. I will have a check on them soon. Warm Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression problem
On Tue, 08 Sep 2009 09:21:35 +, §äŽmŠÛ€vªº...@€ù€Ñ wrote: I have the following source code import re d = 'RTCB\r\nsignature:\xf1\x11 \xde\x10\xfe\x0f\x9c\x10\xf6\xc9_\x10\xf3\xeb\x10\xf2Zt\x10\xef\xd2\x91 \x10\xe6\xe7\xfb\x10\xe5p\x99\x10\xe2\x1e\xdf\x10\xdb\x0e\x9f\x10\xd8p\x06 \x10\xce\xb3_\x10\xcc\x8d\xe2\x10\xc8\x00\xa4\x10\xc5\x994\x10\xc2={\x10 \xc0\xdf\xda\x10\xbb\x03\xa3\x1 0\xb6E\n\x10\xacM\x12\x10\xa5`\xaa\x10\xa0\xaa\x1b\x10\x9bwy\x10\x9a \xc4w\x10\x95\xb6\xde\x10\x93o \x10\x89N\xd3\x10\x86\xda=\x00\x00\x00\x00\x00\x00\x00\x00\r\ncef- ip:127.0.0.1\r\nsender-ip:152.100.123.77\r\n\r\n' m = re.search('signature:(.*?)\r\n',d) --- as you can see, there is signature:... in front of d but re.search can not find the match object, it return None object... That's because you're trying to match over multiple lines. You need to specify the DOTALL flag. I've re-formatted the string constant to take advantage of Python string concatenation, so it is easier to copy and paste into the interactive interpreter: d =('RTCB\r\nsignature:' '\xf1\x11\xde\x10\xfe\x0f\x9c\x10\xf6\xc9' '_\x10\xf3\xeb' '\x10\xf2' 'Zt\x10\xef\xd2\x91\x10\xe6\xe7\xfb\x10\xe5' 'p\x99\x10\xe2\x1e\xdf\x10\xdb\x0e\x9f\x10\xd8' 'p\x06\x10\xce\xb3' '_\x10\xcc\x8d\xe2\x10\xc8\x00\xa4\x10\xc5\x99' '4\x10\xc2' '={\x10\xc0\xdf\xda\x10\xbb\x03\xa3\x10\xb6' 'E\n\x10\xac' 'M\x12\x10\xa5' '`\xaa\x10\xa0\xaa\x1b\x10\x9b' 'wy\x10\x9a\xc4' 'w\x10\x95\xb6\xde\x10\x93' 'o\x10\x89' 'N\xd3\x10\x86\xda' '=\x00\x00\x00\x00\x00\x00\x00\x00' '\r\ncef-ip:127.0.0.1\r\nsender-ip:152.100.123.77\r\n\r\n' ) assert len(d) == 182 re.search('signature:(.*?)\r\n', d) re.search('signature:.*?\r\n', d, re.DOTALL) m _sre.SRE_Match object at 0xb7e98138 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Modifying a row in a textfile
Hi! I got a textfile made out of database records. Is there an easy way to modify rows in that file in case you have to take away some items here and there from each rows. Tanks! OV -- http://mail.python.org/mailman/listinfo/python-list
hanning python
Hello, anyone knows what is the python equivalent of the matlab's hanning function. Note that in matlab hann and hanning are different. Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
Makes sense to me. To step through what's happening: A.n, B.n (0, 0) Here, the lookup on B.n fails (that is, B itself has no variable n), and thus falls back to A.n See, this is what tripped me up, right at the beginning. I thought B would inherit (as in copy) the variable n from A. Can you point out to me which part (or parts) of the Language Reference says this is the way it's supposed to be? -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Sep 8, 12:36 pm, Pierre pierre.gaill...@gmail.com wrote: Hello, anyone knows what is the python equivalent of the matlab's hanning function. Note that in matlab hann and hanning are different. Thanks ! I assume you mean the tapering function mentioned here: http://mathworld.wolfram.com/HanningFunction.html Python is a general purpose language, unlike the maths-specialized MATLAB. I suggest you look into numpy, in which, a quick googling suggests, an implementation of a the Hanning function is provided. In fact, if you're using python to replace matlab in any meaningful way, you'll probably want to use numpy anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: Modifying a row in a textfile
Olli Virta wrote: Hi! I got a textfile made out of database records. Is there an easy way to modify rows in that file in case you have to take away some items here and there from each rows. for line in inf.readlines(): if matches_criteria(line): line = modify_line(line) outf.write(line) Diez -- http://mail.python.org/mailman/listinfo/python-list
google tech talk code (threading module)
I took a little code from google tech talk. It seems interesting, but it doesn't work: import sys, urllib, os, threading, Queue q = Queue.Queue() class RetrWorker(threading.Thread): def run(self): self.setDaemon(True) def hook(*a): print (fn,a) while True: url = q.get() fn = os.path.basename(url) print url, -, fn urllib.urlretrive(url, fn, hook) for i in range(10): RetrWorker().start() for url in sys.argv[1:]: q.put(url) Exception in thread Thread-10: Traceback (most recent call last): File /usr/lib64/python2.6/threading.py, line 522, in __bootstrap_inner self.run() File wget_m.py, line 7, in run self.setDaemon(True) File /usr/lib64/python2.6/threading.py, line 690, in setDaemon self.daemon = daemonic File /usr/lib64/python2.6/threading.py, line 683, in daemon raise RuntimeError(cannot set daemon status of active thread); RuntimeError: cannot set daemon status of active thread -- http://mail.python.org/mailman/listinfo/python-list
Soap with python?
Hi - Does anyone have a reccommendation on the best soap library for Python? Of the products I found, ZSI has had the most recent release 2007. Otto -- http://mail.python.org/mailman/listinfo/python-list
Re: google tech talk code (threading module)
wiso wrote: I took a little code from google tech talk. It seems interesting, but it doesn't work: import sys, urllib, os, threading, Queue q = Queue.Queue() class RetrWorker(threading.Thread): def run(self): self.setDaemon(True) def hook(*a): print (fn,a) while True: url = q.get() fn = os.path.basename(url) print url, -, fn urllib.urlretrive(url, fn, hook) for i in range(10): RetrWorker().start() for url in sys.argv[1:]: q.put(url) Exception in thread Thread-10: Traceback (most recent call last): File /usr/lib64/python2.6/threading.py, line 522, in __bootstrap_inner self.run() File wget_m.py, line 7, in run self.setDaemon(True) File /usr/lib64/python2.6/threading.py, line 690, in setDaemon self.daemon = daemonic File /usr/lib64/python2.6/threading.py, line 683, in daemon raise RuntimeError(cannot set daemon status of active thread); RuntimeError: cannot set daemon status of active thread The traceback explains why. self.setDaemon(True) is in the 'run' method, which is called when the thread starts (becomes active), but you're not allowed to turn the thread into a daemon after it has started. -- http://mail.python.org/mailman/listinfo/python-list
Re: Soap with python?
On 09/08/2009 08:40 AM, Otto Hellwig wrote: reccommend [sic ...] the best soap library ... Client side only? Suds (https://fedorahosted.org/suds/). Accept no subsitute! -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On 8 Sep, 13:36, Pierre pierre.gaill...@gmail.com wrote: anyone knows what is the python equivalent of the matlab's hanning function. Note that in matlab hann and hanning are different. If you don't know how to compute a von Hann window, you are not competent to do any scientific programming. Seriously! I assume you are using NumPy and SciPy, so consider scipy.signal.hanning for convinience. -- http://mail.python.org/mailman/listinfo/python-list
Extracting patterns after matching a regex
Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Sep 8, 1:55 pm, sturlamolden sturlamol...@yahoo.no wrote: On 8 Sep, 13:36, Pierre pierre.gaill...@gmail.com wrote: anyone knows what is the python equivalent of the matlab's hanning function. Note that in matlab hann and hanning are different. If you don't know how to compute a von Hann window, you are not competent to do any scientific programming. Seriously! Come, come. I think it's a good rule that, where available, a vendor- supplied implementation is the preferable choice until proven otherwise. I assume you are using NumPy and SciPy, so consider scipy.signal.hanning for convinience. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Martin wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, m = re.search(rFTPHOST: (.*), s) print m.group(1) -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 1:56 pm, Martin mdeka...@gmail.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin What you're doing is telling python look for all matches of 'FTPHOST'. That doesn't really help you much, because you pretty much expect FTPHOST to be there anyway, so finding it means squat. What you _really_ want to tell it is Look for things shaped like 'FTPHOST: ftpaddress', and tell me what ftpaddress actually is. Look here: http://docs.python.org/howto/regex.html#grouping. That'll explain how to accomplish what you're trying to do. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Martin mdeka...@gmail.com wrote in message news:5941d8f1-27c0-47d9-8221-d21f07200...@j39g2000yqh.googlegroups.com... Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! In regular expressions, you match the entire string you are interested in, and parenthesize the parts that you want to parse out of that string. The group() method is used to get the whole string with group(0), and each of the parenthesized parts with group(n). An example: s = FTPHOST: e4ftl01u.ecs.nasa.gov import re re.search(r'FTPHOST: (.*)',s).group(0) 'FTPHOST: e4ftl01u.ecs.nasa.gov' re.search(r'FTPHOST: (.*)',s).group(1) 'e4ftl01u.ecs.nasa.gov' -Mark -- http://mail.python.org/mailman/listinfo/python-list
[wxGlade] - How to add new event to a button in events tab
Hi, I am a newbie of wxGlade (0.6.2). I am trying buiding a simple application which is a frame contains a button. In the button properties window, select the events tab, there is a default event EVT_BUTTON, I have added a handler to this event, when I want to add a new event to the button here, but can't find how to do it. If we can only add a new event to a button manually in wxGlade? -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 2:15 pm, MRAB pyt...@mrabarnett.plus.com wrote: Martin wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, m = re.search(rFTPHOST: (.*), s) print m.group(1) so the .* means to match everything after the regex? That doesn't help in this case as the string is placed amongst others for example. MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', -- http://mail.python.org/mailman/listinfo/python-list
[wxGlade] - How to add new event to a button in events tab
Hi, I am a starter of wxGlade (0.6.2). I am trying buiding a simple application which is a frame contains a button. In the button properties window, select the events tab, there is a default event EVT_BUTTON, I have added a handler to this event, when I want to add a new event to the button here, but can't find how to do it. If we can only add a new event to a button manually in wxGlade? -- http://mail.python.org/mailman/listinfo/python-list
Re: Migrate From PyQt3 to PyQt4
nusch wrote: I want to migrate from qt,pyqt,pykde 3 to 4 and remove all *.py files to work with newer version, also after remove pyqt3support. How can I do it in easy way ? I've read here http://www.mail-archive.com/p...@riverbankcomputing.com/msg15009.html something about deprecation warning but can't see such warning anywhere. My python modules also produce a lot of output so I can easily overlook such information. Is there a way to stop execution after every old qt3 class/method? I know I can remove all qt3, qt3support libs, but I don't want to make whole system unstable because of one project. Generic answer: when migrating one Python project independent of others on the same system, I'd suggest having an independent Python installation for the temporary mix of addon libraries. In your case the only difference might be the absense of the qt version 3 stuff. The way of supporting multiple environments varies by system and by user environment, but generally you can either change the shebang line, or the script/batch file you start the application with. If you're on Windows, you do not want to change the file association to point to the new environment, so be careful during install, not to make this the default Python installation. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 2:21 pm, Mark Tolonen metolone+gm...@gmail.com wrote: Martin mdeka...@gmail.com wrote in message news:5941d8f1-27c0-47d9-8221-d21f07200...@j39g2000yqh.googlegroups.com... Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! In regular expressions, you match the entire string you are interested in, and parenthesize the parts that you want to parse out of that string. The group() method is used to get the whole string with group(0), and each of the parenthesized parts with group(n). An example: s = FTPHOST: e4ftl01u.ecs.nasa.gov import re re.search(r'FTPHOST: (.*)',s).group(0) 'FTPHOST: e4ftl01u.ecs.nasa.gov' re.search(r'FTPHOST: (.*)',s).group(1) 'e4ftl01u.ecs.nasa.gov' -Mark I see what you mean regarding the groups. Because my string is nested in amongst others e.g. MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', I get the information that follows as well. So is the only way to then parse the new string? I am trying to construct something that is fairly robust, so not sure just printing before the \r is the best solution. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
HPJ wrote: Makes sense to me. To step through what's happening: A.n, B.n (0, 0) Here, the lookup on B.n fails (that is, B itself has no variable n), and thus falls back to A.n See, this is what tripped me up, right at the beginning. I thought B would inherit (as in copy) the variable n from A. Python does not copy objects unless asked to. Inheritance is a link request, not a copy request. Can you point out to me which part (or parts) of the Language Reference says this is the way it's supposed to be? I could, but I will let you read and find what it says about class attributes. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 3:21 pm, nn prueba...@latinmail.com wrote: On Sep 8, 9:55 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks It is not clear from your post what the input is really like. But just guessing this might work: print s 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n','FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r \n','Ftp Pull Download Links: \r\n' re.search(r'FTPHOST: (.*?)\\r',s).group(1) 'e4ftl01u.ecs.nasa.gov' Except, I'm assuming, the OP's getting the data from a (windows- formatted) file, so \r\n shouldn't be escaped in the regex: re.search(r'FTPHOST: (.*?)\r',s).group(1) -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
RE: Extracting patterns after matching a regex
Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: Extracting patterns after matching a regex
Mart. wrote: snip I have been doing this to turn the email into a string email =ys.argv[1] f =open(email, 'r') s =str(f.readlines()) so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', snip The mistake I see is trying to turn a list into a string, just so you can try to parse it back again. Just write a loop that iterates through the list that readlines() returns. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: On Sep 8, 2:15 pm, MRAB pyt...@mrabarnett.plus.com wrote: Martin wrote: Hi, I need to extract a string after a matching a regular expression. Whether or not you need re is an issue to be determined. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. Just split the string on ': ' and take the second part. Or find the position of the space and slice the remainder. so the .* means to match everything after the regex? That doesn't help in this case It helps in the case you presented. as the string is placed amongst others for example. MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', What you show above is a tuple of strings. Scan the members looking for s.startswith('FTPHOST:') and apply previous answer. Or if above is actually meant to be one string (with quotes omitted), split in ',' and apply previous answer. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: incorrect DeprecationWarning (patch needed)
On 9/5/2009 5:50 PM, Alan G Isaac wrote: I've filed a bug report: http://bugs.python.org/issue6844 This is now an accepted bug with a patch request. Can someone on this list please assist with a patch? Thanks, Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 9:55 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks It is not clear from your post what the input is really like. But just guessing this might work: print s 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n','FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r \n','Ftp Pull Download Links: \r\n' re.search(r'FTPHOST: (.*?)\\r',s).group(1) 'e4ftl01u.ecs.nasa.gov' -- http://mail.python.org/mailman/listinfo/python-list
Output file formatting/loop problems -- HELP?
My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string else: print 'The loop is finito' --- here is the sample file -- 23 123 231 1231 --- the output file i get looks like this: 1 23 123 231 1231 -- my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) thanks for your help -- http://mail.python.org/mailman/listinfo/python-list
Re: wxGlade question - How to add new event to a button in events tab?
Could you not post the exact same message 3 times within an hour? -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] possible attribute-oriented class
On Mon, Sep 7, 2009 at 9:02 PM, Jan Kaliszewskiz...@chopin.edu.pl wrote: 08-09-2009 o 02:15:10 Steven D'Aprano st...@pearwood.info wrote: ... what's wrong with this? a['xyz'] = something['blablabla'] + somethingelse['foobar'] b['ababababa'] += afun(bobo['dodo']['kookoo'] * pofopofo['gh'][0]['a']) cupu['abc'] = (kukumunu['bo'], kukumunu['kuu'].mbmbmb['lalala']) a.xyz = something.blablabla + somethingelse.foobar b.ababababa += afun(bobo.dodo.kookoo * pofopofo.gh[0].a) cupu.abc = (kukumunu.bo, kukumunu.kuu.mbmbmb.lalala) For me the latter is definitely easier to read and understand. I would describe it as less difficult rather than easier. My biggest problem is that at that stage, I'm still typing raw, and inclined to make typos. The difference between fname and fnam won't be caught either way, but field access at least keeps me from forgetting quotes, or forgetting them at one end. ... I often change field names two or three times before I settle in on the final version. And often because of an ambiguity with another field that I hadn't originally thought to name. Neither solution fixes this, but attribute access is slightly easier to change. [recipe to simplify attr-access] I think it depends how often people need to implement such boiler-plate code for themselves. Attribute access is clearly better -- except for one thing. While I'm doing this, I'm still in exploratory mode, and I *will* need to clean up the API if I ever want better than quick-and-dirty. If the quick-and-dirty is already using attribute access, that makes the transition a bit trickier. If the quick-and-dirty is using dict access, at least I have a clear marker. -jJ -- http://mail.python.org/mailman/listinfo/python-list
wxGlade question - How to add new event to a button in events tab?
Hi, I am a starter of wxGlade (0.6.2). I am trying buiding a simple application which is a frame contains a button. In the button properties window, select the events tab, there is a default event EVT_BUTTON, I have added a handler to this event, when I want to add a new event to the button here, but can't find how to do it. If we can only add a new event to a button manually in wxGlade? -- http://mail.python.org/mailman/listinfo/python-list
RE: Extracting patterns after matching a regex
Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Suppose the file contains your example text above. Using 'readlines' returns a list of the lines: f = open(email, 'r') lines = f.readlines() lines ['TOTAL FILES: 2\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\n', '\t\tFILESIZE: 11028908\n', '\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml\n', '\t\tFILESIZE: 18975\n'] Using 'str' on that list then converts it to s string _representation_ of that list: str(lines) ['TOTAL FILES: 2\\n', '\\t\\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\\n', '\\t\\tFILESIZE: 11028908\\n', '\\n', '\\t\\tFILENAME:
Re: Extracting patterns after matching a regex
On Sep 8, 10:27 am, pdpi pdpinhe...@gmail.com wrote: On Sep 8, 3:21 pm, nn prueba...@latinmail.com wrote: On Sep 8, 9:55 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks It is not clear from your post what the input is really like. But just guessing this might work: print s 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n','FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r \n','Ftp Pull Download Links: \r\n' re.search(r'FTPHOST: (.*?)\\r',s).group(1) 'e4ftl01u.ecs.nasa.gov' Except, I'm assuming, the OP's getting the data from a (windows- formatted) file, so \r\n shouldn't be escaped in the regex: re.search(r'FTPHOST: (.*?)\r',s).group(1) I am just playing the guessing game like everybody else here. Since the OP didn't use re.DOTALL and was getting more than one line for .* I assumed that the \n was quite literally '\' and 'n'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 10:25 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 3:21 pm, nn prueba...@latinmail.com wrote: On Sep 8, 9:55 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks It is not clear from your post what the input is really like. But just guessing this might work: print s 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n','FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r \n','Ftp Pull Download Links: \r\n' re.search(r'FTPHOST: (.*?)\\r',s).group(1) 'e4ftl01u.ecs.nasa.gov' Hi, That does work. So the \ escapes the \r, does this tell it to stop when it reaches the \r? Thanks Indeed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 11:19 am, Dave Angel da...@ieee.org wrote: Mart. wrote: snip I have been doing this to turn the email into a string email =ys.argv[1] f =open(email, 'r') s =str(f.readlines()) so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', snip The mistake I see is trying to turn a list into a string, just so you can try to parse it back again. Just write a loop that iterates through the list that readlines() returns. DaveA No kidding. Instead of this: s = str(f.readlines()) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir I would have possibly done something like this (not tested): lines = f.readlines() header={} for row in lines: key,sep,value = row.partition(':')[2].rstrip() header[key.lower()]=value url = 'ftp://' + header['ftphost'] + header['ftpdir'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 12:16 pm, nn prueba...@latinmail.com wrote: On Sep 8, 11:19 am, Dave Angel da...@ieee.org wrote: Mart. wrote: snip I have been doing this to turn the email into a string email =ys.argv[1] f =open(email, 'r') s =str(f.readlines()) so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', snip The mistake I see is trying to turn a list into a string, just so you can try to parse it back again. Just write a loop that iterates through the list that readlines() returns. DaveA No kidding. Instead of this: s = str(f.readlines()) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir I would have possibly done something like this (not tested): lines = f.readlines() header={} for row in lines: key,sep,value = row.partition(':')[2].rstrip() header[key.lower()]=value url = 'ftp://' + header['ftphost'] + header['ftpdir'] Well I said not tested that would be of course: lines = f.readlines() header={} for row in lines: key,sep,value = row.partition(':') header[key.lower()]=value.rstrip() url = 'ftp://' + header['ftphost'] + header['ftpdir'] -- http://mail.python.org/mailman/listinfo/python-list
Re: [Guppy-pe-list] An iteration idiom (Was: Re: loading files containing multiple dumps)
On Mon, 2009-09-07 at 16:53 +0100, Chris Withers wrote: Sverker Nilsson wrote: I hope the new loadall method as I wrote about before will resolve this. def loadall(self,f): ''' Generates all objects from an open file f or a file named f''' if isinstance(f,basestring): f=open(f) while True: yield self.load(f) It would be great if load either returned just one result ever, or properly implemented the iterator protocol, rather than half implementing it... Agreed, this is arguably a bug or at least a misfeature, as also Raymond Hettinger remarked, it is not normal for a normal function to raise StopIteration. But I don't think I would want to risk breaking someone's code just for this when we could just add a new method. Should we call it loadall? It is a generator so it doesn't really load all immedietally, just lazily. Maybe call it iload? Or redefine load, but that might break existing code so would not be good. loadall works for me, iload doesn't. Or we could have an option to hpy() to redefine load() as loadall(), but I think it is cleaner (and easier) to just define a new method... Settled then? :-) Minor rant, why do I have to instantiate a class 'guppy.heapy.Use._GLUECLAMP_' to do anything with heapy? Why doesn't heapy just expose load, dump, etc? Basically, the need for the h=hpy() idiom is to avoid any global variables. Eh? What's h then? (And h will reference whatever globals you were worried about, surely?) h is what you make it to be in the context you create it; you can make it either a global variable, a local variable, or an object attribute. Interactively, I guess one tends to have it as a global variable, yes. But it is a global variable you created and responds for yourself, and there are no other global variables behind the scene but the ones you create yourself (also possibly the results of heap() etc as you store them in your environment). If making test programs, I would not use global variables but instead would tend to have h as a class attribute in a test class, eg as in UnitTest. It could also be a local variable in a test function. As the enclosing class or frame is deallocated, so is its attribute h itself. There should be nothing that stays allocated in other modules after one test (class) is done (other than some loaded modules themselves, but I am talking about more severe data that can be hundreds of megabytes or more). Heapy uses some rather big internal data structures, to cache such things as dict ownership. I didn't want to have all those things in global variables. What about attributes of a class instance of some sort then? They are already attributes of an instance: hpy() is a convenience factory method that creates a top level instance for this purpose. the other objects you created. Also, it allows for several parallel invocations of Heapy. When is that helpful? For example, the setref() method sets a reference point somewhere in h. Further calls to heap() would report only objects allocated after that call. But you could use a new hpy() instance to see all objects again. Multiple threads come to mind, where each thread would have its own hpy() object. (Thread safety may still be a problem but at least it should be improved by not sharing the hpy() structures.) Even in the absence of multiple threads, you might have an outer invocation of hpy() that is used for global analysis, with its specific options, setref()'s etc, and inner invocations that make some local analysis perhaps in a single method. However, I am aware of the extra initial overhead to do h=hpy(). I discussed this in my thesis. Section 4.7.8 Why not importing Use directly? page 36, http://guppy-pe.sourceforge.net/heapy-thesis.pdf I'm afraid, while I'd love to, I don't have the time to read a thesis... But it is (an important) part of the documentation. For example it contains the rationale and an introduction to the main categories such as Sets, Kinds and EquivalenceRelations, and some usecases for example how to seal a memory leak in a windowing program. I'm afraid, while I'd love to, I don't have the time to duplicate the thesis here...;-) Try sunglasses:) (Well, I am aware of this, it was a research/experimental system and could have some refactoring :-) I would suggest creating a minimal system that allows you to do heap() and then let other people build what they need from there. Simple is *always* better... Do you mean we should actually _remove_ features to create a new standalone system? I don't think that'd be meaningful. You don't need to use anything else than heap() if you don't want to. You are free to wrap functions as you find suitable; a minimal wrapper module could be just like this: # Module heapyheap from guppy import hpy h=hpy() heap=heap() Should we add some such module? In the thesis I discussed this already and argued it was not
Distutils - can user designate install directory for windows installer?
I have successfully built a windows installer for my python program using distutils, (python setup.py bdist_wininst), but is there a way to do it that will allow a user ('user' == 'boss', in this case!) to designate the installation directory, rather than being forced to install into /Python/Lib/site-packages ? Thanks for any help. Best regards, Tim Grove -- http://mail.python.org/mailman/listinfo/python-list
Re: Output file formatting/loop problems -- HELP?
Maggie wrote: On Sep 8, 11:39 am, MRAB pyt...@mrabarnett.plus.com wrote: Maggie wrote: My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: Try adding: print repr(item) here to see what the lines actually look like. It might be a problem with line endings. count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string else: print 'The loop is finito' --- here is the sample file -- 23 123 231 1231 --- the output file i get looks like this: 1 23 123 231 1231 -- my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) thanks for your help great tip, thanks so much -- now this is the output i get in the terminal... '23\r123\r231\r1231' why is it so? since the file is in .txt format - there should be no formatting involved?... how would i fix this? It shows that the line endings are carriage returns '\r'. Line endings on Windows are '\r\n', on Unix/Linux are '\n' and on MacOS are '\r', although recent versions of MacOS built on top of Unix. The easiest solution would be to open the file in universal line-ending mode: test = open (test.txt, rU) This will translate any of the line endings. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 4:33 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Suppose the file contains your example text above. Using 'readlines' returns a list of the lines: f = open(email, 'r') lines = f.readlines() lines ['TOTAL FILES: 2\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\n', '\t\tFILESIZE: 11028908\n', '\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml\n', '\t\tFILESIZE: 18975\n'] Using 'str' on that list then converts
Re: What python can NOT do?
Boot loaders are another type of software which would be impractical to write in existing Python implementations. I wonder if TinyPy (http://www.tinypy.org/) could be used to write a boot loader. It would probably need some more code to replace the services it uses from an OS, and perhaps it would need to work in 16bit program mode on x86 - but maybe it's doable? tinypy is a minimalist implementation of python in 64k of code -- дамјан ( http://softver.org.mk/damjan/ ) Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian W. Kernighan -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess + python-daemon - bug/problem?
I looked at other daemon libraries and snippets, it's clearly the bug is in subprocess not python-daemon. Then I found Python bug #1731717 which discusses it. I wish my project was opensource so I can post more specific test cases. #1731717 http://bugs.python.org/issue1731717 Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 3:21 pm, nn prueba...@latinmail.com wrote: On Sep 8, 9:55 am, Mart. mdeka...@gmail.com wrote: On Sep 8, 2:16 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. Many thanks It is not clear from your post what the input is really like. But just guessing this might work: print s 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n','FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r \n','Ftp Pull Download Links: \r\n' re.search(r'FTPHOST: (.*?)\\r',s).group(1) 'e4ftl01u.ecs.nasa.gov' Hi, That does work. So the \ escapes the \r, does this tell it to stop when it reaches the \r? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Output file formatting/loop problems -- HELP?
On Sep 8, 11:39 am, MRAB pyt...@mrabarnett.plus.com wrote: Maggie wrote: My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: Try adding: print repr(item) here to see what the lines actually look like. It might be a problem with line endings. count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string else: print 'The loop is finito' --- here is the sample file -- 23 123 231 1231 --- the output file i get looks like this: 1 23 123 231 1231 -- my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) thanks for your help great tip, thanks so much -- now this is the output i get in the terminal... '23\r123\r231\r1231' why is it so? since the file is in .txt format - there should be no formatting involved?... how would i fix this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Output file formatting/loop problems -- HELP?
Maggie wrote: My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: Try adding: print repr(item) here to see what the lines actually look like. It might be a problem with line endings. count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string else: print 'The loop is finito' --- here is the sample file -- 23 123 231 1231 --- the output file i get looks like this: 1 23 123 231 1231 -- my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) thanks for your help -- http://mail.python.org/mailman/listinfo/python-list
AUTO: Vacation (returning 09/08/2009)
I am out of the office until 09/08/2009. I will respond to your message when I return. Note: This is an automated response to your message Announcing: Python Open Mike blog sent on 9/8/2009 10:10:46 AM. You will receive a notification for each message you send to this person while the person is away.-- http://mail.python.org/mailman/listinfo/python-list
Re: Output file formatting/loop problems -- HELP?
On Tuesday 08 September 2009 17:22:30 Maggie wrote: My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) After this, do the following and see what you get: for i,line in enumerate(test.readlines()): print i, line my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- It does - but it sees the entire file as one line, somehow. (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) If it is really text, and if there are newlines at the end of the lines, then it should JustWork... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) So don't do that. Or rather, scan the list of lines returned by .readlines *before* dumping it all into one line. Or, try the email module. When the email parser returns a .message.Message instance, msg['FTPHOST'] will give you what you want. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On 8 Sep, 15:08, pdpi pdpinhe...@gmail.com wrote: Come, come. I think it's a good rule that, where available, a vendor- supplied implementation is the preferable choice until proven otherwise. Even for the simplest of equations? -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
Steven D'Aprano wrote: On Tue, 08 Sep 2009 09:38:51 +0200, Hendrik van Rooyen wrote: On Monday 07 September 2009 20:26:02 John Nagle wrote: Right. Tracking mutablity and ownership all the way down without making the language either restrictive or slow is tough. In multi-thread programs, though, somebody has to be clear on who owns what. I'm trying to figure out a way for the language, rather than the programmer, to do that job. It's a major source of trouble in threaded programs. I think that trying to make the language instead of the programmer responsible for this is a ball-buster. It is unlikely to be either easy or cheap. I would rather have the programmer responsible for the mental model, and give her the tools to do the job with. That was the situation 20 years ago with memory management. Good point. The other big point is the CPython deals with concurrency by preventing it. This is killing performance on multi-core CPUs. Read http://www.dabeaz.com/python/GIL.pdf;, which demonstrates just how awful the current GIL implementation is. Adding more CPUs slows CPython down. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
Is the difference because of mutability versus immutability, or because of C code in Numpy versus Matlab code? Are you comparing bananas and pears? It consisted of something like this Your code does a lot of unnecessary work if you're just trying to demonstrate immutability is faster or slower than mutability. A simple test that just adds one to each element would have much less overhead. In any case, there's no doubt that immutable objects require extra time to create compared to re-using an existing mutable object, and that time is probably O(N) (until you approach the limits of available contiguous memory, in which case you could see O(N**2) or worse behaviour). But an order of magnitude difference? I wasn't comparing bananas against pears. Mathworks informed me they were using my code to investigate why Matlab was showing such slow- downs. I am not sure what they found out, eventially. I have also wondered if immutability vs. mutability was the reason, as NumPy generates temporary arrays. But I have not found a better explanation either. Anyhow, ~30 seconds for Matlab vs. ~3 seconds for Python is a major difference. How does Matlab speed compare to Python in general? Ruby, for example, is an order of magnitude slower than Python (at least it was last time I looked) For what operations? Under what circumstances? I'm just being pedantic because you mentioned comparing bananas and pears .. , not because of immutable arrays, but just because of the speed of the language. U, what is 'speed of a language'? I thought ruby or python or anything else as a language is separate from their implementations. Implementations might have 'speed' but languages don't. Aren't you comparing bananas and pears again? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Output file formatting/loop problems -- HELP?
On Sep 8, 12:35 pm, MRAB pyt...@mrabarnett.plus.com wrote: Maggie wrote: On Sep 8, 11:39 am, MRAB pyt...@mrabarnett.plus.com wrote: Maggie wrote: My code is supposed to enumerate each line of file (1, 2, 3...) and write the new version into the output file -- #!/usr/bin/python import os.path import csv import sys #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, r) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: Try adding: print repr(item) here to see what the lines actually look like. It might be a problem with line endings. count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string else: print 'The loop is finito' --- here is the sample file -- 23 123 231 1231 --- the output file i get looks like this: 1 23 123 231 1231 -- my question is why the enumeration starts and stops at first line and doesnt go through the entire file -- (file is saved as .txt, so hypothetically no .rtf formatting that would screw up the output should be present) thanks for your help great tip, thanks so much -- now this is the output i get in the terminal... '23\r123\r231\r1231' why is it so? since the file is in .txt format - there should be no formatting involved?... how would i fix this? It shows that the line endings are carriage returns '\r'. Line endings on Windows are '\r\n', on Unix/Linux are '\n' and on MacOS are '\r', although recent versions of MacOS built on top of Unix. The easiest solution would be to open the file in universal line-ending mode: test = open (test.txt, rU) This will translate any of the line endings. works beautifully now! thank you all for your input!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Soap with python?
On Sep 8, 7:47 am, Jim Wilson j...@wintek.com wrote: On 09/08/2009 08:40 AM, Otto Hellwig wrote: reccommend [sic ...] the best soap library ... Client side only? Suds (https://fedorahosted.org/suds/). Accept no subsitute! Thank you. I will give Suds a try. -- http://mail.python.org/mailman/listinfo/python-list
Help with cumulative sum
Building on the code that I posted in one of the previous posts.. I need to find a cumulative sum of the file of the times in the test file: here is the code i have: #!/usr/bin/python import os.path #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, rU) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: count = count + 1 tmp_string = str(count) + ' ' + item print FILE, tmp_string, else: print 'The loop is finito' - my test file is this 23 241 34234 83 123 and I need to find a CUMULATIVE sum (or the running sum)...what would be the best way to go about that given the code i already have? thank you all! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
If I gave you a list of numbers, could you come up with a summifier function that returns another list of numbers that are a cumulative sum? You've got the information in place to create a file def summifier(nums): Returns a list of numbers that are the running sum totals of nums # ??? list_of_numbers = [1, 24, 34, 28, 4, 1] cumulative_sum = summifier(list_of_numbers) assert(cumulative_sum == [1, 25, 59, 87, 91, 92]) If you can come up with the summifier function, you're all set. I gotta say, though, this smells like homework. Cheers, Cliff On Tue, 2009-09-08 at 12:29 -0700, Maggie wrote: Building on the code that I posted in one of the previous posts.. I need to find a cumulative sum of the file of the times in the test file: here is the code i have: #!/usr/bin/python import os.path #name of output file filename = OUTPUT.txt #open the file test = open (test.txt, rU) #read in all the data into a list readData = test.readlines() count = 0 FILE = open(filename, w) for item in readData: count = count + 1 tmp_string = str(count) + '' + item print FILE, tmp_string, else: print 'The loop is finito' - my test file is this 23 241 34234 83 123 and I need to find a CUMULATIVE sum (or the running sum)...what would be the best way to go about that given the code i already have? thank you all! -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Tue, 08 Sep 2009 11:12:18 -0700, sturlamolden wrote: On 8 Sep, 15:08, pdpi pdpinhe...@gmail.com wrote: Come, come. I think it's a good rule that, where available, a vendor- supplied implementation is the preferable choice until proven otherwise. Even for the simplest of equations? A decent vendor-supplied implementation will include error checking that you otherwise would need to implement yourself, so yes. Also, given the oddities of floating point, a decent vendor-supplied implementation is likely to work successfully on all the corner cases where floats act bizarrely, or at least fail less disastrously than a naive implementation will. Third, it's very easy to use the wrong formula, especially for something like the Hann window function which is known by two different names and is commonly expressed as three different versions, two of which fail for a window width of 1. http://en.wikipedia.org/wiki/Window_function#Hann_window http://en.wikipedia.org/wiki/Hann_function http://mathworld.wolfram.com/HanningFunction.html And finally, no matter how simple the equation, why re-invent the wheel? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
PyPI upload documentation
Dear all: I'm trying to upload documentation to the PyPI site for a project I'm working on (there's a new feature on the PyPI site that allows admins of projects to upload a zip file of the pages of documentation.) If you have admin access to a PyPI project, you can see this on the admin page for that project, at the bottom. However, it's failing do to what appears to be a permissions error. When I press Upload documentation, I get the following error: Forbidden You don't have permission to access /tabular/ on this server. -- Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.3 Server at packages.python.org Port 80 If anyone could clue me into what's going wrong, that would be great. I know that this list might not be the right thing to write to -- I tried writing to the python.org webmester, but got only the automated reply. If there's a more appropriate list that I should write to instead, I'd be happy to learn of it. Thanks, Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess + python-daemon - bug/problem?
Sewar xsew...@gmail.com writes: I looked at other daemon libraries and snippets, it's clearly the bug is in subprocess not python-daemon. Then I found Python bug #1731717 which discusses it. Thank you very much! I'm glad to see this is a known issue and that some investigation has already been done. (It's a bit depressing that the bug is over two years old, though.) I wish my project was opensource so I can post more specific test cases. Can you make a small, complete test case that shows the problem? You could then post that to the bug report, since it seems they are currently without a good test case for this bug in Python 2.6. (Discussing the details further in this thread would be counter-productive; the discussion should go to the bug report.) Thanks again for finding this! -- \ “I was sleeping the other night, alone, thanks to the | `\ exterminator.” —Emo Philips | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Distutils - can user designate install directory for windows installer?
On 9/09/2009 1:57 AM, Timothy W. Grove wrote: I have successfully built a windows installer for my python program using distutils, (python setup.py bdist_wininst), but is there a way to do it that will allow a user ('user' == 'boss', in this case!) to designate the installation directory, rather than being forced to install into /Python/Lib/site-packages ? Thanks for any help. bdist_wininst is for packaging python modules or packages and so depends on Python itself being installed. As a result, it only installs into where Python libs and modules are generally installed. It sounds like you are looking for something to create a stand-alone version of your program - in that case you are probably looking for py2exe to create the application itself, and something like Inno or NSYS to create an installer which allows the user to specify where they want it installed and doesn't depend on Python already being installed. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
would you expect the B class to have a copy of the foo method? Sorta. I would expect B to have a copy of the foo attribute, which then refers to the same method as A.foo. So the method itself will be be copied, but its address stored separately in A.foo and B.foo. -- http://mail.python.org/mailman/listinfo/python-list
Re: start default application for read a pdf from python
On Tue, 2009-09-08 at 22:22 +0200, Angelo Ballabio wrote: My problem is a way to run a default application to read and show a pdf file from unix or windows, i have a mixed ambient in the office, so I am try to find a way to start a application to show this pdf file I generate whith reportlab. The (most) portable way to do so in Linux (not necessarily Unix) is to use the xdg-open command. Ex, subprocess.Popen(['xdg-open', 'my-document.pdf']) If you want cross-platform between Linux/Windows, then it's advisable to write a wrapper function that checks the value of sys.platform and and acts accordingly. -a -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Sep 8, 4:50 pm, HPJ henrypija...@gmail.com wrote: would you expect the B class to have a copy of the foo method? Sorta. I would expect B to have a copy of the foo attribute, which then refers to the same method as A.foo. So the method itself will be be copied, but its address stored separately in A.foo and B.foo. No, I'm afraid not. Here is what happens. Conceptually, Python checks for the presence of B.foo, and if it's not there it checks for foo's presence in the base classes. (In actuality Python premaps attributes to the approprirate base class, so only two dict lookups are necessary.) Python is a very dynamic langauge which allows you to modify class objects at runtime. So if you inherit from a class, then later modify that class, what should happen? class A(object): foo = 1 class B(A): pass A.foo = 2 print B.foo # what should this print, 1 or 2? You could argue that copying class attributes (so that B.foo would be 1) is a reasonable way to do inheritance, but IMO the referencing attributes in base classes reflects the underlying concept of inheritance better. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Math Notations, Computer Languages, and the “F orm” in Formalism
Musatov Search for Math Notations, Computer Languages, and the “Form ” in Formalism (lacks links) - Math Notations, Computer Languages, and the “Form” in Formalism Xah Lee, 2009-08-31 This page is a collection of essays and expositions on the subjects of nomenclature and notations in math and computer languages, in the context of facilitating human communication and ... Aug 31 by Xah Lee - 4 messages - 3 authors Math Notations, Computer Languages, and the “ Form” in Formalism Aatu Koskensilta aatu.koskensi...@uta.fi sci math Xah Lee xah...@gmail.com writes: • In computer algebra or theorem proving systems, they are intimately tied to the math philosophies of formalism and logicism. In a sense, formalism and logicism today are tied together as a single subject, and using computer ... Aug 31 by Aatu Koskensilta - 4 messages - 3 authors This Week's Finds in Mathematical Physics (Week 279) To see this, note that any guy in h_2(K) has this form: A = t+xy y* tx where t and x are real elements of K, and y is an arbitrary element. They formulated a supersymmetric model in 6 dimensions using the quaternions, and speculated about a similar formalism in 10 dimensions using the octonions: 6) Taichiro ... Sep 6 by Androcles - 4 messages - 3 authors Math Notations, Computer Languages, and the “ Form” in Formalism Aatu Koskensilta aatu.koskensi...@uta.fi sci math David C Ullrich dullr...@sprynet.com writes: Nonsense, surely. Pure nonsense, no doubt. But are you really certain that there's no nonsense out there that's even more pure? Not really. I'm just winging it. -- Aatu Koskensilta (aatu.koskensi...@uta.fi) Wovon mann ... Sep 1 by Aatu Koskensilta - 4 messages - 3 authors Math Notations, Computer Languages, and the “Form” in Formalism David C Ullrich dullr...@sprynet.com sci math On Mon, 31 Aug 2009 17:12:20 +0300, Aatu Koskensilta wrote: Xah Lee xah...@gmail.com writes: • In computer algebra or theorem proving systems, they are intimately tied to the math philosophies of formalism and logicism. In a sense, formalism and logicism today are ... Aug 31 by David C Ullrich - 4 messages - 3 authors fortunatus wrote: On Sep 7, 3:06 pm, Xah Lee xah...@gmail.com wrote: ... • systems for displaying math, such as TeX, Mathematica, MathML, should be unified as part of the computer language's syntax. ... ☄ to that end you might be interested in Fortress at Sun: http://projectfortress.sun.com/Projects/Community http://research.sun.com/projects/plrg/fortress.pdf http://research.sun.com/spotlight/2007/2007-01-10_fortress.html Math Forum Discussions - sci.math.*Form in Formalism. David C. Ullrich. sci.math. 8/31/09. 1 ... subnazi musatov decides what's good for all --with no one's permission. adamk. sci.math ...www.mathforum.com/kb/forumcategory.jspa? categoryID=16start=45 Discussions - sci.math | Google GroupsMusatov (3 authors) 3:18am. Heavy water is water nonetheless. 67 new of 67 ... Math Notations, Computer Languages, and the Form in Formalism. 2 new of 2 ...groups.google.fm/group/sci.math/topics?gvc=2hl=en Discussions - sci.math | Google GroupsBy Musatov - 6:27pm - 5 new of 5 messages ... Math Notations, Computer Languages, and the Form in Formalism ... Languages, and the Form in Formalism ...groups.google.co.zw/group/sci.math/topics? start=10hl=ensa=N Discussions - sci.math | Google GroupsMath Notations, Computer Languages, and the Form in Formalism. 3 new of 3 - Sep 1 ... subnazi musatov decides what's good for all --with no one's permission ...groups.google.jo/group/sci.math/topics? hl=enstart= Sotheby's - Auctions - Calendar - Modern and Contemporary Russian Art... accusations of formalism (which the state defined as the focus on the formal ... 48 he took some drawing classes in the art studio led by S. N. Ivashev-Musatov. ...sothebys.com/app/ live/lot/LotDetail.jsp?...live_lot_id=24 Seismic Wave Field in the Vicinity of Caustics and Higher-Order Travel ...In this section we shall briefly discuss the main formalism (some details can be ... and the quadratic form in (9') is sufficient to describe the wave ...www.math.purdue.edu/~aduchkov/papers/duch_Studia_03.pdf Perturbative QCD Analysis of the Nucleon's Pauli Form Factor F... sophisticated formalism has ... Sudakov form factor in regulating possible end-point. singularities in the ... [31] I. Musatov and A. Radyushkin, Phys. ...www.jlab.org/~riordan/papers/e092003 Discussions - sci.math | Google GroupsMath Notations, Computer Languages, and the Form in Formalism. 3 new of 3 - Sep 1 ... Korner: On the theorem of Ivasev-Musatov. II ...groups.google.com.ua/group/ sci.math/topics?hl=pt Discussions - sci.math | Google GroupsMath Notations, Computer Languages, and the Form in Formalism. 3 new of 3 - Aug 31 ... Korner: On the theorem of Ivasev-Musatov. II ...groups.google.gm/group/sci.math/topics?tsc=21234567 -- http://mail.python.org/mailman/listinfo/python-list
a question about numpy
hello, i want to ask a question about numpy. i know how to select a submatrix using the slice object in numpy. But how can i select a submatrix A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers ) The submatrix must share data memory with original matrix. Any one help? thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On 9 Sep, 00:24, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: A decent vendor-supplied implementation will include error checking that you otherwise would need to implement yourself, so yes. Not for code like this: import numpy as np n = np.arange(101) w = 0.5*(1.0-np.cos(2*np.pi*n/(100.))) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to refer to data files without hardcoding paths?
On Mon 07 Sep 2009 10:57:01 PM EDT, Gabriel Genellina wrote: I prefer to use pkgutil.get_data(packagename, resourcename) because it can handle those cases too. I didn't know about pkgutil until. I thought I had to use setuptools to do that kind of stuff. Thanks! Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
TBK rrezen...@gmail.com wrote in message news:b073f805-f8ce-49b3-b2d4-3d29bd97a...@j4g2000yqa.googlegroups.com... *snip* Download *snip URL* Free videos high resolution photos and much more. You know what to do! Free Downloads! Sold! Thanks everyone. spam If you feel the need to respond to a spam like this, please snip out any URLs or email addresses used by the spammers -- otherwise all you're doing is giving the spammer more advertising. -- Steve Lord sl...@mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ -- http://mail.python.org/mailman/listinfo/python-list
Re: a question about numpy
On 9 Sep, 03:45, hi_roger rechardc...@gmail.com wrote: hello, i want to ask a question about numpy. i know how to select a submatrix using the slice object in numpy. But how can i select a submatrix A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers ) The submatrix must share data memory with original matrix. So the only way to do this is to make an ndarray subclass that overloads __getitem__, __setitem__, and __iter__, and takes care of the mapping into A. Thus you get a double indirection. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
Conceptually, Python checks for the presence of B.foo, and if it's not there it checks for foo's presence in the base classes. Yes, I have no problem believing you guys that this is what Python does. Still, my question remains about where in the Language Reference this is specified. And if the answer is nowhere, than the LR needs to be amended, for obviously the way inheritance is done is no small matter and its understanding should not be left to the user's own intuition. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On 9/09/2009 1:51 PM, HPJ wrote: Conceptually, Python checks for the presence of B.foo, and if it's not there it checks for foo's presence in the base classes. Yes, I have no problem believing you guys that this is what Python does. Still, my question remains about where in the Language Reference this is specified. And if the answer is nowhere, than the LR needs to be amended, for obviously the way inheritance is done is no small matter and its understanding should not be left to the user's own intuition. http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes - search for 'method resolution order' for other hits in that document. HTH, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: SPAM
Steven Lord sl...@mathworks.com writes: [snip] If you feel the need to respond to a spam like this, please snip out any URLs or email addresses used by the spammers -- otherwise all you're doing is giving the spammer more advertising. Better yet, if you feel the need to respond to a spam, step away from the keyboard until the feeling passes. -- Keith Thompson (The_Other_Keith) ks...@mib.org http://www.ghoti.net/~kst Nokia We must do something. This is something. Therefore, we must do this. -- Antony Jay and Jonathan Lynn, Yes Minister -- http://mail.python.org/mailman/listinfo/python-list