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 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 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 - 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" 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 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 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 wrote: > > > ... > > In a web/html environment or in broken ascii-only consoles like the > one on windows ... C:\Users\Jean-Michel>echo 'Cet œuf de Lætitia coûte un €uro' 'Cet œuf de Lætitia coûte un €uro' C:\Users\Jean-Michel>c:\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-Michel>c:\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 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 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 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 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 Yingjie Lin 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 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 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 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 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: 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 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 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 > Mechanize seems like what you want. It's built on top of > urllib2.http://wwwsearch.sourceforge.net/mechanize/ > > From: Chris Rebert > Selenium:http://seleniumhq.org/ > -- http://mail.python.org/mailman/listinfo/python-list
Re: try... except with unknown error types
In Yingjie Lin 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 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 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 wrote: > On Thu, Aug 18, 2011 at 7:44 PM, luvspython 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 is equivalent to > . However, > is equivalent to . > > 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 wrote: > On Fri, 19 Aug 2011 10:15:20 -0700 (PDT), Edgar Fuentes > > > > > > > > > > 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 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 Yingjie Lin > 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 "", line 1, in NameError: name 'foo' is not defined >>> urllib2.HTTPError Traceback (most recent call last): File "", line 1, in 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 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 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 > > 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 Funk 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 > 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 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 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 ...]
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" 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 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 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 | 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 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 > > > 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 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 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 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 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 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 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 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
Re: List spam
Javier writes: > You will lose a lot of people asking/answering interesting stuff, and > maybe eventually the list will die. I don't think it would die, but the chances are greater that it would become insular and further disconnected from the Python community, and hence far less useful. > Me (like many people with little free time) seldom post in > blogs/forums/mailing lists where I need to register. +1 -- \ “Ignorance more frequently begets confidence than does | `\ knowledge.” —Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list