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 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 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 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 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 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 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 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 æ¾å°èªå·±çä¸ç天 : > 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 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 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 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(r"FTPHOST", 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 wrote: > On 8 Sep, 13:36, Pierre 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(r"FTPHOST", 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(r"FTPHOST: (.*)", 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 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(r"FTPHOST", 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: ', and tell me what 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" 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(r"FTPHOST", 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 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(r"FTPHOST", 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(r"FTPHOST: (.*)", 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" wrote: > "Martin" 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(r"FTPHOST", 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" 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(r"FTPHOST", 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 wrote: > On Sep 8, 9:55 am, "Mart." wrote: > > > > > > > On Sep 8, 2:16 pm, "Andreas Tawn" 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(r"FTPHOST", 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" 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(r"FTPHOST", 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 wrote: > Mart. wrote: > > On Sep 8, 3:14 pm, "Andreas Tawn" 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(r"FTPHOST", 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(r"MOD\.\.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(r"FTPHOST", 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" 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(r"FTPHOST", 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: 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', 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 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." wrote: > On Sep 8, 2:16 pm, "Andreas Tawn" 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(r"FTPHOST", 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 Kaliszewski wrote: > 08-09-2009 o 02:15:10 Steven D'Aprano 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(r"FTPHOST", 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 wrote: Mart. wrote: On Sep 8, 3:14 pm, "Andreas Tawn" 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(r"FTPHOST", 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(r"MOD\.\.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: MOD13A2.A2007033.h
Re: Extracting patterns after matching a regex
On Sep 8, 10:27 am, pdpi wrote: > On Sep 8, 3:21 pm, nn wrote: > > > > > On Sep 8, 9:55 am, "Mart." wrote: > > > > On Sep 8, 2:16 pm, "Andreas Tawn" 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(r"FTPHOST", 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." wrote: > On Sep 8, 3:21 pm, nn wrote: > > > > > On Sep 8, 9:55 am, "Mart." wrote: > > > > On Sep 8, 2:16 pm, "Andreas Tawn" 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(r"FTPHOST", 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 wrote: > Mart. wrote: > > > > 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', > > > > 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 wrote: > On Sep 8, 11:19 am, Dave Angel wrote: > > > > > Mart. wrote: > > > > > > 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', > > > > > > 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 > >> > >> 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 th
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 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 wrote: > Mart. wrote: > > On Sep 8, 3:53 pm, MRAB wrote: > >> Mart. wrote: > >>> On Sep 8, 3:14 pm, "Andreas Tawn" 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(r"FTPHOST", 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(r"MOD\.\.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
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 wrote: > On Sep 8, 9:55 am, "Mart." wrote: > > > > > On Sep 8, 2:16 pm, "Andreas Tawn" 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(r"FTPHOST", 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 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 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 wrote: > Maggie wrote: > > On Sep 8, 11:39 am, MRAB 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 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
start default application for read a pdf from python
I try to start a default application for reading a pdf file inside the python script. I try os.startfile(name,option) but say me startfile not implemented there are some system to start for example acrobar or okular from the script with a name of pdf file? thenks Angelo -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
On Sep 8, 3:29 pm, 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! --- was trying to plug in the sum for the loop..but for some reason it doesnt want to work -- #!/usr/bin/python import os.path #name of output file filename = "OUTPUT.txt" #open the file formisano = open ("test.txt", "rU") #read in all the data into a list readData = formisano.readlines() sum = 0 count = 0 FILE = open(filename, "w") for item in readData: count = count + 1 sum = sum + (int(item) * int(item)) tmp_string = str(count) + ' ' + item + ''+ sum print >> FILE, tmp_string, else: print 'The loop is finito' -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Tue, 8 Sep 2009 11:12:18 -0700 (PDT) sturlamolden wrote: > On 8 Sep, 15:08, pdpi 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? > Yes. It might be implemented in some clever way that you didn't think of, and thereby work much faster or more precisely than your own implementation. Or it could come with a whole library that might help you with other tasks related to what you're doing. And just a matter of personal opinion: I think the phrase "you are not competent to do any scientific programming" was overly harsh. Not that the general sentiment of "this is actually easy" shouldn't be expressed at all, but bringing in estimations of competence based on two sentences might hurt feelings that were in no need to be hurt. /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Re: Math Notations, Computer Languages, and the “F orm” in Formalism
On Sep 7, 3:06 pm, Xah Lee 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
On Sep 8, 4:17 pm, MRAB wrote: > Maggie wrote: > > On Sep 8, 3:29 pm, 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! > > > --- > > > was trying to plug in the sum for the loop..but for some reason it > > doesnt want to work -- > > Read the traceback. > > > > > #!/usr/bin/python > > > import os.path > > > #name of output file > > filename = "OUTPUT.txt" > > > #open the file > > formisano = open ("test.txt", "rU") > > > #read in all the data into a list > > readData = formisano.readlines() > > > sum = 0 > > Try to avoid using the names of builtin functions and classes, in this > case 'sum'. > > > count = 0 > > > FILE = open(filename, "w") > > > for item in readData: > > > count = count + 1 > > sum = sum + (int(item) * int(item)) > > tmp_string = str(count) + ' ' + item + ' '+ sum > > You can't add a number to a string; a number is a number and a string is > a string! :-) > > tmp_string = str(count) + ' ' + item + ' '+ str(sum) > > > print >> FILE, tmp_string, > > > else: > > print 'The loop is finito' > > I saw my mistake...now it is telling me the following -- Traceback (most recent call last): File "formisano_count.py", line 22, in running_sum = running_sum + (int(item) * int(item)) ValueError: invalid literal for int() with base 10: '' .. not sure what exactly i am doing wrong! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
Maggie wrote: On Sep 8, 4:17 pm, MRAB wrote: Maggie wrote: On Sep 8, 3:29 pm, 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! --- was trying to plug in the sum for the loop..but for some reason it doesnt want to work -- Read the traceback. #!/usr/bin/python import os.path #name of output file filename = "OUTPUT.txt" #open the file formisano = open ("test.txt", "rU") #read in all the data into a list readData = formisano.readlines() sum = 0 Try to avoid using the names of builtin functions and classes, in this case 'sum'. count = 0 FILE = open(filename, "w") for item in readData: count = count + 1 sum = sum + (int(item) * int(item)) tmp_string = str(count) + ' ' + item + ''+ sum You can't add a number to a string; a number is a number and a string is a string! :-) tmp_string = str(count) + '' + item + ''+ str(sum) print >> FILE, tmp_string, else: print 'The loop is finito' I saw my mistake...now it is telling me the following -- Traceback (most recent call last): File "formisano_count.py", line 22, in running_sum = running_sum + (int(item) * int(item)) ValueError: invalid literal for int() with base 10: '' .. not sure what exactly i am doing wrong! You're trying to convert an empty string into an integer. Does the file contain a blank line? -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
On Tue, 8 Sep 2009 12:49:23 -0700 (PDT) Maggie wrote: > On Sep 8, 3:29 pm, 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: > > As was suggested elsewhere: use enumerate here: for count, item in enumerate(readData): tmp_string = str(count) + ' ' + item > > 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! > > --- > > was trying to plug in the sum for the loop..but for some reason it > doesnt want to work -- > "For some reason it doesnt want to work" is not a very useful description. What do you expect? And more importantly: What do you actually get? Output? Error message? Anyway, I'll fire up my magic crystal ball. Let's see what I can do. > #!/usr/bin/python > > import os.path > > #name of output file > filename = "OUTPUT.txt" > > #open the file > formisano = open ("test.txt", "rU") > > #read in all the data into a list > readData = formisano.readlines() > NB: You don't need to do this. Just iterate over formisano. A file is its own iterator. > sum = 0 'sum' is a builtin function. With the above statement you're shadowing it. While it doesn't break anything here, it is generally considered bad practice to shadow builtins, unless you want to purposefully shadow it with something more useful than the builtin version. Just saying. > count = 0 > > FILE = open(filename, "w") > I'm probably going overboard with suggestions now, but from Python 2.5 onwards you can use the 'with' statement to work on files. If nothing else, it frees you from having to close the file manually. And it is 'pretty damn cool'™ too. with open(filename, "w") as FILE: # Do your usual stuff here. > for item in readData: > >count = count + 1 >sum = sum + (int(item) * int(item)) >tmp_string = str(count) + '' + item + ''+ sum >print >> FILE, tmp_string, > > else: >print 'The loop is finito' It works for me (after correcting your 'typo'). Was that the problem? Or is there anything else left? /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-list
Invitation to connect on LinkedIn
LinkedIn Manzur Ahmed requested to add you as a connection on LinkedIn: -- Jaime, I'd like to add you to my professional network on LinkedIn. - Manzur Accept invitation from Manzur Ahmed http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I316895250_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvc3kOdjAUdz4PiiZHemgVd6lkq2YSejkNcj8RczsLrCBxbOYWrSlI/EML_comm_afe/ View invitation from Manzur Ahmed http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I316895250_3/0PnP0RczkVe3oNcQALqnpPbOYWrSlI/svi/ -- Why might connecting with Manzur Ahmed be a good idea? Have a question? Manzur Ahmed's network will probably have an answer: You can use LinkedIn Answers to distribute your professional questions to Manzur Ahmed and your extended network. You can get high-quality answers from experienced professionals. http://www.linkedin.com/e/ash/inv19_ayn/ -- (c) 2009, LinkedIn Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: start default application for read a pdf from python
On 2009-09-08, Angelo Ballabio wrote: > I try to start a default application for reading a pdf file > inside the python script. > > I try > > os.startfile(name,option) but say me startfile not implemented Are you _sure_ it says startfile not implemented? Or does it say this: >>> os.startfile("foo.bar") Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'startfile' [You'll always get better answers if your questions are specific and precise -- whenever possible, you should paste in actual code and error messages.] > there are some system to start for example acrobar or okular > from the script with a name of pdf file? Google tells me that Okular is something for KDE. That implies that you're running Linux or Unix? [When asking a question, you also need to provide OS, Python version, etc.] If you are running Linux/Unix, then I suspect the answer to your problem can be seen in the fine documentation at http://docs.python.org/library/os.html#process-management os.startfile(path[, operation]) Start a file with its associated application. [...] Availability: Windows. If you want to do something similar on Unix/Linux, you'll probably need to call some desktop-specific. Googling for python+startfile+linux found me these links: http://mail.python.org/pipermail/python-list/2003-March/193897.html http://lists.freebsd.org/pipermail/freebsd-python/2004-August/000138.html -- Grant Edwards grante Yow! FOOLED you! Absorb at EGO SHATTERING impulse visi.comrays, polyester poltroon!! -- http://mail.python.org/mailman/listinfo/python-list
Re: simple string question
D'Arcy J.M. Cain wrote: On Mon, 7 Sep 2009 15:29:23 +1000 "jwither" wrote: Given a string (read from a file) which contains raw escape sequences, (specifically, slash n), what is the best way to convert that to a parsed string, where the escape sequence has been replaced (specifically, by a NEWLINE token)? I don't know what your actual requirement is but maybe this fits: exec("print '%s'" % x) Lots of fun when preceded by: x = "'; sys.exit(); print 'b" or far nastier things. Exec is the same level of dangerous as eval. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
On Tue, 8 Sep 2009 13:23:43 -0700 (PDT) Maggie wrote: > On Sep 8, 4:17 pm, MRAB wrote: > [snip] > I saw my mistake...now it is telling me the following -- > > Traceback (most recent call last): > File "formisano_count.py", line 22, in > running_sum = running_sum + (int(item) * int(item)) > ValueError: invalid literal for int() with base 10: '' > .. > not sure what exactly i am doing wrong! What this error means is that the int() constructor is passed an empty string (''). So there is probably an empty line in your input file. You can catch these with a simple if item: # usual code goes here /W -- INVALID? DE! -- 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: Help with cumulative sum
On Sep 8, 4:05 pm, "J. Cliff Dyer" wrote: > 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! > > i WISH it would be homework! that way i can ask my professor and be done with it. i need this code to pre-process fMRI data for my research. and given i have never done python..i am at a loss...thanks for your help i will try this right now.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
On Sep 8, 3:49 pm, Maggie wrote: > On Sep 8, 3:29 pm, 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! > > --- > > was trying to plug in the sum for the loop..but for some reason it > doesnt want to work -- > > #!/usr/bin/python > > import os.path > > #name of output file > filename = "OUTPUT.txt" > > #open the file > formisano = open ("test.txt", "rU") > > #read in all the data into a list > readData = formisano.readlines() > > sum = 0 > count = 0 > > FILE = open(filename, "w") > > for item in readData: > > count = count + 1 > sum = sum + (int(item) * int(item)) > tmp_string = str(count) + ' ' + item + ' '+ sum > print >> FILE, tmp_string, > > else: > print 'The loop is finito' sorry...typo in code: tmp_string = str(count) + ' ' + str(sum) + ' ' + item any suggestions are welcome -- http://mail.python.org/mailman/listinfo/python-list
Re: start default application for read a pdf from python
Sorry to not be very specific 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. actualy I write a file in a directory and then I have to open the directory find a file and open it, I try to find a way to do this automatic, in this way then they only have to close the windows. sorry I do not see before is only for windows, so this means under unix system I cant to use. thenks for the suggestion Angelo Grant Edwards ha scritto: On 2009-09-08, Angelo Ballabio wrote: I try to start a default application for reading a pdf file inside the python script. I try os.startfile(name,option) but say me startfile not implemented Are you _sure_ it says startfile not implemented? Or does it say this: >>> os.startfile("foo.bar") Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'startfile' -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
> I could, but I will let you read and find what it says about class > attributes. You think I would have asked specifically about the Language Reference if I hadn't read it and failed to find what I was looking for? The closest thing I was able to find was section 3.2. "The standard type hierarchy", subsection "Custom classes", where it says: "When the attribute name is not found [in its namespace dictionary], the attribute search continues in the base classes. This search of the base classes uses the C3 method resolution order [...]" That tells me how the lookup works, which I already knew. But it doesn't tell me what happens when a class is inherited. Now, one could argue if the attributes were copied, there would be no need for a lookup in the base classes, so derivatively it says that's not the case. To this I would say yes, there still would because after they've been copied through inheritance, attributes can still be removed via "del". Anyway, this passage, which is the only one I could find, doesn't provide a direct and conclusive answer to my question. -- http://mail.python.org/mailman/listinfo/python-list
[ANNC] pybotwar-0.6
pybotwar is a fun and educational game where players create computer programs to control simulated robots to compete in a battle arena. http://pybotwar.googlecode.com/ pybotwar uses pybox2d for the physical simulation, and uses either pygame and pygsear or PyQt4 for the visualization. pybotwar is released under GPLv3. Changes in pybotwar-0.6: - expanded README file - add robot program template - new (optional) PyQt4 interface - track amount of damage caused by each robot - warn if database version is out of date - add position sensor and example robot to test it out - new robot and turret images - fix possibility of 2 robots spawning at same position - add a maximum time for match - fix crash from too many files open during long tournament - catch and log robot errors during module compilation - add cannon overheat sensor - add cannon loaded sensor - reload penalty for firing while cannon overheated (defaults to 0) - reload penalty for firing before cannon is loaded (defaults to 0) - use both tangent and normal impulse to determine collision damage - fix crash saving stats when using multiple copies of the same robot _ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
On Sep 8, 2:14 am, PythonAB wrote: > 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? > You can use any email you want to join the wxPython list, just as you can do so with the Python list. You just send an email to wxPython- users+subscr...@googlegroups.com from whatever email address you want to use. And Robin Dunn sent out multiple notices about the switch and why he was doing it about a month before the switch. --- Mike Driscoll Blog: http://blog.pythonlibrary.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with cumulative sum
Maggie wrote: On Sep 8, 3:29 pm, 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! --- was trying to plug in the sum for the loop..but for some reason it doesnt want to work -- Read the traceback. #!/usr/bin/python import os.path #name of output file filename = "OUTPUT.txt" #open the file formisano = open ("test.txt", "rU") #read in all the data into a list readData = formisano.readlines() sum = 0 Try to avoid using the names of builtin functions and classes, in this case 'sum'. count = 0 FILE = open(filename, "w") for item in readData: count = count + 1 sum = sum + (int(item) * int(item)) tmp_string = str(count) + ' ' + item + ''+ sum You can't add a number to a string; a number is a number and a string is a string! :-) tmp_string = str(count) + ' ' + item + ''+ str(sum) print >> FILE, tmp_string, else: print 'The loop is finito' -- http://mail.python.org/mailman/listinfo/python-list
make test curses on 3.1.1
It appears that 3.1.1 built pretty cleanly on my SUSE 11 box. However, the curses test appears to fail. I see this message on the www.python.org site many times when searching Google, but the contents appears to have been removed. http://www.google.com/search?hl=en&as_q=test+test_curses+crashed+--+% 3Cclass+%27io.UnsupportedOperation%27% 3E&as_epq=&as_oq=&as_eq=&num=10&lr=&as_filetype=&ft=i&as_sitesearch=&as_qdr=all&as_rights=&as_occt=any&cr=&as_nlo=&as_nhi=&safe=images Any suggestions? test test_curses crashed -- : fileno ./configure --enable-ipv6 --enable-big-digits \ --with-signal-module --with-threads make EXTRATESTOPS='-u all' make test -- http://mail.python.org/mailman/listinfo/python-list
Re: The future of Python immutability
On Tue, 08 Sep 2009 11:23:05 -0700, Daniel Fetchinson wrote: >> 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 .. In general, Ruby was significantly slower than Python "most of the time", although my recollection was wrong about it being an order of magnitude difference -- it was more like a factor of 3-6 depending on the specific benchmark being tested. This was for Ruby 1.8, Ruby 1.9 included some significant speedups, including tail-optimization which makes it about three times as fast as Python 2.5 for tail-recursive functions. Of course there's a lot of hand-waving in the above. Language implementations vary in their performance for specific pieces of code -- it's invalid to conclude that every single Ruby script will be exactly 3 times faster than every single Python script. But one can argue that Ruby 1.8 was, in general, at least three times slower than Python 2.5 comparing equivalent pieces of code. There's nothing controversial or strange over the claim that a well- written (but not heavily optimized) C program will be much faster than the equivalent Python program, which in turn will be faster than the equivalent PHP program. Nobody is surprised to learn that Numpy's C implementation of some function will almost certainly out-perform the same function written in pure Python. It's easy to oversell the idea that "language X is faster than language Y", but that's not what I'm doing. I'm asking, all else being equal, how does the speed of Matlab compare to the speed of Numpy? >>, 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? Go point -- of course you're right, and I was sloppy. I meant "the speed of the specific implementation". -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Tue, 08 Sep 2009 04:36:19 -0700, 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. Inherit does not mean copy. What makes you think it does? Given the following: class A(object): def foo(self): return "foo" class B(A): pass would you expect the B class to have a copy of the foo method? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: recursive decorator
Michele Simionato wrote: [snip] Yes, it is portable. BTW, here is what you want to do (requires decorator-3.1.2): from decorator import FunctionMaker def bindfunc(f): name = f.__name__ signature = ', '.join(FunctionMaker(f).args[1:]) # skip first arg return FunctionMaker.create( '%s(%s)' % (name, signature), 'return _func_(%s, %s)' % (name, signature), dict(_func_=f), defaults=f.func_defaults, doc=f.__doc__, module=f.__module__) I figured there must be an easy way using your module. Here is what I came up with *not* using the module -- this whole thing was definitely a mind-stretching exercise. Many thanks for your decorator routines -- no way could I have gotten this far without them to guide me! def bind_func(func): name = func.__name__ argspec = inspect.getargspec(func) self = argspec[0][0] newargspec = (argspec[0][1:], ) + argspec[1:] signature = inspect.formatargspec( \ formatvalue=lambda val: "", *newargspec)[1:-1] new_func = 'def _wrapper_(%(signature)s):\n' \ 'return %(self)s(_wrapper_, %(signature)s)' % \ {'signature':signature, 'self':'old_func'} evaldict = {'old_func':func} exec new_func in evaldict wrapped = evaldict['_wrapper_'] wrapped.__name__ = name wrapped.__doc__ = func.__doc__ wrapped.__module__ = func.__module__ wrapped.__dict__ = func.__dict__ wrapped.func_defaults = func.func_defaults return wrapped ~Ethan~ -- 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 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