Re: How to convert a list of strings into a list of variables
noydb wrote: How would you convert a list of strings into a list of variables using the same name of the strings? So, [red, one, maple] into [red, one, maple] Thanks for any help! red=a string one=another string maple=a file path old=[red, one, maple] newList=map(eval, old) -- http://mail.python.org/mailman/listinfo/python-list
OT
I'll be 59 in a couple of months. -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: OT
Daniel Fetchinson, 19.08.2011 10:17: I'll be 59 in a couple of months. That's actually more on topic for one of the alt.test newsgroups. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: List spam
On Thursday, August 18, 2011 10:23:49 PM Steven D'Aprano did opine: gene heskett wrote: But I'd like to return the question. What's wrong with nntp? The sheer volume of traffic eats 99% of an ISP's bandwidth. I doubt that very much, particularly if the ISP drops the binary newsgroups. [...] It's not like you have to install a second Interweb tube just for bittorrent, or that bittorrent packets cost more than HTTP packets. Fer fecks sake, the ISP doesn't even have to run a bittorrent server! It's practically free money to the ISP, packets go in, packets go out, they don't have to do a bloody thing with them. Except pay for the bandwidth to get the bytes into their system. Now, an ISP might not have the bandwidth to supply all the needs of their customers, that's a separate issue. Yes it is, which is why Hughs has a bandwidth limit cap they lift in the middle of the night when overall traffic is zilch. The bird(s) only have so much bandwidth and it costs tens of millions to 'lay another fiber' when its 22,300 miles up. OTOH, they have to pay for that bandwidth 24/7, so if they can move the relatively few high traffic folks usage to 3-5 AM, they can service more people watching old black and white John Holmes clips at 9-11pm. ;-) But complaining that the problem is specifically because they use bittorrent, as if it would disappear if they changed to HTTP, is bogus. Agreed, that's 100% a red herring. Cheers, gene -- There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. -Ed Howdershelt (Author) Q: How many mathematicians does it take to screw in a light bulb? A: One. He gives it to six Californians, thereby reducing the problem to the earlier joke. -- http://mail.python.org/mailman/listinfo/python-list
Re: List spam
On Thursday, August 18, 2011 12:16:50 PM Jason Staudenmayer did opine: [...] I do know it is ironic that I forgot to stop the footer for the one reply. It's not my choice to add it but I was able to find a way around that work policy for list emails. I'm a strong opponent of dropping any email with a stupid footer spam. Jason I'm a strong proponent of dropping any email with a stupid footer spam. There, I fixed it for you. ;-) Sorry, couldn't resist, Jason. At nearly 77, I am a firm believer that one can grow old without growing up. ;p) Cheers, gene -- There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. -Ed Howdershelt (Author) Renning's Maxim: Man is the highest animal. Man does the classifying. -- http://mail.python.org/mailman/listinfo/python-list
Re: Word Perfect integration
:P Personally, I use LaTeX, which fits all my requirements. On Fri, Aug 19, 2011 at 5:24 AM, Ethan Furman et...@stoneleaf.us wrote: Alec Taylor wrote: wow, people still use WordPerfect? Them's fightin' words right there! :) Yes, we still use Word Perfect, and will as long as it is available. The ability to see the codes in use (bold, margins, columns, etc) has so far been unequaled in anything else I have looked at. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Word Perfect integration
On Aug 18, 7:00 pm, Ethan Furman et...@stoneleaf.us wrote: I have WordPerfect v13 which we are currently using for letter merges. I would like to automate this with Python instead of learning the WP Macro language. Does anyone have any pointers? paper letter or eletronic mail merger ? What you need is : - 1. write a template in WP with tag like NAME DATE ADDRESS - 2. make a database with the corresponding data - 3. replace tag by data from a database, and generate a new WP document - 4. print all these ducument. 1 2 are not programming related 3. Should not be impossible, look at the wp binary file if you can find and replace the tag 4. More difficult: can you start a print job from a command line ? or put all file in a directory, then start WP and ask him to print all file in this directory or create print job and put them in a queue and hope WP will process the queue. Regards ~Ethan~ Alain -- http://mail.python.org/mailman/listinfo/python-list
Re: 'super' object has no attribute '__setitem__'
If you really want __setitem__ and not __setattr__, you should change the base class to 'dict'. Or 'import UserDict' and use that for the base class. On Aug 18, 2011 9:45 PM, luvspython srehtva...@gmail.com wrote: I'm using Python 2.7 and the code below fails at the 'super' statement in the __setitem__ function in the HistoryKeeper class. The error is: 'super' object has no attribute '_setitem__' Can anyone please tell me why and how to fix it? (I've googled endlessly and I don't see the problem.) [The code will seem silly as it is, because it's pared down to show the example. The goal is that multiple classes, like the Vehicle class below, will inherit HistoryKeeper. History keeper overloads __setitem__ and will eventually keep a running history every time an attribute of any of the inheriting classes is changed.] Thanks in advance class HistoryKeeper(object): def __init__(self, args): for arg, value in args.items(): if arg != 'self': self.__setitem__(arg, value) def __setitem__(self, item, value): super(HistoryKeeper, self).__setitem__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): args = locals() super(Vehicle, self).__init__(args) if __name__ == __main__: car = Vehicle('TAG123', 'FORD', 'Model A') print car.make -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a list of strings into a list of variables
In article 2ab25f69-6017-42a6-a7ef-c71bc2ee8...@l2g2000vbn.googlegroups.com, noydb jenn.du...@gmail.com wrote: How would you convert a list of strings into a list of variables using the same name of the strings? So, [red, one, maple] into [red, one, maple] Thanks for any help! I'm not sure what you're trying to do, but explore the dictionary returned by locals(). You can do something like: loc = locals() [loc[red], loc[one], loc[maple]] -- http://mail.python.org/mailman/listinfo/python-list
Execute script from ipython
Hi all, I have a script myscript.py located in /usr/local/bin on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Best regards, Johan -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
Hi Josh, thanks for the reply. I am no expert so please bear with me: I thought that the {32} was supposed to match the previous expression 32 times? So how can i have all matches accessible to me? matt On Thursday, August 18, 2011, Josh Benner wrote: On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk matze...@gmail.com wrote: Hi guys, thanks for the suggestions. I had tried the white space before as well (to no avail). So here is the expression i am using (based on suggestions), but still no success: instance_linetype_pattern_str =\ r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)' instance_linetype_pattern = re.compile(instance_linetype_pattern_str) results = instance_linetype_pattern.findall(line) print results: ; print results The match i get is: results: [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome description')] btw: The line to be matched (given below) is ONE line. There are no line breaks (even though my email client adds them). matt If a group matches multiple times, only the last match is accessible. The matches returned represent the inner groupings of the last match found. JB-) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert a list of strings into a list of variables
Thanks to all for your responses! Good lessons. I implemented something like what Jerry Hill suggested (dictionary), which works well for my purposes. The list of strings that is being passed into this code is also provided by something I wrote so I do trust what is being sent. Might use what AB suggested down the line, as tool expands. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
Hi Josh, thanks for the reply. I am no expert so please bear with me: I thought that the {32} was supposed to match the previous expression 32 times? So how can i have all matches accessible to me? $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 2.15e+01 2.199000e+01 : (instance: 0) : some description' import re re.findall(r\d\.\d+e\+\d+, data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.00e+01', '2.20e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.15e+01', '2.15e+01', '2.199000e+01'] -- http://mail.python.org/mailman/listinfo/python-list
How to make statements running in strictly sequential fashion like in an interactive shell
I have an instrument that has a RS232 type serial comm port and I need to connect to and control. I use Python 3.2 in Windows XP, plus pySerial module. I have a problem when I execute a script consisting of statements that open the comm port, configure it, write strings to and receive strings from it. Thoese strings aer either commands pertinent to the instrument (control) or responses from the instrument (response). When those statements are executed in a python interpreter interactively (at ), I get what I expect and the results are good and correct. However, when I execute the script, either being invoked within the interpreter or run file, I don’t get what I want. The statements in the script is the same as what I use in the interactive interpreter. Why do I get the strange behavior and how can I change the script to make it to behave like in interactive interpreter? --script--- def read(comport): wrt_str=b'movt 3000'+b'\r\n' ret_str=comport.write(wrt_str) wrt_str=b'scan'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines() #1 wrt_str=b'hllo'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines()#2 -- The problem is with the lines above with ###. In interactive mode, there is about 1 second delay at #1, and 9 seonds delay at #2. I get correct responses there. However, if I execute the script above, there is no delay at all and I get incorrect results (garbage). I set the read timeout to 0 in comm port set up, as comport.timeout=0 So the comport should be in blocking mode if it waits for the end of line or end of file. I tried many things, like exec (execfile in 2.7), but at no avail. I have an update to the original post I made a few days ago. I think I know what the problem is and want to know if anyone has a solution: After putting print and time.sleep(delay) after every statement, I found when the script is running, it appears going around the pyserial statement, such as comport.write(..) or comport.readlines(...) while the pyserial command is executing (appearing as waiting and busying doing some thing, you know serial port is slow). So for example, when I exec all statements in a python interactive shell, I am not able to type and run a new statement if the previous one is not returned. Let's ay, if comport.readlines() is not returning, I can't type and run the next comport.write(...) statemtn. However, in a script that is running, if the comport.readlines() is busy reading, the next statement is running, if the next statement happens to be a comport.write() which will abort the reading. Is there any way to force the python script to behave like running exactly sequentially? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print non-printable chars??
On 18 août, 22:44, coldpizza vri...@gmail.com wrote: ... In a web/html environment or in broken ascii-only consoles like the one on windows ... C:\Users\Jean-Michelecho 'Cet œuf de Lætitia coûte un €uro' 'Cet œuf de Lætitia coûte un €uro' C:\Users\Jean-Michelc:\Python27\python Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print 'Cet œuf de Lætitia coûte un €uro' Cet œuf de Lætitia coûte un €uro import sys u = unicode('Cet œuf de Lætitia coûte un €uro', sys.stdin.encoding) print u.encode(sys.stdout.encoding) Cet œuf de Lætitia coûte un €uro C:\Users\Jean-Michelc:\Python32\python Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print('Cet œuf de Lætitia coûte un €uro') Cet œuf de Lætitia coûte un €uro PS Cet œuf de Lætitia coûte un €uro - This Lætitia's egg costs one €uro' PS2 ñ does not require special attention. PS3 To the original question: This not a *coding* issue, it is a character *representation* question. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Execute script from ipython
On Fri, Aug 19, 2011 at 6:00 AM, Johan Ekh ekh.jo...@gmail.com wrote: Hi all, I have a script myscript.py located in /usr/local/bin on my linux box. I can execute it in ipython with run /usr/local/bin/myscript.py but not with run myscript.py even though /usr/local/bin is in my $PATH and in my $PYTHONPATH. What should I do to correct this? Given that %run takes a filename and not a module name, I doubt PYTHONPATH matters. ipython's docs for %run don't seem to indicate that a search of any kind is performed. So, I'd say you have to either pass a valid absolute or relative path to myscript.py, or run myscript.py from bash instead of ipython. Changing your script's shebang line to ipython might also work (haven't tried it myself). Or you could try patching ipython's run() function to add this search feature you desire. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
Hi, thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. anyway, thanks though matt On 8/19/2011 8:41 AM, Jason Friedman wrote: Hi Josh, thanks for the reply. I am no expert so please bear with me: I thought that the {32} was supposed to match the previous expression 32 times? So how can i have all matches accessible to me? $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 2.15e+01 2.199000e+01 : (instance: 0) : some description' import re re.findall(r\d\.\d+e\+\d+, data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.00e+01', '2.20e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.15e+01', '2.15e+01', '2.199000e+01'] -- http://mail.python.org/mailman/listinfo/python-list
Replacement for the shelve module?
Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an ls did not make sense, etc.). Thanks in advance for your suggestions. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On Fri, Aug 19, 2011 at 11:31 AM, Forafo San ppv.g...@gmail.com wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: For what you're doing, I would give PyTables a try. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On 19 août, 17:20, Matt Funk matze...@gmail.com wrote: Hi, thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. re is not always the right tool to be used. Without more precisions: s = '2.201000e+01 2.15e+01 2.15e+01\ ... : (instance: 0) : some description' s 2.201000e+01 2.15e+01 2.15e+01 : (instance: 0) : some description s[:s.find(':')] 2.201000e+01 2.15e+01 2.15e+01 s[:s.find(':')].split() ['2.201000e+01', '2.15e+01', '2.15e+01'] jmf -- http://mail.python.org/mailman/listinfo/python-list
HTML client sctript
Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically uses this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Thank you. - Yingjie -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On 19/08/11 17:31, Forafo San wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an ls did not make sense, etc.). Thanks in advance for your suggestions. Firstly, since when is shelve deprecated? Shouldn't there be a deprecation warning on http://docs.python.org/dev/library/shelve.html ? If you want to keep your current approach of having an object containing all the data for each symbol, you will have to think about how to serialise the data, as well as how to store the documents/objects individually. For the serialisation, you can use pickle (as shelve does) or JSON (probably better because it's easier to edit directly, and therefore easier to debug). To store these documents, you could use a huge pickle'd Python dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; this is what shelve uses), or simple the file system: one file per serialised object. Looking at your use case, however, I think what you really should use is a SQL database. SQLite is part of Python and will do the job nicely. Just use a single table with three columns: symbol, date, value. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
Matt Funk matze...@gmail.com writes: thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times a space followed by a number. Using Jason's regexp, you can build the regexp step by step: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31} % (number,number) There are better ways to build your regexp, but I think this one is convenient to answer your question. You still have to append what will match the end of the line. -- Alain. P/S: please do not top-post $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 2.15e+01 2.199000e+01 : (instance: 0) : some description' import re re.findall(r\d\.\d+e\+\d+, data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.00e+01', '2.20e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.15e+01', '2.15e+01', '2.199000e+01'] -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML client sctript
In mailman.224.1313769546.27778.python-l...@python.org Yingjie Lin yingjie@mssm.edu writes: Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically uses this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Mechanize seems like what you want. It's built on top of urllib2. http://wwwsearch.sourceforge.net/mechanize/ -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On Aug 19, 11:54 am, Thomas Jollans t...@jollybox.de wrote: On 19/08/11 17:31, Forafo San wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an ls did not make sense, etc.). Thanks in advance for your suggestions. Firstly, since when is shelve deprecated? Shouldn't there be a deprecation warning onhttp://docs.python.org/dev/library/shelve.html? If you want to keep your current approach of having an object containing all the data for each symbol, you will have to think about how to serialise the data, as well as how to store the documents/objects individually. For the serialisation, you can use pickle (as shelve does) or JSON (probably better because it's easier to edit directly, and therefore easier to debug). To store these documents, you could use a huge pickle'd Python dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2; this is what shelve uses), or simple the file system: one file per serialised object. Looking at your use case, however, I think what you really should use is a SQL database. SQLite is part of Python and will do the job nicely. Just use a single table with three columns: symbol, date, value. Thomas Sorry. There is no indication that shelve is deprecated. I was using it on a FreeBSD system and it turns out that the bsddb module is deprecated and confused it with the shelve module. Thanks Ken and Thomas for your suggestions -- I will play around with both and pick one. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML client sctript
On Fri, Aug 19, 2011 at 8:08 AM, Yingjie Lin yingjie@mssm.edu wrote: Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically uses this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any one suggest any Python modules, articles, tutorials, ect. that might be helpful? Selenium: http://seleniumhq.org/ Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Help on PyQt4 QProcess
Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal finished(int) of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x=started:print(x))# connect pro.connect(pro, SIGNAL(finished(int)), lambda x=finished:print(x)) pro.start('python',['hello.py'])# star hello.py program (contain print(hello world!)) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) I'm using Python 3.2 and PyQt 4.8.4 under winxp 32bit. best regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
You might check one of many binary encoders (like Avro, Thrift ...). The other option is to use a database, sqlite3 is pretty fast (if you schema is fixed). Otherwise you can look at some NoSQL ones (like MongoDB). -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On Friday, August 19, 2011, Alain Ketterlin wrote: Matt Funk matze...@gmail.com writes: thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times a space followed by a number. Using Jason's regexp, you can build the regexp step by step: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31} % (number,number) That didn't work either. Using the (modified (where the (.+) matches the end of the line)) expression as: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31}(.+) % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. thanks for all the help matt There are better ways to build your regexp, but I think this one is convenient to answer your question. You still have to append what will match the end of the line. -- Alain. P/S: please do not top-post $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. data '1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 2.15e+01 2.199000e+01 : (instance: 0) : some description' import re re.findall(r\d\.\d+e\+\d+, data) ['1.002000e+01', '2.037000e+01', '2.128000e+01', '1.908000e+01', '1.871000e+01', '1.914000e+01', '2.007000e+01', '1.664000e+01', '2.204000e+01', '2.109000e+01', '2.209000e+01', '2.376000e+01', '2.158000e+01', '2.177000e+01', '2.152000e+01', '2.267000e+01', '1.084000e+01', '1.671000e+01', '1.888000e+01', '1.854000e+01', '2.064000e+01', '2.00e+01', '2.20e+01', '2.139000e+01', '2.137000e+01', '2.178000e+01', '2.179000e+01', '2.123000e+01', '2.201000e+01', '2.15e+01', '2.15e+01', '2.199000e+01'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On 8/19/11 10:49 AM, Ken Watford wrote: On Fri, Aug 19, 2011 at 11:31 AM, Forafo Sanppv.g...@gmail.com wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: For what you're doing, I would give PyTables a try. For a few gigs of stock price data, this is what I use. Much better than SQLite for that amount of data. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on PyQt4 QProcess
On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes fuente...@gmail.com wrote: Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal finished(int) of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x=started:print(x))# connect pro.connect(pro, SIGNAL(finished(int)), lambda x=finished:print(x)) pro.start('python',['hello.py'])# star hello.py program (contain print(hello world!)) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) Yes it is, and your lambda slot is printing 0 which is the return code of the process. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On 19 août, 19:33, Matt Funk matze...@gmail.com wrote: The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. Seen on this list: And always keep this in mind: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' --Jamie Zawinski, comp.lang.emacs I proposed a solution which seems to corresponds to your problem if it were better formulated... jmf -- http://mail.python.org/mailman/listinfo/python-list
try... except with unknown error types
Hi Python users, I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't spell the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. - Yingjie -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML client sctript
Hi John and Chris, Thanks for the help. I looked at both and think that mechanize suits my needs better, since it simply needs a python script and doesn't depend on Firefox. Yingjie From: John Gordon gor...@panix.com Mechanize seems like what you want. It's built on top of urllib2.http://wwwsearch.sourceforge.net/mechanize/ From: Chris Rebert c...@rebertia.com Selenium:http://seleniumhq.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
In mailman.230.1313780957.27778.python-l...@python.org Yingjie Lin yingjie@mssm.edu writes: try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Have you imported urllib2 in your code? Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You can catch all exceptions by catching the base class Exception: try: some_method() except Exception, e: print some error happened, here is the explanation: print str(e) -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
On Friday 2011 August 19 12:09, Yingjie Lin wrote: Hi Python users, I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't spell the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You probably need to import urllib2 before you can use urllib2.HTTPError. Otherwise, you can try using the base class: except Exception, e: -- I have seen the future and I am not in it. -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
: On 19 August 2011 15:09, Yingjie Lin yingjie@mssm.edu wrote: I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't spell the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You should always specify the error type, so that your error-handling code won't attempt to handle an error it didn't anticipate and cause even more problems. In this case, I think it's just that you haven't imported HTTPError into your namespace - if you do, it works: from urllib2 import urlopen, HTTPError try: ... response = urlopen(http://google.com/invalid;) ... except HTTPError: ... print URL does not exist! ... URL does not exist! Alternatively: import urllib2 try: ... response = urllib2.urlopen(http://google.com/invalid;) ... except urllib2.HTTPError: ... print URL does not exist! ... URL does not exist! A careful look at the difference between these two ought to make it clear what's going on. -[]z. -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
Hi Zero, I see! This is very helpful. Thank you. - Yingjie On Aug 19, 2011, at 3:30 PM, Zero Piraeus wrote: : On 19 August 2011 15:09, Yingjie Lin yingjie@mssm.edu wrote: I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't spell the error types correctly. For example, try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You should always specify the error type, so that your error-handling code won't attempt to handle an error it didn't anticipate and cause even more problems. In this case, I think it's just that you haven't imported HTTPError into your namespace - if you do, it works: from urllib2 import urlopen, HTTPError try: ... response = urlopen(http://google.com/invalid;) ... except HTTPError: ... print URL does not exist! ... URL does not exist! Alternatively: import urllib2 try: ... response = urllib2.urlopen(http://google.com/invalid;) ... except urllib2.HTTPError: ... print URL does not exist! ... URL does not exist! A careful look at the difference between these two ought to make it clear what's going on. -[]z. -- http://mail.python.org/mailman/listinfo/python-list
Re: 'super' object has no attribute '__setitem__'
I'm pretty sure I'd actually read the first 2 links you point to, but the difference between __setattr__ and __setitem__ still never registered with me -- perhaps partly because even the discussion of __setattr__ discusses adding an entry to the *dictionary* of instance attributes. *MANY* thanks for your help! On Thu, Aug 18, 2011 at 10:07 PM, Eric Snow ericsnowcurren...@gmail.comwrote: On Thu, Aug 18, 2011 at 7:44 PM, luvspython srehtva...@gmail.com wrote: I'm using Python 2.7 and the code below fails at the 'super' statement in the __setitem__ function in the HistoryKeeper class. The error is: 'super' object has no attribute '_setitem__' Can anyone please tell me why and how to fix it? (I've googled endlessly and I don't see the problem.) [The code will seem silly as it is, because it's pared down to show the example. The goal is that multiple classes, like the Vehicle class below, will inherit HistoryKeeper. History keeper overloads __setitem__ and will eventually keep a running history every time an attribute of any of the inheriting classes is changed.] Thanks in advance class HistoryKeeper(object): def __init__(self, args): for arg, value in args.items(): if arg != 'self': self.__setitem__(arg, value) def __setitem__(self, item, value): super(HistoryKeeper, self).__setitem__(item, value) class Vehicle(HistoryKeeper): def __init__(self, tag, make, model): args = locals() super(Vehicle, self).__init__(args) if __name__ == __main__: car = Vehicle('TAG123', 'FORD', 'Model A') print car.make Did you mean to use __setattr__ instead? object, the base class of HistoryKeeper, does not have a __setitem__ method, hence the AttributeError. super() is a proxy for the next class in the MRO, typically the base class of your class. Keep in mind that obj.tag = TAG123 is equivalent to obj.__setattr__(tag, TAG123). However, obj[tag] = TAG123 is equivalent to obj.__setitem__(tag, TAG123). see: http://docs.python.org/reference/datamodel.html#object.__setattr__ http://docs.python.org/reference/datamodel.html#object.__setitem__ http://docs.python.org/library/functions.html#super -eric -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on PyQt4 QProcess
On Aug 19, 1:56 pm, Phil Thompson p...@riverbankcomputing.com wrote: On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes fuente...@gmail.com wrote: Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal finished(int) of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x=started:print(x)) # connect pro.connect(pro, SIGNAL(finished(int)), lambda x=finished:print(x)) pro.start('python',['hello.py']) # star hello.py program (contain print(hello world!)) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) Yes it is, and your lambda slot is printing 0 which is the return code of the process. Phil Ok, but the output should be: started b'hello world!\n' finished no?. thanks Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On 08/19/2011 11:33 AM, Matt Funk wrote: On Friday, August 19, 2011, Alain Ketterlin wrote: Matt Funk matze...@gmail.com writes: thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times a space followed by a number. Using Jason's regexp, you can build the regexp step by step: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31} % (number,number) That didn't work either. Using the (modified (where the (.+) matches the end of the line)) expression as: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31}(.+) % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. The secret is buried very unobtrusively in the re docs, where it has caught me out in the past. Specifically in the docs for re.group(): If a group is contained in a part of the pattern that matched multiple times, the last match is returned. In addition to the findall solution someone else posted, another thing you could do is to explicitly express the groups in your re: number = r\d\.\d+e\+\d+ groups = (r( %s) % number)*31 numbersequence = r%s%s(.+) % (number,groups) ... results = match_object.group(range(1,33)) Or (what I would probably do), simply match the whole string of numbers and pull it apart later: number = r\d\.\d+e\+\d+ numbersequence = r(%s(?: %s){31})(.+) % (number,number) results = (match_object.group(1)).split() [none of this code is tested but should be close enough to convey the general idea.] -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
John Gordon wrote: In mailman.230.1313780957.27778.python-l...@python.org Yingjie Lin yingjie@mssm.edu writes: try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Have you imported urllib2 in your code? Good question. If Python doesn't recognize it as an error type name, there is a reason for that. Exceptions are exactly the same as every other name: foo.spam Traceback (most recent call last): File stdin, line 1, in module NameError: name 'foo' is not defined urllib2.HTTPError Traceback (most recent call last): File stdin, line 1, in module NameError: name 'urllib2' is not defined Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You can catch all exceptions by catching the base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot Girls are Looking for Sex
That's great - but do they program in python? On Fri, Aug 19, 2011 at 2:38 PM, Sajjad Ahmad sajjad.ahmad...@gmail.com wrote: See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . See All details on http://hotelandtourism9.blogspot.com/2011/08/indian-hotels-wall-st-effect.html . -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31}(.+) % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. I think the problem is that repeat counts don't actually repeat the groupings; they just repeat the matchings. Take this expression: r(\w+\s*){2} This will match exactly two words separated by whitespace. But the match result won't contain two groups; it'll only contain one group, and the value of that group will match only the very last thing repeated: Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import re m = re.match(r(\w+\s*){2},abc def) m.group(1) 'def' So you see, the regular expression is doing what you think it is, but the way it forms groups is not. Just a little advice (I know you've found a different method, and that's good, this is for the general reader). The functions re.findall and re.finditer could have helped here, they find all the matches in a string and let you iterate through them. (findall returns the strings matched, and finditer returns the sequence of match objects.) You could have done something like this: row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] And regexp matching is often overkill for a particular problem; this may be of them. line.split() could have been sufficient: row = [ float(x) for x in line.split() ] Of course, these solutions don't account for the case where you have lines, some of which aren't 32 floating-point numbers. You need extra error handling for that, but you get the idea. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
In 4e4ec405$0$29994$c3e8da3$54964...@news.astraweb.com Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: You can catch all exceptions by catching the base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. I agree, but it did seem to be exactly what he was asking for. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on PyQt4 QProcess
On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: On Aug 19, 1:56 pm, Phil Thompson wrote: On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes fuen...@gmail.com wrote: Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal finished(int) of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x=started:print(x)) # connect pro.connect(pro, SIGNAL(finished(int)), lambda x=finished:print(x)) pro.start('python',['hello.py']) # star hello.py program (contain print(hello world!)) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) Yes it is, and your lambda slot is printing 0 which is the return code of the process. Phil Ok, but the output should be: started b'hello world!\n' finished no?. thanks Phil Two issues. First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. Anyway, to fix that, try this: pro.connect(pro, SIGNAL(finished(int)), lambda v, x=finished:print(x)) Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of finished. Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Hot Girls are Looking for Sex
On Aug 19, 2011, at 4:17 PM, Matty Sarro wrote: That's great - but do they program in python? Please don't repost URLs sent by a spammer. Only Google truly knows how its algorithm works, but the general consensus is that the more times Google sees a link repeated, the more credibility the link is given. By reposting links, you help the spammer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
Forafo San wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. You might save some memory by using tuples rather than lists: sys.getsizeof([01/01/2000, 123.456]) # On a 32-bit system. 40 sys.getsizeof((01/01/2000, 123.456)) 32 By the way, you know that you should never, ever use floats for currency, right? http://vladzloteanu.wordpress.com/2010/01/11/why-you-shouldnt-use-float-for-currency-floating-point-issues-explained-for-ruby-and-ror/ http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated It certainly is not. http://docs.python.org/library/shelve.html http://docs.python.org/py3k/library/shelve.html Not a word about it being deprecated in either Python 2.x or 3.x. AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an ls did not make sense, etc.). I would like to see this replicated. If it is true, that's a bug in shelve, but I expect you're probably doing something wrong. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On 19/08/2011 20:55, ru...@yahoo.com wrote: On 08/19/2011 11:33 AM, Matt Funk wrote: On Friday, August 19, 2011, Alain Ketterlin wrote: Matt Funkmatze...@gmail.com writes: thanks for the suggestion. I guess i had found another way around the problem as well. But i really wanted to match the line exactly and i wanted to know why it doesn't work. That is less for the purpose of getting the thing to work but more because it greatly annoys me off that i can't figure out why it doesn't work. I.e. why the expression is not matches {32} times. I just don't get it. Because a line is not 32 times a number, it is a number followed by 31 times a space followed by a number. Using Jason's regexp, you can build the regexp step by step: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31} % (number,number) That didn't work either. Using the (modified (where the (.+) matches the end of the line)) expression as: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31}(.+) % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. The secret is buried very unobtrusively in the re docs, where it has caught me out in the past. Specifically in the docs for re.group(): If a group is contained in a part of the pattern that matched multiple times, the last match is returned. [snip] There's a regex implementation on PyPI: http://pypi.python.org/pypi/regex which does support capturing all of the matches of a group. -- http://mail.python.org/mailman/listinfo/python-list
Stop quoting spam [was Re: Hot Girls ...]
Matty Sarro wrote: That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your joke I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your joke was so worth it. Not. [spam deleted] -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
John Gordon wrote: In 4e4ec405$0$29994$c3e8da3$54964...@news.astraweb.com Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: You can catch all exceptions by catching the base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. I agree, but it did seem to be exactly what he was asking for. Sure, but if we're giving advice to somebody who is clearly a beginner (doesn't even know how to deal with a simple NameError from failing to import a module), it is our responsibility to teach *good* habits, not to teach him to be a crap programmer. Even if you don't think it's the ethical thing to do, consider that someday you might be maintaining code written by the OP :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Stop quoting spam [was Re: Hot Girls ...]
It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Matty Sarro wrote: That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your joke I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your joke was so worth it. Not. [spam deleted] -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Stop quoting spam [was Re: Hot Girls ...]
It was a joke, no need to be a prick about it. If you're that offended then spend the cycles fixing the damn list so it stops having so much spam. You realize spam comes in almost constantly, right? Enough that multiple tines over the past weeks there have been no less than 3 threads about it. If php, red hat, and perl can manage it for their lists, why not python? Is that a statement about python programmers? God forbid I try to make a joke. Grow up. On Aug 19, 2011 4:46 PM, Steven Dapos;Aprano steve+comp.lang.pyt...@pearwood.info wrote: Matty Sarro wrote: That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your joke I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your joke was so worth it. Not. [spam deleted] -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Stop quoting spam [was Re: Hot Girls ...]
Glad someone has a sense of humor :) If one person smiled I consider it a success. Happy weekend! On Aug 19, 2011 5:12 PM, Rodrick Brown rodrick.br...@gmail.com wrote: It's not the end of the world calm down I thought it was quite funny for a friday joke! Sent from my iPhone On Aug 19, 2011, at 4:43 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Matty Sarro wrote: That's great - but do they program in python? Thanks for that, I didn't see the spam the first time, but thanks to your joke I saw it now! I really appreciate that, because I LOVE to have spam sent to me, including all the URLs. An extra bonus is that when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your joke was so worth it. Not. [spam deleted] -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On Friday, August 19, 2011, jmfauth wrote: On 19 août, 19:33, Matt Funk matze...@gmail.com wrote: The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. Seen on this list: And always keep this in mind: 'Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems.' --Jamie Zawinski, comp.lang.emacs I proposed a solution which seems to corresponds to your problem if it were better formulated... Agreed, and i will probably take your proposed route or a similar one. However, i still won't know WHY it didn't work. I would really LIKE to know why, simply because it tickles me. matt jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
xDog Walker wrote: On Friday 2011 August 19 12:09, Yingjie Lin wrote: [ ... ] Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You probably need to import urllib2 before you can use urllib2.HTTPError. Otherwise, you can try using the base class: except Exception, e: There are maybe better base classes to use. Running the interpreter: Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. import urllib2 help (urllib2.HTTPError) will show you class HTTPError(URLError, urllib.addinfourl) | Raised when HTTP error occurs, but also acts like non-error return | | Method resolution order: | HTTPError | URLError | exceptions.IOError | exceptions.EnvironmentError | exceptions.StandardError | exceptions.Exception | exceptions.BaseException So catching any of urllib2.HTTPError, urllib2.URLError, IOError, EnvironmentError, or StandardError will detect the exception -- with increasing levels of generality. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stop quoting spam [was Re: Hot Girls ...]
On Fri, 19 Aug 2011 17:12:40 -0400 Matty Sarro msa...@gmail.com wrote: It was a joke, no need to be a prick about it. It was spam. You're the prick. If you think spam is funny it's because you aren't the one that has to spend your time dealing with the fallout. If you're that offended then spend the cycles fixing the damn list so it Most of us have fixed it. We didn't see the spam until you repeated it. For whatever reason the original message was caught by our filters. You helped the spammer break through. I can assure you though that your attitude means that you won't be able to help them again. I can hear the plonking going on all over the net. Here's another one; *plonk* No point in replying. I won't hear it. Hope you don't have any important questions for the group. It just became more of a read-only list for you. If php, red hat, and perl can manage it for their lists, why not python? Is that a statement about python programmers? And that should get you blacklisted by anyone on the cusp. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on PyQt4 QProcess
On Aug 19, 4:21 pm, Carl Banks pavlovevide...@gmail.com wrote: On Friday, August 19, 2011 12:55:40 PM UTC-7, Edgar Fuentes wrote: On Aug 19, 1:56 pm, Phil Thompson wrote: On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes fuen...@gmail.com wrote: Dear friends, I need execute an external program from a gui using PyQt4, to avoid that hang the main thread, i must connect the signal finished(int) of a QProcess to work properly. for example, why this program don't work? from PyQt4.QtCore import QProcess pro = QProcess() # create QProcess object pro.connect(pro, SIGNAL('started()'), lambda x=started:print(x)) # connect pro.connect(pro, SIGNAL(finished(int)), lambda x=finished:print(x)) pro.start('python',['hello.py']) # star hello.py program (contain print(hello world!)) timeout = -1 pro.waitForFinished(timeout) print(pro.readAllStandardOutput().data()) output: started 0 b'hello world!\n' see that not emit the signal finished(int) Yes it is, and your lambda slot is printing 0 which is the return code of the process. Phil Ok, but the output should be: started b'hello world!\n' finished no?. thanks Phil Two issues. First of all, your slot for the finished function does not have the correct prototype, and it's accidentally not throwing an exception because of your unnecessary use of default arguments. Anyway, to fix that, try this: pro.connect(pro, SIGNAL(finished(int)), lambda v, x=finished:print(x)) Notice that it adds an argument to the lambda (v) that accepts the int argument of the signal. If you don't have that argument there, the int argument goes into x, which is why Python prints 0 instead of finished. Second, processess run asynchrously, and because of line-buffering, IO can output asynchronously, and so there's no guarantee what order output occurs. You might try calling the python subprocess with the '-u' switch to force unbuffered IO, which might be enough to force synchronous output (depending on how signal/slot and subprocess semantics are implemented). Carl Banks Thanks Carl, your intervention was very helpful for me, this solve my semantic error. I need to study more about signal/slots and process. -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
On 8/19/11 12:09 PM, Yingjie Lin wrote: try: response = urlopen(urljoin(uri1, uri2)) except urllib2.HTTPError: print URL does not exist! Though urllib2.HTTPError is the error type reported by Python, Python doesn't recognize it as an error type name. I tried using HTTPError alone too, but that's not recognized either. Exceptions are objects like any other, and they are defined in specific places. Only the standard ones are available everywhere; things like IndexError and AttributeError. See the 'exceptions' module for the standard ones. Everything else, you have to 'grab' the object from where it lives -- in this case, in urllib2. Does anyone know what error type I should put after the except statement? or even better: is there a way not to specify the error types? Thank you. You can use a bare except, like so: try: ... except: ... But avoid it, if you can. Or at least, don't let it become habit-forming: for networking code and interaction with external things, I usually have a bare-except as a final fallback, after trying other more specific things-- but only as a last resort. FWIW, the error hierarchy of url fetching is more then a little bit annoying. My own _request object I end up using for one of our services catches, in order: try: ... except urllib2.HTTPError: except urllib2.URLError: except httplib.BadStatusLine: except httplib.HTTPException: except socket.timeout: except: With each case logging and handling the error in a bit of a different way. (Though most, eventually, resulting in the request being retried -- all in the name of a mandate that this particular bit of code must not, under any circumstances, not ultimately work. Even going so far as to start having hour long waits between retries until the other side is finally up :P) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with regular expression in python
On Friday, August 19, 2011, Carl Banks wrote: On Friday, August 19, 2011 10:33:49 AM UTC-7, Matt Funk wrote: number = r\d\.\d+e\+\d+ numbersequence = r%s( %s){31}(.+) % (number,number) instance_linetype_pattern = re.compile(numbersequence) The results obtained are: results: [(' 2.199000e+01', ' : (instance: 0)\t:\tsome description')] so this matches the last number plus the string at the end of the line, but no retaining the previous numbers. Anyway, i think at this point i will go another route. Not sure where the issues lies at this point. I think the problem is that repeat counts don't actually repeat the groupings; they just repeat the matchings. Take this expression: r(\w+\s*){2} I see This will match exactly two words separated by whitespace. But the match result won't contain two groups; it'll only contain one group, and the value of that group will match only the very last thing repeated: Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. import re m = re.match(r(\w+\s*){2},abc def) m.group(1) 'def' So you see, the regular expression is doing what you think it is, but the way it forms groups is not. Just a little advice (I know you've found a different method, and that's good, this is for the general reader). The functions re.findall and re.finditer could have helped here, they find all the matches in a string and let you iterate through them. (findall returns the strings matched, and finditer returns the sequence of match objects.) You could have done something like this: I did use findall but when i tried to match the everything (including the 'some description' part) it did not work. But i think the explanation you gave above matches this case and explains why it did not. row = [ float(x) for x in re.findall(r'\d+\.\d+e\+d+',line) ] And regexp matching is often overkill for a particular problem; this may be of them. line.split() could have been sufficient: row = [ float(x) for x in line.split() ] Of course, these solutions don't account for the case where you have lines, some of which aren't 32 floating-point numbers. You need extra error handling for that, but you get the idea. thanks matt Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On 8/19/11 3:36 PM, Steven D'Aprano wrote: By the way, you know that you should never, ever use floats for currency, right? That's just incorrect. You shouldn't use (binary) floats for many *accounting* purposes, but for many financial/econometric analyses, floats are de rigeur and work much better than decimals (either floating or fixed point). If you are collecting gigs of stock prices, you are much more likely to be doing the latter than the former. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make statements running in strictly sequential fashion like in an interactive shell
On Aug 19, 5:00 pm, lzlu123 lzlu...@gmail.com wrote: I have an instrument that has a RS232 type serial comm port and I need to connect to and control. I use Python 3.2 in Windows XP, plus pySerial module. I have a problem when I execute a script consisting of statements that open the comm port, configure it, write strings to and receive strings from it. Thoese strings aer either commands pertinent to the instrument (control) or responses from the instrument (response). When those statements are executed in a python interpreter interactively (at ), I get what I expect and the results are good and correct. However, when I execute the script, either being invoked within the interpreter or run file, I don’t get what I want. The statements in the script is the same as what I use in the interactive interpreter. Why do I get the strange behavior and how can I change the script to make it to behave like in interactive interpreter? --script--- def read(comport): wrt_str=b'movt 3000'+b'\r\n' ret_str=comport.write(wrt_str) wrt_str=b'scan'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines() #1 You use readlines() with a s at the end ! * Note that when the serial port was opened with no timeout, that readline() * blocks until it sees a newline (or the specified size is reached) * and that readlines() would never return and therefore refuses to work * (it raises an exception in this case)! wrt_str=b'hllo'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines()#2 -- The problem is with the lines above with ###. In interactive mode, there is about 1 second delay at #1, and 9 seonds delay at #2. I get correct responses there. However, if I execute the script above, there is no delay at all and I get incorrect results (garbage). I set the read timeout to 0 in comm port set up, as comport.timeout=0 So the comport should be in blocking mode if it waits for the end of line or end of file. Wrong : timeout = None: wait forever timeout = 0: non-blocking mode (return immediately on read) timeout = x: set timeout to x seconds (float allowed) I tried many things, like exec (execfile in 2.7), but at no avail. I have an update to the original post I made a few days ago. I think I know what the problem is and want to know if anyone has a solution: After putting print and time.sleep(delay) after every statement, I found when the script is running, it appears going around the pyserial statement, such as comport.write(..) or comport.readlines(...) while the pyserial command is executing (appearing as waiting and busying doing some thing, you know serial port is slow). So for example, when I exec all statements in a python interactive shell, I am not able to type and run a new statement if the previous one is not returned. Let's ay, if comport.readlines() is not returning, I can't type and run the next comport.write(...) statemtn. However, in a script that is running, if the comport.readlines() is busy reading, the next statement is running, if the next statement happens to be a comport.write() which will abort the reading. Is there any way to force the python script to behave like running exactly sequentially? You have some new things to try -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
On Fri, Aug 19, 2011 at 8:31 AM, Forafo San ppv.g...@gmail.com wrote: Folks, What might be a good replacement for the shelve module, but one that can handle a few gigs of data. I'm doing some calculations on daily stock prices and the result is a nested list like: [[date_1, floating result 1], [date_2, floating result 2], ... [date_n, floating result n]] However, there are about 5,000 lists like that, one for each stock symbol. Using the shelve module I could easily save them to a file ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the data. But shelve is deprecated AND when a lot of data is written shelve was acting weird (refusing to write, filesizes reported with an ls did not make sense, etc.). I'd probably use a cachedb, though perhaps I'm biased since I wrote it: http://stromberg.dnsalias.org/~dstromberg/cachedb.html It'll allow you to specify functions for serializing and deserializing values (but not keys), and cache a user-specified number of values in virtual memory. IOW, once you instantiate the class, you pretty much get caching and seralizing/deserializing as freebies, without the details of same getting scattered throughout your code. It wraps something like gdbm. -- http://mail.python.org/mailman/listinfo/python-list
Re: Stop quoting spam [was Re: Hot Girls ...]
On Friday, August 19 at 17:12 (-0400), Matty Sarro said: If you're that offended then spend the cycles fixing the damn list so it stops having so much spam. You realize spam comes in almost constantly, right? Enough that multiple tines over the past weeks there have been no less than 3 threads about it. For me, the original post ended in my spam box, which means my filter is doing it's job, but when you re-post it, my filter did not regard it as spam. I actually wish it had. Therefore you are an enabler. If php, red hat, and perl can manage it for their lists, why not python? Is that a statement about python programmers? The python list is (also) a Usenet newsgroup. Usenet is distributed and therefore there is no central place to filter spam (each usenet host would have to have its own filter and what one considers spam another might consider ham)... anyway, that's neither here nor there. Having my own filter usually works. I'm not here to dis you, just to try to help you understand the how/why regarding the re-post and why your attitude about it might give the impression of apathy toward your peer community. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacement for the shelve module?
Robert Kern wrote: On 8/19/11 3:36 PM, Steven D'Aprano wrote: By the way, you know that you should never, ever use floats for currency, right? That's just incorrect. You shouldn't use (binary) floats for many *accounting* purposes, but for many financial/econometric analyses, floats are de rigeur and work much better than decimals (either floating or fixed point). If you are collecting gigs of stock prices, you are much more likely to be doing the latter than the former. That makes sense, and I stand corrected. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: testing if a list contains a sublist
Johannes wrote: hi list, what is the best way to check if a given list (lets call it l1) is totally contained in a second list (l2)? [...] For anyone interested, here's a pair of functions that implement sub-sequence testing similar to str.find and str.rfind: http://code.activestate.com/recipes/577850-search-sequences-for-sub-sequence/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: How to make statements running in strictly sequential fashion like in an interactive shell
Never used it, but I think you can try this: Pexpect - a Pure Python Expect-like module Pexpect is a pure Python Expect-like module. Pexpect makes Python... www.noah.org/python/pexpect/ lzlu123 lzlu...@gmail.com wrote: I have an instrument that has a RS232 type serial comm port and I need to connect to and control. I use Python 3.2 in Windows XP, plus pySerial module. I have a problem when I execute a script consisting of statements that open the comm port, configure it, write strings to and receive strings from it. Thoese strings aer either commands pertinent to the instrument (control) or responses from the instrument (response). When those statements are executed in a python interpreter interactively (at ), I get what I expect and the results are good and correct. However, when I execute the script, either being invoked within the interpreter or run file, I don???t get what I want. The statements in the script is the same as what I use in the interactive interpreter. Why do I get the strange behavior and how can I change the script to make it to behave like in interactive interpreter? --script--- def read(comport): wrt_str=b'movt 3000'+b'\r\n' ret_str=comport.write(wrt_str) wrt_str=b'scan'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines() #1 wrt_str=b'hllo'+b'\r\n' ret_str=comport.write(wrt_str) rsp_str=comport.readlines()#2 -- The problem is with the lines above with ###. In interactive mode, there is about 1 second delay at #1, and 9 seonds delay at #2. I get correct responses there. However, if I execute the script above, there is no delay at all and I get incorrect results (garbage). I set the read timeout to 0 in comm port set up, as comport.timeout=0 So the comport should be in blocking mode if it waits for the end of line or end of file. I tried many things, like exec (execfile in 2.7), but at no avail. I have an update to the original post I made a few days ago. I think I know what the problem is and want to know if anyone has a solution: After putting print and time.sleep(delay) after every statement, I found when the script is running, it appears going around the pyserial statement, such as comport.write(..) or comport.readlines(...) while the pyserial command is executing (appearing as waiting and busying doing some thing, you know serial port is slow). So for example, when I exec all statements in a python interactive shell, I am not able to type and run a new statement if the previous one is not returned. Let's ay, if comport.readlines() is not returning, I can't type and run the next comport.write(...) statemtn. However, in a script that is running, if the comport.readlines() is busy reading, the next statement is running, if the next statement happens to be a comport.write() which will abort the reading. Is there any way to force the python script to behave like running exactly sequentially? -- http://mail.python.org/mailman/listinfo/python-list
Re: List spam
You will lose a lot of people asking/answering interesting stuff, and maybe eventually the list will die. Me (like many people with little free time) seldom post in blogs/forums/mailing lists where I need to register. gene heskett ghesk...@wdtv.com wrote: That is asking the user to take considerable effort and resources to do that. What is wrong with the mailing list only approach? -- http://mail.python.org/mailman/listinfo/python-list
Python Windows Extensions for Mac
Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Windows Extensions for Mac
You mean pywin32? They sure don't install on linux so that should give you a clue... On 19 August 2011 22:02, johnny.venter johnny.ven...@zoho.com wrote: Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Windows Extensions for Mac
On Fri, Aug 19, 2011 at 1:02 PM, johnny.venter johnny.ven...@zoho.com wrote: Hello, I am looking for the Python Windows Extensions to see if they can be installed on a Mac.THanks. Your request is nonsensical. pywin32 wraps the Windows API libraries. Mac OS X is not Windows; it does not implement the Windows API. Thus, there is nothing for pywin32 to wrap on a Mac. Square peg, round hole. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
On 2011-08-19, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Even if you don't think it's the ethical thing to do, consider that someday you might be maintaining code written by the OP :) A common further conclusion people reach is but then I will be able to get a job fixing it! Trust me, this is NOT where you want to go. :) -s -- Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
[issue12780] Clean up tests for pyc/pyo in __file__
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 98d13885a574 by Vinay Sajip in branch '3.2': Issue #12780: Removed checks in logging for .pyc/.pyo in __file__. http://hg.python.org/cpython/rev/98d13885a574 New changeset ac0c04d8eafb by Vinay Sajip in branch 'default': Issue #12780: Merged fix from 3.2. http://hg.python.org/cpython/rev/ac0c04d8eafb -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12780 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'
Marc-Andre Lemburg m...@egenix.com added the comment: James Y Knight wrote: James Y Knight f...@users.sourceforge.net added the comment: Sure, you can compile and run Python on both versions of Linux, but what if your application uses features that are only present in Linux 3.0 and later ? This comment is making me think you've missed just how irrelevant kernel version 3.0 really is. To a first approximation, it *has no new features*. Now, to be sure, there are a couple of things, sure. Just like there were a couple new features in 2.6.39 two months earlier, 2.6.38 two months before that, 2.6.37 two months before that, and so on, every 2-3 months, back to the release of 2.6.7 or so in 2004. I am aware of the history behind that version number change. The difference between Linux 2.x and 3.x may be small nowadays, but another 20 kernel releases down the road, the difference will show. BTW: The new attribute should contain the complete version number, not just the major version. `uname -r` would provide a good start. To be useful, that would have to be a runtime-computed thing, not the build-time value that sys.platform's trailing number is. But we already have that: os.uname(). It certainly doesn't need a second name. There are two aspects to consider: 1. The platform Python (and presumably the application) was compiled on. 2. The platform Python and the application are currently running on. Both Python and the application will make certain assumptions about the platform depending on the compile time environment. If the deployment platform is too different from that environment, it won't run or not as expected. So you need both the compile and the runtime version information. The suggested change removes the compile time information from the platform string, so that information needs to be preserved in a new attribute. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'
Martin von Gagern martin.vgag...@gmx.net added the comment: As people keep stating how easy the change from sys.platform == 'linux2' to sys.platform.startswith('linux') is, e.g. msg142385, please also keep in mind cases like someDict.get(sys.platform) where the comparison is implicit and therefore a simple change to startswith won't do the trick. Seen that in the wild. Besides that, I can only wholeheartedly agree to the points so eloquently described by Martin v. Löwis and James Y Knight. Thanks! Let's please force it to 'linux2' for the next 2.7 and 3.2 releases, so people can use recent kernels without breaking (or having to rewrite) third-party apps. Let's also encourage distros to do the same for older releases, perhaps even suggesting patches. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'
Martin von Gagern martin.vgag...@gmx.net added the comment: Marc-Andre Lemburg wrote: Both Python and the application will make certain assumptions about the platform depending on the compile time environment. Can you give examples for this? So you need both the compile and the runtime version information. I very much doubt that any feature in Python is actually enabled if compiled under Linux 3. If so that's probably a bug in Python, due to the small number of features added from 2.6.39 to 3.0. Either the feature was introduced into Linux before 3.0, in which case Python should use it as early as possible, or the feature was introduced in some 3.x release, in which case not all Linux 3 builds will have it. So the single digit major number will not be enough for this kind of checks, and the safest way is to check for the feature itself, e.g. by simply using it and handling NotImplementedException appropriately. That approach is more portable for new platforms as well. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'
Marc-Andre Lemburg m...@egenix.com added the comment: Martin von Gagern wrote: Martin von Gagern martin.vgag...@gmx.net added the comment: Marc-Andre Lemburg wrote: Both Python and the application will make certain assumptions about the platform depending on the compile time environment. Can you give examples for this? Sure, just have a look at how different the various minor release Mac OS X versions are. They even changed the default architecture without bumping the major version of the OS. A configure run on one OS version will pick up different environment settings than on a later one. As a result Python and application extensions use different libs/packages/tools or even create completely different runtimes (e.g. one for PPC, the other for i386). So you need both the compile and the runtime version information. I very much doubt that any feature in Python is actually enabled if compiled under Linux 3. If so that's probably a bug in Python, due to the small number of features added from 2.6.39 to 3.0. Either the feature was introduced into Linux before 3.0, in which case Python should use it as early as possible, or the feature was introduced in some 3.x release, in which case not all Linux 3 builds will have it. So the single digit major number will not be enough for this kind of checks, and the safest way is to check for the feature itself, e.g. by simply using it and handling NotImplementedException appropriately. That approach is more portable for new platforms as well. That works fine for features that you can programmatically control. It doesn't work well for static data that you provide externally depending on the platform OS version. Take e.g. the plat-freebsdN directories with the OS dependent constants/functions as example. As already mentioned, the diff between Linux 2.x and 3.x will grow over time and while there may not be much to see now, things will change in the coming years. Just look at the differences between plat-linux1 and plat-linux2 (plat-linux1 was phased out in Python 2.4 so you have to go back to Python 2.3 or earlier). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10504] Trivial mingw compile fixes
Changes by Kalev Lember kalevlem...@gmail.com: -- nosy: +kalev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10293] PyMemoryView object has obsolete members
Stefan Krah stefan-use...@bytereef.org added the comment: I think PyBUF_SHADOW was the renamed version of PyBUF_UPDATEIFCOPY from the PEP. :) -- nosy: +skrah ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10293 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12650] Subprocess leaks fd upon kill()
Charles-François Natali neolo...@free.fr added the comment: The test now passes on the buildbots, closing. -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12650 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12783] test_posix failure on FreeBSD 6.4: test_get_and_set_scheduler_and_param
New submission from Charles-François Natali neolo...@free.fr: http://www.python.org/dev/buildbot/all/builders/x86%20FreeBSD%206.4%203.x/builds/1734/steps/test/logs/stdio == ERROR: test_get_and_set_scheduler_and_param (test.test_posix.PosixTester) -- Traceback (most recent call last): File /usr/home/db3l/buildarea/3.x.bolen-freebsd/build/Lib/test/test_posix.py, line 878, in test_get_and_set_scheduler_and_param posix.sched_setparam(0, param) OSError: [Errno 22] Invalid argument -- The reason is quite simple: http://freebsd.active-venture.com/FreeBSD-srctree/newsrc/posix4/ksched.c.html /* * XXX About priorities * * POSIX 1003.1b requires that numerically higher priorities be of * higher priority. It also permits sched_setparam to be * implementation defined for SCHED_OTHER. I don't like * the notion of inverted priorites for normal processes when * you can use setpriority for that. * * I'm rejecting sched_setparam for SCHED_OTHER with EINVAL. */ [...] int ksched_setparam(register_t *ret, struct ksched *ksched, struct proc *p, const struct sched_param *param) { register_t policy; int e; e = getscheduler(policy, ksched, p); if (e == 0) { if (policy == SCHED_OTHER) e = EINVAL; else e = ksched_setscheduler(ret, ksched, p, policy, param); } return e; } And indeed, sched_setparam is implementation-defined if the process' scheduling policy is SCHED_OTHER, see http://pubs.opengroup.org/onlinepubs/007908799/xsh/sched_setparam.html If the current scheduling policy for the process specified by pid is not SCHED_FIFO or SCHED_RR, including SCHED_OTHER, the result is implementation-dependent. It seems that FreeBSD made the choice of returning EINVAL, but it changed in recent versions (the test passes on FreeBSD 8). I'm not sure about the best solution though: 1) don't perform this test if the scheduling policy is not SCHED_RR or SCHED_FIFO 2) skip this test on FreeBSD versions that return EINVAL (maybe adding a new requires_freebsd_version to test.support) -- components: Tests messages: 142423 nosy: benjamin.peterson, neologix priority: normal severity: normal stage: needs patch status: open title: test_posix failure on FreeBSD 6.4: test_get_and_set_scheduler_and_param type: behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12707] Deprecate addinfourl getters
Éric Araujo mer...@netwok.org added the comment: For these two reasons I propose to: * document the 3 attributes as the suggested way to access this information; * deprecate the 3 getters; * avoid to document the now undocumented getcode(); +1 The addclosehook class could be provided via an alternative constructor I can’t say why, but I don’t like that. -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12707 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: code should avoid using sys.platform == 'linux2'
Antoine Pitrou pit...@free.fr added the comment: The suggested change removes the compile time information from the platform string, so that information needs to be preserved in a new attribute. -1 on any new platform identification attribute. We already have too many of them, and there's the platform module for precise identification. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11564] pickle not 64-bit ready
Antoine Pitrou pit...@free.fr added the comment: I have tried running the tests on a machine with 12GB of RAM, but when I do so, the new tests get skipped saying not enough memory, even when I specify -M 11G on the command-line. How much does it say is required? Did you remove the skips in BigmemPickleTests? The problem seems to be the change to the precisionbigmemtest decorator in test.support. I don't understand what the purpose of the dryrun flag is, but the modified condition for skipping doesn't look right to me. Well, perhaps I got the logic wrong. Debugging welcome :) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11564 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12256] Link isinstance/issubclass doc to abc module
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset eeb8a440bde0 by Éric Araujo in branch '3.2': Link isinstance/issubclass to the ABC glossary entry (#12256) http://hg.python.org/cpython/rev/eeb8a440bde0 New changeset e2e8c752c1b6 by Éric Araujo in branch '3.2': Mention virtual subclasses in the glossary entry for ABCs (#12256). http://hg.python.org/cpython/rev/e2e8c752c1b6 New changeset 5160d8eb3468 by Éric Araujo in branch 'default': Merge fixes for #12256 and typos from 3.2 http://hg.python.org/cpython/rev/5160d8eb3468 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1626300] 'Installing Python Modules' does not work for Windows
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 59f7bbe1236c by Éric Araujo in branch '3.2': Remove obsolete term + indicate how to find the program (#1626300). http://hg.python.org/cpython/rev/59f7bbe1236c New changeset adaec1a0dd47 by Éric Araujo in branch '3.2': Fix instance I missed in 59f7bbe1236c (#1626300) http://hg.python.org/cpython/rev/adaec1a0dd47 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1626300 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10149] Data truncation in expat parser
Éric Araujo mer...@netwok.org added the comment: I was about to commit an edited version of your patch (attached) but then I thought we should check whether this isn’t really a bug. I just don’t see why expat would chunk without paying heed to the newlines if it is supposed to chunk at newlines. -- Added file: http://bugs.python.org/file22945/pyexpat.rst.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10149 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12256] Link isinstance/issubclass doc to abc module
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 96222062239f by Éric Araujo in branch '2.7': Link isinstance/issubclass to the ABC glossary entry (#12256) http://hg.python.org/cpython/rev/96222062239f -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10745] setup.py install --user option undocumented
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 25a48fe791e6 by Éric Araujo in branch '2.7': Add documentation for PEP 370 features in distutils (#10745). http://hg.python.org/cpython/rev/25a48fe791e6 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10745 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8617] Better document user site-packages in site module doc
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset b3f72b6450f1 by Éric Araujo in branch '2.7': Improve documentation for PEP 370 support in site module (#8617). http://hg.python.org/cpython/rev/b3f72b6450f1 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8617 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1626300] 'Installing Python Modules' does not work for Windows
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset e9022dc7a411 by Éric Araujo in branch '2.7': Remove obsolete term + indicate how to find the program (#1626300). http://hg.python.org/cpython/rev/e9022dc7a411 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1626300 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10745] setup.py install --user option undocumented
Changes by Éric Araujo mer...@netwok.org: -- components: +Distutils nosy: +alexis resolution: - fixed stage: - committed/rejected status: open - closed versions: +Python 2.7, Python 3.2, Python 3.3 -3rd party ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10745 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11564] pickle not 64-bit ready
Nadeem Vawda nadeem.va...@gmail.com added the comment: How much does it say is required? Did you remove the skips in BigmemPickleTests? Yes, I did remove the skips. It says 2GB for some, and 4GB for others. Well, perhaps I got the logic wrong. Debugging welcome :) I'd be glad to do so, but I'm not sure what the aim of the dryrun flag is. Do you want to make it the default that precisionbigmem tests are skipped, unless the decorator invocation explicitly specifies dryrun=False? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11564 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8617] Better document user site-packages in site module doc
Changes by Éric Araujo mer...@netwok.org: -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8617 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12256] Link isinstance/issubclass doc to abc module
Éric Araujo mer...@netwok.org added the comment: I committed a modified version of the patch. -- resolution: - fixed stage: commit review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11564] pickle not 64-bit ready
Antoine Pitrou pit...@free.fr added the comment: I'd be glad to do so, but I'm not sure what the aim of the dryrun flag is. Do you want to make it the default that precisionbigmem tests are skipped, unless the decorator invocation explicitly specifies dryrun=False? No, the point is to avoid running these tests when -M is not specified. See what happens with other bigmem tests. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11564 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9173] logger statement not guarded in shutil._make_tarball
Éric Araujo mer...@netwok.org added the comment: I fixed this in 615a29295d5f but forgot to mention the bug number in the commit message. To reproduce the bug, I only had to backport two lines from 3.2, so I did not use your patch. Thanks to both of you nonetheless for the report and help! -- assignee: tarek - eric.araujo resolution: - fixed stage: patch review - committed/rejected status: open - closed versions: -Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9173 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12703] Improve error reporting for packaging.util.resolve_name
Changes by Éric Araujo mer...@netwok.org: -- keywords: +easy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12703 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12707] Deprecate addinfourl getters
Ezio Melotti ezio.melo...@gmail.com added the comment: I thought about having another class, but I couldn't come up with a decent name for it (ResponseWithCloseHook?). After all it's still a Response and unless you need a way to distinguish responses with and without close hooks, I think it might be better to have a single class for both. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12707 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10149] Data truncation in expat parser
Fred L. Drake, Jr. f...@fdrake.net added the comment: Chunking of the data is expected with Expat. There are no promises about *where* chunks are broken; the underlying behavior will break at line endings, but is not limited to that. Setting buffer_text informs the Python wrapper that it's allowed to combine the chunks reported by the Expat library; this was made optional since it could affect working applications (changing the default with the move to Python 3 may have been acceptable, though). -- nosy: +fdrake ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10149 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com