Re: eric not working on ubuntu 9.04
bvidinli wrote: An unhandled exception occurred. Please report the problem using the error reporting dialog or via email to eric4-b...@die-offenbachs.de. A log has been written to /home/bvidinli/.eric4/eric4_error.log. Did you try that? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another list comprehension question
This isn't list comprehension, but it's something to keep in mind: b = filter(lambda x: None not in x, input_list) On Sat, May 2, 2009 at 10:25 PM, CTO debat...@gmail.com wrote: On May 2, 10:13 pm, Ross ross.j...@gmail.com wrote: I'm trying to set up a simple filter using a list comprehension. If I have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)] and I wanted to filter out all tuples containing None, I would like to get the new list b = [(1,2), (3,4),(6,7)]. try this: b = [i for i in a if None not in i] I tried b = [i for i in a if t for t in i is not None] but I get the error that t is not defined. What am I doing wrong? You've got a for and an if backwards. t isn't defined when the if tries to evaluate it. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: writing consecutive data to subprocess command 'more'
Hmm, it works as long as the pager command is available on the system. I created a test file to explain what I mean. You can find it here: http://gist.github.com/105880 The 'pager' command is on purpose a command that is not available on the system. It should fall back to sys.stdout in the write method. However, it does not show any output at all. Strangely enough, when a put a time.sleep(1) between the first and second printer.write statements, the second and third statement do appear. Btw, the normal pager command works fine on my system. How can I solve this, so that the fallback sys.stdout does show output? --- Sander On 2 mei, 23:00, SanPy jhmsm...@gmail.com wrote: Thanks, that works beautifully! Regards, Sander On 2 mei, 22:35, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: communicate writes to the child's stdin and waits for it to finish. If you want to keep writing, don't use communicate. And you'll need to keep state from one call to another, so use a class. Based on the code above, create a class Pager with __init__, write and close methods: class Pager: def __init__(self): # copy the logic above self.proc = subprocess.Popen(...) self.file = self.proc.stdin # if something goes wrong, set self.proc=None and self.file=sys.stdout def write(self, text): self.file.write(text) def close(self): if self.proc: self.file.close() self.proc.wait() Also, take a look at the pager function in the pydoc module (see the source) - it handles several cases. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
On Sat, 02 May 2009 11:01:39 -0700, bearophileHUGS wrote: Esmail: Is there a Python construct to allow me to do something like this: for i in range(-10.5, 10.5, 0.1): Sometimes I use an improved version of this: http://code.activestate.com/recipes/66472/ Care to contribute your improvements back to the recipe? Or at least here? I for one am curious to see how you do it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Doc strings in descriptors
On Sat, 02 May 2009 23:36:26 -0500, Kevin D. Smith wrote: I have a simple descriptor to create a cached property as shown below. ... What do I need to do to get the doc string of the wrapped function to apper when using help()? Call it on the class, not the instance: class Test(object): ... def getx(self): return spam ... def setx(self, value): return None # and do nothing ... x = property(getx, setx, None, This is my docstring) ... t = Test() t.x.__doc__ # like spam.__doc__ 'str(object) - string\n\nReturn a nice string representation of the object.\nIf the argument is a string, the return value is the same object.' Test.x.__doc__ 'This is my docstring' -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
import numpy as np for i in np.arange(-10.5, 10.5, 0.1): ... print i ... -10.5 -10.4 -10.3 -10.2 -- http://mail.python.org/mailman/listinfo/python-list
Re: eric not working on ubuntu 9.04
File /usr/lib/python2.6/email/message.py, line 790, in Message from email.Iterators import walk Well, the module is called email.iterators (rather than email.Iterators), for starters. It looks like __all__ exports both names (which seems a little dodgy to me, but hey, y'all are the experts) but Ubuntu messes with Python a lot before it makes it to a package. I don't have a jaunty box handy, but my guess is that some heinous confluence of email.iterators.walk moving to Message.walk() in python 3, the module email.Iterators not existing anymore, and Ubuntu messing with Python has caused the whole house of cards to come crashing down. If I were you, I'd probably do the following: 1) file a ubuntu bug report 2) see if you can fire up the interpreter and see if the following works: from email.Iterators import walk If not, try it with the 'i' lowercased. If that works, you've got your culprit. Otherwise, let me know and I'll take a look at it when I get back in front of my jaunty box. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: eric not working on ubuntu 9.04
bvidinli wrote: any idea ? It works on my Kubuntu 9.04, but I can provoke a similar error with $ export PYTHONPATH=`pwd` $ touch email.py $ eric As a first step I recommend that you make sure that eric doesn't accidentally import modules written by you. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: stuck with PyOBEX
Yes! I haven't tried to run it under Windows. I just assumed that BluetoothSocket would have the same API on both Linux and Windows. Looking around, it seems that this is something we can work around: http://svn.navi.cx/misc/trunk/laserprop/client/BluetoothConduit.py I'll send you an updated version to try if you would like to test it. David -- http://mail.python.org/mailman/listinfo/python-list
Use of Unicode in Python 2.5 source code literals
I'm working with Python 2.5.4 and the NLTK (Natural Language Toolkit). I'm an experienced programmer, but new to Python. This question arose when I tried to create a literal in my source code for a Unicode codepoint greater than 255. (I also posted this question in the NLTK discussion group). The Python HELP (at least for version 2.5.4) states: +++ Python supports writing Unicode literals in any encoding, but you have to declare the encoding being used. This is done by including a special comment as either the first or second line of the source file: #!/usr/bin/env python # -*- coding: latin-1 -*- Based on some experimenting I've done, I suspect that the support for Unicode literals in ANY encoding isn't really accurate. What seems to happen is that there must be an 8-bit mapping between the set of Unicode literals and what can be used as literals. Even when I set Options / General / Default Source Encoding to UTF-8, IDLE won't allow Unicode literals (e.g. characters copied and pasted from the Windows Character Map program) to be used, even in a quoted string, if they represent an ord value greater than 255. I noticed, in researching this question, that Marc Andre Lemburg stated, back in 2001, Since Python source code is defined to be ASCII... I'm writing code for linguistics (other than English), so I need access to lots more characters. Most of the time, the characters come from files, so no problem. But for some processing tasks, I simply must be able to use real Unicode literals in the source code. (Writing hex escape sequences in a complex regex would be a nightmare). Was this taken care of in the switch from Python 2.X to 3.X? Is there a way to use more than 255 Unicode characters in source code literals in Python 2.5.4? Also, in the Windows version of Python, how can I tell if it was compiled to support 16 bits of Unicode or 32 bits of Unicode? Bruce in Toronto -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Unicode in Python 2.5 source code literals
Uncle Bruce wrote: I'm working with Python 2.5.4 and the NLTK (Natural Language Toolkit). I'm an experienced programmer, but new to Python. This question arose when I tried to create a literal in my source code for a Unicode codepoint greater than 255. (I also posted this question in the NLTK discussion group). The Python HELP (at least for version 2.5.4) states: +++ Python supports writing Unicode literals in any encoding, but you have to declare the encoding being used. This is done by including a special comment as either the first or second line of the source file: #!/usr/bin/env python # -*- coding: latin-1 -*- Based on some experimenting I've done, I suspect that the support for Unicode literals in ANY encoding isn't really accurate. What seems to happen is that there must be an 8-bit mapping between the set of Unicode literals and what can be used as literals. Even when I set Options / General / Default Source Encoding to UTF-8, IDLE won't allow Unicode literals (e.g. characters copied and pasted from the Windows Character Map program) to be used, even in a quoted string, if they represent an ord value greater than 255. I noticed, in researching this question, that Marc Andre Lemburg stated, back in 2001, Since Python source code is defined to be ASCII... I'm writing code for linguistics (other than English), so I need access to lots more characters. Most of the time, the characters come from files, so no problem. But for some processing tasks, I simply must be able to use real Unicode literals in the source code. (Writing hex escape sequences in a complex regex would be a nightmare). Was this taken care of in the switch from Python 2.X to 3.X? Is there a way to use more than 255 Unicode characters in source code literals in Python 2.5.4? Also, in the Windows version of Python, how can I tell if it was compiled to support 16 bits of Unicode or 32 bits of Unicode? Bruce in Toronto Works for me: --- snip --- $ cat snowman.py #!/usr/bin/env python # -*- coding: utf-8 -*- import unicodedata snowman = u'☃' print len(snowman) print unicodedata.name(snowman) $ python2.6 snowman.py 1 SNOWMAN --- snip --- What did you set the encoding to in the declaration at the top of the file? The help text you quoted uses latin-1 as an example, an encoding which, of course, only supports 256 code points. Did you try utf-8 instead? The regular expression engine's Unicode support is a different question, and I do not know the answer. By the way, Python 2.x only supports using non-ASCII characters in source code in string literals. Python 3 adds support for Unicode identifiers (e.g. variable names, function argument names, etc.). -- -- http://mail.python.org/mailman/listinfo/python-list
ANN: pyscite
ANN: pyscite released Download it from: http://code.google.com/p/pyscite/ What is pyscite? Pyscite is a python module for accessing the SciTE editors Director Interface on windows. Example are included with code to integrate the aspell spell checker engine with SciTE. -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Unicode in Python 2.5 source code literals
On Sun, 03 May 2009 03:43:27 -0700, Uncle Bruce wrote: Based on some experimenting I've done, I suspect that the support for Unicode literals in ANY encoding isn't really accurate. What seems to happen is that there must be an 8-bit mapping between the set of Unicode literals and what can be used as literals. Even when I set Options / General / Default Source Encoding to UTF-8, IDLE won't allow Unicode literals (e.g. characters copied and pasted from the Windows Character Map program) to be used, even in a quoted string, if they represent an ord value greater than 255. When you say it won't allow, what do you mean? That you can't paste them into the document? Does it give an error? An exception at compile time or runtime? I assume you have included the coding line at the top of the file. Make sure it says utf-8 and not latin-1. # -*- coding: uft-8 -*- This is especially important if you use a Windows text editor that puts a Unicode BOM at the start of the file. What happens if you use a different editor to insert the characters in the file, and then open it in IDLE? How are you writing the literals? As byte strings or unicode strings? E.g. # filename = nonascii.py theta = 'θ' # byte string, probably will lead to problems sigma = u'Σ' # unicode, this is the Right Way Is there a way to use more than 255 Unicode characters in source code literals in Python 2.5.4? It works for me in Python 2.4 and 2.5, although I'm not using IDLE. import nonascii nonascii.sigma print nonascii.sigma Σ print nonascii.theta θ Perhaps it is a problem with IDLE? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
AutoComplete in C++ Editor for Python
Hello, I am embedding python support in my C++ application and was looking at adding Intellisense or AutoComplete support. I found a way to do it using the dir function, but this creates a problem. Here's why. Let's say I have the following code in my editor: import sys x = sys Now, I would like to get all attributes of the object called 'x'. I can instrument the code and add print dir(x) at the end, temporarily redirect the python output to a string and execute the code. But this is not safe: I do NOT want to execute the code while the user is typing! Is there a way to compile the python code and get access to the symbol table from that compiled block? Did anybody ever implement AutoComplete in a editor for Python? cheers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help with str.replace tuples
On May 2, 6:22 pm, bearophileh...@lycos.com wrote: mikefromvt: I am very very unfamiliar with Python and need to update a Python script. What I need to do is to replace three variables (already defined in the script) within a string. The present script correctly replaces two of the three variables. I am unable to add a third variable. Specifically, I would like to add panoble,panoble to the following code: idxItemStr+=string.replace(string.replace (idxItemTplStr,stylenumber,stylenumber),formalname,formalname) This isn't going to win some contest of coding style quality, but you may try this (for other people: I have not added any new variable name on purpose): idxItemStr += idxItemTplStr.replace(stylenumber, stylenumber).replace(formalname, formalname).replace(panoble, panoble) Note that in Python names are usually written like this: idx_item_tpl Instead of: idxItemTplStr Bye, bearophile Thank you SO MUCH. It works perfectly. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Use of Unicode in Python 2.5 source code literals
On May 3, 7:37 am, Matt Nordhoff mnordh...@mattnordhoff.com wrote: Uncle Bruce wrote: snip -- I think I've figured it out! What I was trying to do was to enter the literal strings directly into the IDLE interpreter. The IDLE interpreter will not accept high codepoints directly. However, when I put a defined function in a separate file with high codepoints, IDLE processes them just fine! display produced the expected Hex strings, and Print displayed the correct characters. Success! -- http://mail.python.org/mailman/listinfo/python-list
Strange interaction between timeit and recursion
I'm seeing a strange interaction between timeit and recursion. sys.getrecursionlimit() 1000 from timeit import Timer setup = def test(n=1): ... if n 999: return test(n+1) ... return None ... exec setup test() is None True Timer('test()', setup).repeat(number=1) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/timeit.py, line 188, in repeat t = self.timeit(number) File /usr/lib/python2.5/timeit.py, line 161, in timeit timing = self.inner(it, self.timer) File timeit-src, line 9, in inner File timeit-src, line 4, in test File timeit-src, line 4, in test File timeit-src, line 4, in test ... File timeit-src, line 4, in test I don't understand why my recursive function hits the recursion limit inside the timeit.Timer when it works outside of it. Is there any way to see the current recursion depth at a particular moment? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Using Help inside Python
Hi, I have an idea of the basics of programming language in general. How to access help in python i.e. help followed by something or to get to know about some inbuilt module or method etc. how do I access help from within the IDLE using the help command. Thank You. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with money datatype based calculations in python
On Sun, 2009-05-03 at 03:20 +, D'Arcy J.M. Cain wrote: Sorry, I should have mentioned my bias. :-) No problems at all. It is a very good library. I get an impression that it is realy a mature module and a very powerful set of API. I would like to know if it has been tested with postgresql 8.3 and are The current version of PyGreSQL has been tested with Python 2.5 and PostGreSQL 8.3. Older version should work as well, but you will need at least Python 2.3 and PostgreSQL 7.4. Ah, I am using python 2.6 and postgresql 8.3 I am really impressed with the library. I want some manual or tutorial for the same and if possible can you write me off the list with a small tutorial for things like connecting to the database, sending queries, and working with the resultset at the client site. I will be really happy if this library also supports calling a stored procedurs directly. Psycopg2 does not have such a feature and I had to create one small module which does that work. What it does is that you just give the name of the procuedure procedure as the first parameter and a list of arguements as the second parameter. That's all, you will get the result because the query for the call is created inside the module and the programmer need not worry about what the sored procedure looks like. Never the less I am expecting that pygresql has some infrastructure for making calls to the stored procedures. Please send me some tutorial off the list. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
smtplib send email by using gmail smtp server
Hi all I'm tring send email using smtp.gmail.com here's the code: *s = SMTP('**smtp.gmail.com* http://smtp.gmail.com/*', 25) s.set_debuglevel(1)* *s.ehlo() s.starttls() s.ehlo() s.login(mygmailaccount, mygmailpassword) s.sendmail(from_addr, to_addr_list, message) s.close()* I got the following: *send: 'ehlo [192.168.1.104]\r\n' reply: b'**250-mx.google.com* http://250-mx.google.com/* at your service, [58.39.112.163]\r\n' reply: b'250-SIZE 35651584\r\n' reply: b'250-8BITMIME\r\n' reply: b'250-STARTTLS\r\n' reply: b'250-ENHANCEDSTATUSCODES\r\n' reply: b'250 PIPELINING\r\n' reply: retcode (250); Msg: b'**mx.google.com* http://mx.google.com/* at your service, [58.39.112.163]\nSIZE 35651584\n8BITMIME\nSTARTTLS\nENHANCED STATUSCODES\nPIPELINING' send: 'STARTTLS\r\n' reply: b'220 2.0.0 Ready to start TLS\r\n' reply: retcode (220); Msg: b'2.0.0 Ready to start TLS'* After a long time waiting I got: *Traceback (most recent call last): ... File sendmail.py, line 56, in send_mail s.starttls() File C:\usr\bin\python30\lib\smtplib.py, line 619, in starttls self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) File C:\usr\bin\python30\lib\ssl.py, line 381, in wrap_socket suppress_ragged_eofs=suppress_ragged_eofs) File C:\usr\bin\python30\lib\ssl.py, line 135, in __init__ raise x File C:\usr\bin\python30\lib\ssl.py, line 131, in __init__ self.do_handshake() File C:\usr\bin\python30\lib\ssl.py, line 327, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [Errno 8] _ssl.c:486: EOF occurred in violation of protocol* After this I tried port 465, I got no debug messages like send... reply..., and after a long time waiting the following exception occured: *Traceback (most recent call last): ...* * File sendmail.py, line 49, in send_mail s = SMTP('smtp.gmail.com', 465) File C:\usr\bin\python30\lib\smtplib.py, line 239, in __init__ (code, msg) = self.connect(host, port) File C:\usr\bin\python30\lib\smtplib.py, line 296, in connect (code, msg) = self.getreply() File C:\usr\bin\python30\lib\smtplib.py, line 342, in getreply raise SMTPServerDisconnected(Connection unexpectedly closed) smtplib.SMTPServerDisconnected: Connection unexpectedly closed* Am I doing something wrong? I'm using python30 and python31a2 under Windows XP thanks! Tiefeng Wu 2009-05-03 -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Help inside Python
On Sun, 03 May 2009 07:49:49 -0700, rose wrote: Hi, I have an idea of the basics of programming language in general. How to access help in python i.e. help followed by something or to get to know about some inbuilt module or method etc. how do I access help from within the IDLE using the help command. Thank You. At the prompt, type any of: help() help(module) help(function) help(any_object) help(keyword) # note the quotes around the keyword then hit Enter to get help about that object or keyword. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange interaction between timeit and recursion
Steven D'Aprano schrieb: I'm seeing a strange interaction between timeit and recursion. sys.getrecursionlimit() 1000 from timeit import Timer setup = def test(n=1): ... if n 999: return test(n+1) ... return None ... exec setup test() is None True Timer('test()', setup).repeat(number=1) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/timeit.py, line 188, in repeat t = self.timeit(number) File /usr/lib/python2.5/timeit.py, line 161, in timeit timing = self.inner(it, self.timer) File timeit-src, line 9, in inner File timeit-src, line 4, in test File timeit-src, line 4, in test File timeit-src, line 4, in test ... File timeit-src, line 4, in test I don't understand why my recursive function hits the recursion limit inside the timeit.Timer when it works outside of it. Is there any way to see the current recursion depth at a particular moment? import inspect def rec(count=100): if not count: return print len(inspect.getouterframes(inspect.currentframe())) rec(count-1) rec() Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: stuck with PyOBEX
On Sunday 03 May 2009 10:33, alejandro wrote: Yes! I'll send you an updated version to try if you would like to test it. My mails to you keep getting returned, so I've put it here: http://www.boddie.org.uk/david/Projects/Python/PyOBEX/Software/PyOBEX-0.21.zip Please let me know if it works on Windows, and feel free to get in touch if you have any problems. David -- http://mail.python.org/mailman/listinfo/python-list
Re: File handling problem.
Dear Group, I am working on a code like the following: from decimal import* #SAMPLE TEST PROGRAM FOR FILE def sample_file_test(n): #FILE FOR STORING PROBABILITY VALUES open_file=open(/python26/Newfile1.txt,r+) #OPENING OF ENGLISH CORPUS open_corp_eng=open(/python26/TOTALENGLISHCORPUS1.txt,r) #READING THE ENGLISH CORPUS corp_read=open_corp_eng.read() #CONVERTING THE CORPUS FILE IN WORDS corp_word=corp_read.split() #EXTRACTING WORDS FROM CORPUS FILE OF WORDS for word in corp_word: #COUNTING THE WORD count1=corp_word.count(word) #COUNTING TOTAL NUMBER OF WORDS count2=len(corp_word) #COUNTING PROBABILITY OF WORD count1_dec=Decimal(count1) count2_dec=Decimal(count2) getcontext().prec = 6 prob_count=count1_dec/count2_dec print prob_count string_of_prob_count=str(prob_count) file_input_val=open_file.write(string_of_prob_count) open_file.close() The problems I am getting: (i) The probability values are not being stored properly in file. (ii)“Newfile1.txt” is storing not the series of values but an arbitrary value from series 0.0143096 (iii) As I was testing it again it gave me another error Traceback (most recent call last): File pyshell#2, line 1, in module sample_file_test(1) File C:\Python26\testprogramforfiles1.py, line 25, in sample_file_test file_input_val=open_file.write(string_of_prob_count) ValueError: I/O operation on closed file If you can kindly let me know what is the wrong I am doing here. As I took out the code pasted it in MS-Word before posting, there may be slight indentation problem. Best Regards, Subhabrata. On Sat, May 2, 2009 at 2:16 PM, Pascal Chambon chambon.pas...@wanadoo.frwrote: subhakolkata1...@gmail.com a écrit : Dear Group, I am using Python2.6 and has created a file where I like to write some statistical values I am generating. The statistical values are generating in a nice way, but as I am going to write it, it is not taking it, the file is opening or closing properly but the values are not getting stored. It is picking up arbitrary values from the generated set of values and storing it. Is there any solution for it? Best Regards, SBanerjee. -- http://mail.python.org/mailman/listinfo/python-list Hello Could you post excerpt of your file-handling code ? It might be a buffering problem (although when the file closes, I think buffers get flushed), else it's really weird... Regards, pascal -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure the memory cost in Python?
In article 7744f434-dd43-4010-ba25-90096f59d...@n7g2000prc.googlegroups.com, CTO debat...@gmail.com wrote: I will admit, I have *no idea* what that code is doing, but in looking through the gc module documentation, I'm seeing the gc.get_objects function. Would it be equivalent to what the OP is asking to track the size of every element returned by that? Perhaps. gc.get_objects() only returns objects tracked by GC (i.e. containers). You would need to also check all the object references held by the containers. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Typing is cheap. Thinking is expensive. --Roy Smith -- http://mail.python.org/mailman/listinfo/python-list
Reg: MFC71.DLL
Hi, I had written a python 2.4 program. When I made it to an executable with py2exe, it told that the mfc71.dll is not added - so I may have to ship it separately. It also showed many other dll's which are all in windows/system32 - which again it said is not added. Now, I have two questions - (1) Should I include mfc71.dll separately? - I found in the following dicsussion - http://groups.google.com/group/comp.lang.python/browse_thread/thread/96933f0b9a1a0f12/887675601f5c5c63 - that mfc71 might not be needed. Should I ship it separately? (2) The dlls in windows/system32 - do I need to ship it separately? Koran -- http://mail.python.org/mailman/listinfo/python-list
Re: File handling problem.
On Sun, May 3, 2009 at 9:51 AM, SUBHABRATA BANERJEE subhakolkata1...@gmail.com wrote: Dear Group, I am working on a code like the following: from decimal import* #SAMPLE TEST PROGRAM FOR FILE def sample_file_test(n): #FILE FOR STORING PROBABILITY VALUES open_file=open(/python26/Newfile1.txt,r+) Is there a reason you must output the results to the same file the input came from? It's possible this is part of your problems. #OPENING OF ENGLISH CORPUS open_corp_eng=open(/python26/TOTALENGLISHCORPUS1.txt,r) #READING THE ENGLISH CORPUS corp_read=open_corp_eng.read() #CONVERTING THE CORPUS FILE IN WORDS corp_word=corp_read.split() #EXTRACTING WORDS FROM CORPUS FILE OF WORDS for word in corp_word: #COUNTING THE WORD count1=corp_word.count(word) Note: Your program is currently O(N^2) rather than O(N) because you re-count the number of occurrences of each word /on every occurrence of the word/. #COUNTING TOTAL NUMBER OF WORDS count2=len(corp_word) #COUNTING PROBABILITY OF WORD count1_dec=Decimal(count1) count2_dec=Decimal(count2) getcontext().prec = 6 prob_count=count1_dec/count2_dec print prob_count string_of_prob_count=str(prob_count) file_input_val=open_file.write(string_of_prob_count) open_file.close() You shouldn't be closing the file until the /entire loop/ has finished writing to the file. So the previous line should be dedented. The problems I am getting: (i) The probability values are not being stored properly in file. Also, you're currently not putting any separator between consecutive entires, so it's all going to run together as one long line. Have you considered using one of the std lib modules to output the file in a well-defined human-readable format such as JSON or CSV? (ii) “Newfile1.txt” is storing not the series of values but an arbitrary value from series 0.0143096 (iii) As I was testing it again it gave me another error Traceback (most recent call last): File pyshell#2, line 1, in module sample_file_test(1) File C:\Python26\testprogramforfiles1.py, line 25, in sample_file_test file_input_val=open_file.write(string_of_prob_count) ValueError: I/O operation on closed file Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to measure the memory cost in Python?
Alright, it's pretty obvious that I have a lot to learn before I'll be able to intelligently address this problem, but if somebody could point me at something that would help me figure out the terminology at least I'd really appreciate it. From what you're saying, it sounds like a combination of the above approaches would do what I'm asking- ie, get all the containers, then get the contents of each container- but I don't see why that would work unless gc tracks some kind of global container for small values, which, as I (poorly) understand it, are tracked separately? Thanks again, Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: File handling problem.
Dear Sir, Thanx for your prompt reply, I would be trying to work on your suggestion and get back to you as soon as possible. Best Regards, Subhabrata. On Sun, May 3, 2009 at 10:47 PM, Chris Rebert c...@rebertia.com wrote: On Sun, May 3, 2009 at 9:51 AM, SUBHABRATA BANERJEE subhakolkata1...@gmail.com wrote: Dear Group, I am working on a code like the following: from decimal import* #SAMPLE TEST PROGRAM FOR FILE def sample_file_test(n): #FILE FOR STORING PROBABILITY VALUES open_file=open(/python26/Newfile1.txt,r+) Is there a reason you must output the results to the same file the input came from? It's possible this is part of your problems. #OPENING OF ENGLISH CORPUS open_corp_eng=open(/python26/TOTALENGLISHCORPUS1.txt,r) #READING THE ENGLISH CORPUS corp_read=open_corp_eng.read() #CONVERTING THE CORPUS FILE IN WORDS corp_word=corp_read.split() #EXTRACTING WORDS FROM CORPUS FILE OF WORDS for word in corp_word: #COUNTING THE WORD count1=corp_word.count(word) Note: Your program is currently O(N^2) rather than O(N) because you re-count the number of occurrences of each word /on every occurrence of the word/. #COUNTING TOTAL NUMBER OF WORDS count2=len(corp_word) #COUNTING PROBABILITY OF WORD count1_dec=Decimal(count1) count2_dec=Decimal(count2) getcontext().prec = 6 prob_count=count1_dec/count2_dec print prob_count string_of_prob_count=str(prob_count) file_input_val=open_file.write(string_of_prob_count) open_file.close() You shouldn't be closing the file until the /entire loop/ has finished writing to the file. So the previous line should be dedented. The problems I am getting: (i) The probability values are not being stored properly in file. Also, you're currently not putting any separator between consecutive entires, so it's all going to run together as one long line. Have you considered using one of the std lib modules to output the file in a well-defined human-readable format such as JSON or CSV? (ii)“Newfile1.txt” is storing not the series of values but an arbitrary value from series 0.0143096 (iii) As I was testing it again it gave me another error Traceback (most recent call last): File pyshell#2, line 1, in module sample_file_test(1) File C:\Python26\testprogramforfiles1.py, line 25, in sample_file_test file_input_val=open_file.write(string_of_prob_count) ValueError: I/O operation on closed file Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: smtplib send email by using gmail smtp server
En Sun, 03 May 2009 12:18:33 -0300, tiefeng wu iceberg...@gmail.com escribió: I'm tring send email using smtp.gmail.com here's the code: *s = SMTP('**smtp.gmail.com* http://smtp.gmail.com/*', 25) s.set_debuglevel(1)* *s.ehlo() s.starttls() s.ehlo() s.login(mygmailaccount, mygmailpassword) s.sendmail(from_addr, to_addr_list, message) s.close()* I've tested with 3.0.1 on Windows XP and worked fine. Seems to be a problem in the SSL support, but that's all I could say. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: AutoComplete in C++ Editor for Python
flam...@gmail.com wrote: Hello, I am embedding python support in my C++ application and was looking at adding Intellisense or AutoComplete support. I found a way to do it using the dir function, but this creates a problem. Here's why. Let's say I have the following code in my editor: import sys x = sys Now, I would like to get all attributes of the object called 'x'. I can instrument the code and add print dir(x) at the end, temporarily redirect the python output to a string and execute the code. But this is not safe: I do NOT want to execute the code while the user is typing! Is there a way to compile the python code and get access to the symbol table from that compiled block? Did anybody ever implement AutoComplete in a editor for Python? cheers. Several editors for Python support auto-complete, to one extent or another. The only one I have experience with is Komodo. Komodo runs in a separate process, so it doesn't suffer from the problems of having two gui event-loops in the same process, and other similar problems. It also won't be executing code that might have side effects in the child process. The downside is that in order to do auto-complete, it has to figure it out from other clues. From the docs, and from reading, and from experiementing, I believe that it uses two approaches. One approach is a set of language files which try to describe all the symbols in the standard language and library. They have one for each release (2.4, 2.5, ...) Theoretically, you could add your own for other libraries. Second approach is to parse the code that's visible to it. That parsing is well done, and surprisingly quick, but there are lots of tricks a developer might use that can fool it. For example, wxPython lets you import just one symbol, and lots more appear magically. It's no big deal, they have code structured one way, but the interface is very different. Catch is that code completion frequently gets fooled by these. I'd point out that if you do walk the dictionaries at run time, you'll get different results when you do it with nothing running than if you do a strictly static analysis. So some things might only show up if you've stepped into the function with the magic going on. Simplest example I can come up with of something a static analysis won't spot: An instance objectobj may have some number of attributes assigned the the __init__() method. But it could also have new fields added by anyone with a referent into it. There is a Python parser in module ast. Perhaps that'd be some help. I've not used it, so can't give you any specifics. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Is it better to use threads or fork in the following case
Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
grocery_stocker schrieb: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Help inside Python
On May 3, 8:15 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 03 May 2009 07:49:49 -0700, rose wrote: Hi, I have an idea of the basics of programming language in general. How to access help in python i.e. help followed by something or to get to know about some inbuilt module or method etc. how do I access help from within the IDLE using the help command. Thank You. At the prompt, type any of: help() help(module) help(function) help(any_object) help(keyword) # note the quotes around the keyword then hit Enter to get help about that object or keyword. -- Steven Many Thanks to you Steven, for such a concise explanation of using the help. May I request some examples to make it a bit more explicit. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
On May 3, 1:16 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Okay, here is what was going through my mind. I'm a 56k dialup modem. What happens it takes me 15 minutes to download the file? Now let's say during those 15 minutes, the program needs to parse the data in the existing file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
grocery_stocker schrieb: On May 3, 1:16 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Okay, here is what was going through my mind. I'm a 56k dialup modem. What happens it takes me 15 minutes to download the file? Now let's say during those 15 minutes, the program needs to parse the data in the existing file. Is this an exercise in asking 20 hypothetical questions? Getting concurrency right isn't trivial, so if you absolute don't need this, don't do it. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
There is no need for a function or a generator. A for() loop is a unique case of a while loop ## for i in range(-10.5, 10.5, 0.1): ctr = -10.5 while ctr 10.5: print ctr ctr += 0.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
Probably better just to check HEAD and see if its updated within the time you're looking at before any unpack. Even on a 56k that's going to be pretty fast, and you don't risk unpacking an old file while a new version is on the way. If you still want to be able to unpack the old file if there's an update then you're probably right about needing to run it concurrently, and personally I'd just fork it for ease of use- it doesn't sound like you're trying to run 100,000 of these at the same time, and you're saving the file anyway. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
On May 3, 10:29 pm, grocery_stocker cdal...@gmail.com wrote: On May 3, 1:16 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Okay, here is what was going through my mind. I'm a 56k dialup modem. What happens it takes me 15 minutes to download the file? Now let's say during those 15 minutes, the program needs to parse the data in the existing file. If your modem is going at full speed for those 15 minutes, you'll have around 6.3Mb of data. Even after decompressing, and unless the data is in some quite difficult to parse format, it'll take seconds to process. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
Zentrader wrote: There is no need for a function or a generator. A for() loop is a unique case of a while loop ## for i in range(-10.5, 10.5, 0.1): ctr = -10.5 while ctr 10.5: print ctr ctr += 0.1 Python stores floats in binary, and 0.1 can't be held exactly as a fractional binary number. Therefore it might be better to produce the values as integers divided by 10: for i in range(-105, 105): i = i / 10.0 # do stuff here using i -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
On May 3, 1:40 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: On May 3, 1:16 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Okay, here is what was going through my mind. I'm a 56k dialup modem. What happens it takes me 15 minutes to download the file? Now let's say during those 15 minutes, the program needs to parse the data in the existing file. Is this an exercise in asking 20 hypothetical questions? No. This the prelude to me writing a real life python program. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
En Sun, 03 May 2009 17:45:36 -0300, Paul Hankin paul.han...@gmail.com escribió: On May 3, 10:29 pm, grocery_stocker cdal...@gmail.com wrote: On May 3, 1:16 pm, Diez B. Roggisch de...@nospam.web.de wrote: grocery_stocker schrieb: Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? Neither. Why do you think you need concurrency at all? Okay, here is what was going through my mind. I'm a 56k dialup modem. What happens it takes me 15 minutes to download the file? Now let's say during those 15 minutes, the program needs to parse the data in the existing file. If your modem is going at full speed for those 15 minutes, you'll have around 6.3Mb of data. Even after decompressing, and unless the data is in some quite difficult to parse format, it'll take seconds to process. In addition, the zip file format stores the directory at the end of the file. So you can't process it until it's completely downloaded. Concurrency doesn't help here. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
In addition, the zip file format stores the directory at the end of the file. So you can't process it until it's completely downloaded. Concurrency doesn't help here. Don't think that's relevant, if I'm understanding the OP correctly. Lets say you've downloaded the file once and you're doing whatever the app does with it. Now, while that's happening the half an hour time limit comes up. Now you want to start another download, but you also want to continue to work with the old version. Voila, concurrency. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it better to use threads or fork in the following case
grocery_stocker wrote: Let's say there is a new zip file with updated information every 30 minutes on a remote website. Now, I wanna connect to this website every 30 minutes, download the file, extract the information, and then have the program search the file search for certain items. Would it be better to use threads to break this up? I have one thread download the data and then have another to actually process the data . Or would it be better to use fork? I concur with Diez that I don't think threading/forking will bring significant advantages for this particular case. That said, if you are thinking from a responsiveness perspective, I would definitely say threading. If you ask from a performance perspective I would need to know what OS you are running (that is is if forking is even supported) and if you have multiple CPU's and if you are actually planning on spawning that sub-process on a (possibly) a different CPU as the parent process. So the workflow would be something like this: Downloading block If block has enough data to process, spawn a new process (using multiprocessing module) and let it write the result back to x (requiring lock and release). Things to keep in mind, is the overhead of: - Multiple interpreters running on the multiple CPU's - IPC - Locking/Releasing Still less then if you would have no threading at all? About forking, this usually means that the child process starts out as an exact copy of the parent process and runs ideally mostly independent of the parent meaning that the best case would be that the child process can run fine without the presents of the parent process, is this really what you want to do? -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Self function
Sometimes I rename recursive functions, or I duplicatemodify them, and they stop working because inside them there's one or more copy of their old name. This happens to me more than one time every year. So I have written this: from inspect import getframeinfo, currentframe def SOMEVERYUGLYNAME(n): if n = 1: return 1 else: self_name = getframeinfo(currentframe()).function #self_name = getframeinfo(currentframe())[2] # older python # only if it's a global function #return n * globals()[self_name](n - 1) return n * eval(self_name + (%d) % (n - 1)) assert SOMEVERYUGLYNAME(6) == 2*3*4*5*6 Are there nicer ways to do that? I don't know. If there aren't, then a way may be added. An idea-syntax: def fact(n): return 1 if n = 1 else n * inspect.self(n - 1) Or even a lambda, because you don't need the name anymore to call the function: fact = lambda n: 1 if n = 1 else n * self(n - 1) (If you have two or more recursive functions that call each other this idea can't be used, but I think such situations are uncommon enough to not deserve help from the language). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Help inside Python
On Sun, 03 May 2009 21:21:49 +0100, rose rose.0...@gmail.com wrote: On May 3, 8:15 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sun, 03 May 2009 07:49:49 -0700, rose wrote: Hi, I have an idea of the basics of programming language in general. How to access help in python i.e. help followed by something or to get to know about some inbuilt module or method etc. how do I access help from within the IDLE using the help command. Thank You. At the prompt, type any of: help() help(module) help(function) help(any_object) help(keyword) # note the quotes around the keyword then hit Enter to get help about that object or keyword. Many Thanks to you Steven, for such a concise explanation of using the help. May I request some examples to make it a bit more explicit. I'll try and expand on Steven's examples a bit, but really help() gives you quite a lot of the information anyway. If you want help on the for keyword, for example, type: help(for) (As Steven said, note the quote marks.) If you want help on anything else in Python at all, be it a function, module or object, then stick that object in the brackets. Thus: help(123) tells you all about Python's integers, while l = [1, 2, 3] help(l) tells you about lists. The only gotcha is that if you try getting help on a string object, it thinks that you're trying to look up a keyword. In other words: s = for help(s) and help(for) get the same message. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Tkinter, Trouble with Message,Label widget
Intended action: Two Tkinter windows. W1 is complex, user interacts with program from here ONLY W2 is for display only, NO user interactions I can get info to W2. But to get it to update I first have to manually kill it. Program does create both. Both terminate when programs says. I want to post 'verbal' (text) progress reports to W2 and I want it to self update at posting. (Or at least appear to do so to the user.) If a control sequence is changed, the posting is to reflect it. As long as I manually kill it, everything works fine, but I get: 1) finger cramps 2) quite uhhh... 'unhappy' at the stupidity requiring that... There has to be some way of using a Message or Label (or some) widget as a simple posting board. I have been using the python print statement (via what Windows calls a Command Window) quite nicely in Linux. Under Linux only I would be content to go that route. Unfortunately the program also has to work in MicroSoft. And Microsoft has much to much of the old dinosaur age still in it. Why the posting board? 1) It posts for visual inspection the current controls chosen. A tally, a synopsis of the current choice pattern. 2) It remains visible while the control panel vanishes to give the user the full screen to conduct the rest of the human interface with vendor's product. It reminds the user of what is to happen next. 3) On re-display of main control screen the posting again functions as in 1) above. Thus serving as a reminder of What I did last, because it does not change until a button is pressed, as well as What I'm about to do. This can't be the first time someone has needed this. But I have not found (probably just plain missed) it in all Tkinter references I have been able to find. I have tried: ... (overhead) a= StringVar() p=string with formatting, variables and new lines a.set(p) ... Label(root, textvar= '%s%s...' % p[:], and a number of other things and either it fails completely, looks horrible or generates lots of horrible messages telling me it don't like me because I'm not allowed to do that. :) print '%s%s%...' % p[:] works in any Command Window, Linux or MS The ...Label(... text= '%s%s%...' % p[:], works if I manually destroy the posting window to get each update. I think I need a way to generate the W2 and exit leaving it visible. Question is HOW? Or what is needed to effect the same? Then the update can destroy old one and put up new one. ANY help is appreciated. Using: Python 2.5.2, Linux Slackware 10.2 Today: 20090503 Snippets: non functional, for clarifying only Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Help inside Python
On Sun, 03 May 2009 13:21:49 -0700, rose wrote: Many Thanks to you Steven, for such a concise explanation of using the help. May I request some examples to make it a bit more explicit. Suppose you want to get help about the max() function. Inside IDLE, at the command prompt, type: help(max) ENTER where ENTER means press the ENTER key. If you want help about the min() function instead, type: help(min) ENTER If you have an object called parrot, and you want to get help about that object, do this: help(parrot) ENTER If you just want general help about everything, type: help() ENTER and follow the instructions on screen. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: return functions
You seem to have finally discovered that when using Apache/mod_wsgi, Apache does a level of URL matching to filesystem based resources. didn't Paste include something like that ... This isn't automatic in normal WSGI servers unless you use a WSGI middleware that does the mapping for you. :-) finally found it http://pythonpaste.org/modules/urlparser.html -- дамјан ( http://softver.org.mk/damjan/ ) Begin...the rest is easy. -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
On Sun, 03 May 2009 13:41:49 -0700, Zentrader wrote: There is no need for a function or a generator. A for() loop is a unique case of a while loop ## for i in range(-10.5, 10.5, 0.1): ctr = -10.5 while ctr 10.5: print ctr ctr += 0.1 To match the semantics of range(), the final value to ctr must be less than but not equal to 10.5. print ctr 10.6 Your solution does not do this -- it goes one steps too many, and then misleadingly fails to print the value. This is a bug waiting to hit, any time somebody runs your loop then goes to use ctr outside the loop. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Doc strings in descriptors
I have a simple descriptor to create a cached property as shown below. ... The problem is that when I use the help() function on them, I don't get the doc string from the function that is being wrapped. ... What do I need to do to get the doc string of the wrapped function to apper when using help()? take a look at http://pypi.python.org/pypi/decorator and possibly http://docs.python.org/library/functools.html#functools.update_wrapper -- дамјан ( http://softver.org.mk/damjan/ ) Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies. -- Linus Torvalds -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
En Sun, 03 May 2009 17:41:49 -0300, Zentrader zentrad...@gmail.com escribió: There is no need for a function or a generator. A for() loop is a unique case of a while loop ## for i in range(-10.5, 10.5, 0.1): ctr = -10.5 while ctr 10.5: print ctr ctr += 0.1 Isn't so easy. You have representation errors and rounding errors here, and they accumulate. The last number printed should be 10.4 but I get 10.5: ... 10.3 10.4 10.5 (or more precisely, 10.459) Also, after exiting a for loop, the *last* value used is retained. In your while loop, the ctr variable contains the *next* value. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
On 5/3/2009 3:39 PM bearophileh...@lycos.com said... Sometimes I rename recursive functions, or I duplicatemodify them, and they stop working because inside them there's one or more copy of their old name. This happens to me more than one time every year. So I have written this: from inspect import getframeinfo, currentframe def SOMEVERYUGLYNAME(n): if n = 1: return 1 else: self_name = getframeinfo(currentframe()).function #self_name = getframeinfo(currentframe())[2] # older python # only if it's a global function #return n * globals()[self_name](n - 1) return n * eval(self_name + (%d) % (n - 1)) assert SOMEVERYUGLYNAME(6) == 2*3*4*5*6 Are there nicer ways to do that? I've sometimes used classes like: class SOMEVERYUGLYNAME: def __call__(self,n): if n=1: return 1 else: return n*self.__class__()(n-1) assert SOMEVERYUGLYNAME()(6) == 2*3*4*5*6 It's probably nicer (for some definition of nice), but I wouldn't say it's nice. Emile -- http://mail.python.org/mailman/listinfo/python-list
Re: Doc strings in descriptors
En Sun, 03 May 2009 20:58:19 -0300, Дамјан Георгиевски gdam...@gmail.com escribió: I have a simple descriptor to create a cached property as shown below. ... The problem is that when I use the help() function on them, I don't get the doc string from the function that is being wrapped. ... What do I need to do to get the doc string of the wrapped function to apper when using help()? take a look at http://pypi.python.org/pypi/decorator and possibly http://docs.python.org/library/functools.html#functools.update_wrapper That doesn't help. The descriptor *does* have its docstring copied from the function. But pydoc (the module behind the help system) doesn't handle the case - normal properties are handled specially, but a generic descriptor like that is not understood. (and it's not so easy to fix - pydoc does a lot of things, all intermixed: it tries to discover all methods and attributes, determine which are relevant, extract documentation from them, organize and clasify such documentation, generate HTML files/text files/present it to the user/run a webserver/invoke the pager... Too much for my taste, but I disgress...) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
python docs for beginner programmer?
Starting to learn python and because i don't want to read something twice (i get bored quickly) i need a source to learn python that is as comprehensive as possible. Do you think python online docs are good starting point for me? ( i experience with other programming languages ) or should i get giant book or something ? thankx -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs for beginner programmer?
In message deb7353b-19f7-48d7-9777-92b02eed7...@r3g2000vbp.googlegroups.com, Deep_Feelings wrote: Do you think python online docs are good starting point for me? Why not try them and see? -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs for beginner programmer?
On May 4, 3:44 am, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message deb7353b-19f7-48d7-9777-92b02eed7...@r3g2000vbp.googlegroups.com, Deep_Feelings wrote: Do you think python online docs are good starting point for me? Why not try them and see? thank you should i try them then after a month of reading i discover that they are - for example - not suitable for beginners OR should i ask here first ? :) -- http://mail.python.org/mailman/listinfo/python-list
How to walk up parent directories?
Is there already a tool in the standard library to let me walk up from a subdirectory to the top of my file system? In other words, I'm looking for something like: for x in walkup('/home/matt/projects'): ... print(x) /home/matt/projects /home/matt /home / I know I could build something like this with various os.path components, but I'm hoping I don't have to. TIA Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs for beginner programmer?
Deep_Feelings doctore...@gmail.com writes: should i try them then after a month of reading i discover that they are - for example - not suitable for beginners OR should i ask here first ? :) You should take on the task of educating yourself. The official Python docs are an excellent resource. If you're self-admittedly someone who gets bored quickly, though, that's not a problem anyone but you can solve. -- \ “It seems intuitively obvious to me, which means that it might | `\ be wrong.” —Chris Torek | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs for beginner programmer?
Hey, I am a person who gets bored too quickly, too especially reading technical materials, and if the author(s) have the habit of wondering off the subject often. So far, I like Wesley Chun's Core Python book the most as a Python beginner like you. He also has video training material on the same subject. Easy to read, very well explanations and good chosen examples... That said, after getting a few months of familiarity, I want to get into the roots of the Python. So where else could be the best choice but the actual language user guide and reference manual :) Enjoy your Python programming adventures... Gökhan On Sun, May 3, 2009 at 7:41 PM, Deep_Feelings doctore...@gmail.com wrote: Starting to learn python and because i don't want to read something twice (i get bored quickly) i need a source to learn python that is as comprehensive as possible. Do you think python online docs are good starting point for me? ( i experience with other programming languages ) or should i get giant book or something ? thankx -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: How to walk up parent directories?
Matthew Wilson m...@tplus1.com writes: Is there already a tool in the standard library to let me walk up from a subdirectory to the top of my file system? Sounds like a pretty seldom-needed task, with an implementation simple using the existing standard library parts. In other words, I'm looking for something like: for x in walkup('/home/matt/projects'): ... print(x) /home/matt/projects /home/matt /home / import os.path def walkup(path): ... at_top = False ... while not at_top: ... yield path ... parent_path = os.path.dirname(path) ... if parent_path == path: ... at_top = True ... else: ... path = parent_path ... for dir in walkup('/home/matt/projects'): ... print dir ... /home/matt/projects /home/matt /home / I know I could build something like this with various os.path components, but I'm hoping I don't have to. Not every simple function belongs in the standard library :-) -- \“Ubi dubium, ibi libertas.” (“Where there is doubt, there is | `\freedom.”) | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
pythonic chew toyz (continued)
On Sun, May 3, 2009 at 5:52 PM, kirby kirby.ur...@gmail.com wrote: From: kirby.ur...@gmail.com kirby.ur...@gmail.com Date: Jan 14, 2:18 pm Subject: pythonic chew toyz (a column, by K. Urner) v.1 n.1 To: comp.lang.python Selena spotted me right away as the O'Reilly spy, me agreeing she had an exceptionally good memory, maybe we could recruit her? Our banter traces to the first meeting on OS Bridge and how I introduced myself [0], not yet realizing Allison Randal was in the audience (way more an insider, as to how many Ls in Randall).[1] Selena kindly welcomed us into her home for an OS Bridge meeting awhile back, where we tackled the daunting task of sorting through a great many interesting proposals, mine barely squeaking by (yes, helps to have a self interested party at the table, I don't deny it). Audrey was a strong advocate for Allison Randal's getting to speak, but of course that's a shoe in. I'm more the maverick, not having invented any virtual machines yet, just a lot of verbiage mostly, with source code sprinkled in (syntactic sugar we call it). Selena is a Postgres jock many of you may already know. http://www.chesnok.com/daily/ Take a look for news on the new Sun - Oracle merger (yes we know, MySQL). Audrey is with our Legion of Tech especially in the Rails community (which Kaplan-Moss said some nice things about). Together these two are anchoring OS Bridge, our new Open Source conference in Oregon, the Pacific Northwest always in the mood for some big geeky festival, with lots of fun themes, like FOSS on the Farm. http://opensourcebridge.org/sessions/240 Last night in the Roman room (CubeSpace) I proposed she could emcee the panel we're planning (maybe?), after the new Mayor (Sam Adams) kicks it off with a keynote -- all in the proposal stage, looking over her shoulder. Sam got rather famous after I posted this or was it before I forget, but a Wild West town like ours is supposed to go overboard into various forms of burlesque, player piano optional, maybe a few head turning cross-dressers (truly, PDX is proud of its heritage, think our airport is pretty spiffy, plus Ikea, other destinations, take the Max, Go By Train, very green). I was also there for the __metaclasses__ discussion by John Melesky, and for work, most of that same day (this is PDX CubeSpace, a lot of us rent office space). Jason talked about the __missing__ rib (in dict).[2] As we were getting settled, they talked about OSCON, perking my interest. Whereas some take the view we're somehow competing with San Jose (where some of my friends work, or worked in the case of Maxtor and IBM), my model is more Cirque du Soleil, given where geeks come from (something about chickens).[3] I haven't decided about OSCON yet, would love to go, love the show, but this retarded economy has me showing my bank every move, no suitcases of cash like before (just kidding). Seriously, that O'Reilly School of Technology guy was like we're gonna miss the free beer referring to sometimes generous Alaska airlines people, maybe Frontier I don't know, giving passengers an up front taste for our offerings, this being not only a FOSS capital, per CSM 2005, but a Beer Capital as well (funny how these go together hand in glove -- no tap at Free Geek though, whereas at Cubespace it's like 50% foam). Anyway, I've heard many wonderful things about San Jose and will say this first hand: the Silicon Valley is not our enemy, nor is the Silicon Hills (Austin), so there, you have it in writing. Five OSCONs running in parallel in any given summer would make more sense than just one, but then O'Reilly isn't quite as big as McGraw- Hill (BYTE), yet. Anyway, Portland is happy to share the glory. OS Bridge is yet another bulb on the breadboard (aka grid), getting brighter by the day. Speaking of BYTE, I also learned last night that Eliza, our geek therapist, is alive and well in Python, as a part of the Natural Language Toolkit or NLTK. And she's got company. Some of you may recall Hugh Kenner's hilarious investigation of chat bots, then very new, in a way back issue (1980s).[4] I tried to get Nat Bobbitt interested in this but he said no more comms perhaps being strategic, time will tell. I admit to not following through either, making Sun Tzu and Eliza have conversational intercourse, a great high school project, and now we have a Watcher between Pycons -- Vern Ceder, tasked with scoping out talent, Pythonistas too young for a Pycon maybe (Hyatts pretty racy, lots of alcoholic beverages), but still able to exhibit in a poster session, perhaps with a teacher as stand in, proud for the whole school (Python Teacher of the Year?) -- we'll have someone for high schools to contact (soon). Check edu-sig archives for more data. edu-sig @ Python.org web page was transitioned to our university president in residence, Dr. Crunchy (yes, an alias), should have some contact info by summer. Ramping up slowly, as Pycon
Re: for with decimal values?
Gabriel Genellina wrote: Isn't so easy. You have representation errors and rounding errors here, and they accumulate. The last number printed should be 10.4 but I get 10.5: ... 10.3 10.4 10.5 (or more precisely, 10.459) Also, after exiting a for loop, the *last* value used is retained. In your while loop, the ctr variable contains the *next* value. All this discussion makes me wonder if it would be a good idea for Python to have this feature (batteries included and all) - it would have its uses, no? -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
Esmail ebo...@hotmail.com writes: All this discussion makes me wonder if it would be a good idea for Python to have this feature (batteries included and all) - it would have its uses, no? What feature are you referring to? Python already has fixed-point decimal values in the ‘decimal.Decimal’ type, if that's what you mean. -- \ “I spent all my money on a FAX machine. Now I can only FAX | `\ collect.” —Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Code works fine except...
For the past couple weeks, I've been working on an algorithm to schedule tennis leagues given court constraints and league considerations (i.e. whether it's a singles or a doubles league). Here were my requirements when I was designing this algorithm: -Each player plays against a unique opponent each week. -Similarly, in a doubles league, each player plays with a unique partner each week. -Each player gets a fair number of bye weeks (i.e. the player with the most bye weeks will have no more than one bye week than the player with the least number of bye weeks) I'm very close to arriving at my desired solution, but I have one glaring flaw. When I have an even number of players sign up for my league and there are court constraints, my current algorithm gives the first player in my league a bye week every single week. I'll post my code below and see how you guys think I should add to/ amend my code. def round_robin(players, rounds): if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): if doubles == True: doubles_week = len(week)/2.0 byes = doubles_week - courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:]) print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] print playing, bye_list -- http://mail.python.org/mailman/listinfo/python-list
Re: for with decimal values?
On May 4, 11:41 am, Esmail ebo...@hotmail.com wrote: All this discussion makes me wonder if it would be a good idea for Python to have this feature (batteries included and all) - it would have its uses, no? Well, sometimes more discussion == less consensus :) But it's really easy to roll your own: from decimal import Decimal def args2dec(fn): '''*args to Decimal decorator''' float2dec = lambda f: Decimal(str(f)) def _args2dec(*args): args = map(float2dec, args) return fn(*args) return _args2dec @args2dec def drange(start, stop, step): while start stop: yield start start += step -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On Sun, May 3, 2009 at 7:36 PM, Ross ross.j...@gmail.com wrote: For the past couple weeks, I've been working on an algorithm to schedule tennis leagues given court constraints and league considerations (i.e. whether it's a singles or a doubles league). Here were my requirements when I was designing this algorithm: -Each player plays against a unique opponent each week. -Similarly, in a doubles league, each player plays with a unique partner each week. -Each player gets a fair number of bye weeks (i.e. the player with the most bye weeks will have no more than one bye week than the player with the least number of bye weeks) I'm very close to arriving at my desired solution, but I have one glaring flaw. When I have an even number of players sign up for my league and there are court constraints, my current algorithm gives the first player in my league a bye week every single week. I'll post my code below and see how you guys think I should add to/ amend my code. def round_robin(players, rounds): if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): if doubles == True: doubles_week = len(week)/2.0 byes = doubles_week - courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:]) print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] print playing, bye_list Probably not the cause of the problem, but where did the magic numbers 1.072 and 1.08 come from? Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 4, 12:36 pm, Ross ross.j...@gmail.com wrote: For the past couple weeks, I've been working on an algorithm to schedule tennis leagues given court constraints and league considerations (i.e. whether it's a singles or a doubles league). Here were my requirements when I was designing this algorithm: -Each player plays against a unique opponent each week. -Similarly, in a doubles league, each player plays with a unique partner each week. -Each player gets a fair number of bye weeks (i.e. the player with the most bye weeks will have no more than one bye week than the player with the least number of bye weeks) I'm very close to arriving at my desired solution, but I have one glaring flaw. When I have an even number of players sign up for my league and there are court constraints, my current algorithm gives the first player in my league a bye week every single week. I'll post my code below and see how you guys think I should add to/ amend my code. def round_robin(players, rounds): if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) DON'T change the type/contents/meaning of a variable name like that. E.g. use nthings for a number of things and things for a collection of things. for week in round_robin(players,rounds,courts): The round_robin() function has only TWO arguments. This code won't even run. When you document neither your data structures nor what your functions are intended to do, the last hope for somebody trying to make sense of your code is to give meaningful names to your variables. week and doubles_week are NOT meaningful. if doubles == True: Bletch. s/ == True// doubles_week = len(week)/2.0 I doubt very much that using floating point is a good idea here. byes = doubles_week - courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] The derivation of the constants 1.072 and 1.08 is what? playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:]) print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] print playing, bye_list -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 3, 10:36 pm, Ross ross.j...@gmail.com wrote: def round_robin(players, rounds): [snip] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): [snip] First things first: I take it the call to round_robin is only supposed to take two parameters? Or do you have a version that takes 3? John -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter, Trouble with Message,Label widget
I assume that you create the two windows through two different calls to Tkinter.Tk() but you cannot enter two mainloops (at least not in a normal way). If you want a second window use the Toplevel widget. Try the following, it does what you want: import Tkinter root = Tkinter.Tk() my_text = Tkinter.StringVar(root) another_window = Tkinter.Toplevel() entry = Tkinter.Entry(root, textvar=my_text) entry.pack() label = Tkinter.Label(another_window, textvar=my_text) label.pack() root.mainloop() In the above example, whatever you type in the entry widget in the root window gets reflected in the label widget which is inside the second window, the one that was created with Tkinter.Toplevel(). Hope it helps, John -- http://mail.python.org/mailman/listinfo/python-list
Re: object query assigned variable name?
On Sat, 2 May 2009, John O'Hagan wrote: On Fri, 1 May 2009, warpcat wrote: [...] Given an object: class Spam(object): def __init__(self): # stuff I'd like it to print, when instanced, something like this: s = Spam() I’m assigned to s! If you just want the names an instance has in a given namespace, you could give your class a method like: class KnowNames(object): def get_names(self, namespace): id_str = str(hex(id(self))[:-1]) return [i for i in namespace if id_str in str(namespace[i])] which will give you a list of names when called on an instance. And which is a silly way of saying: class KnowName(object): def get_names(self, namespace): return [i for i in namespace if namespace[i] is self] removing four function calls, an assignment and a slicing operation from a mere two lines; certainly a personal best for insanely over-wrought code! Oops. :) , John -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue - I want to end.
Quoting Hendrik van Rooyen m...@microcorp.co.za: Luis Zarrabeitia akaky...@uh.cu wrote: 8 ---explanation and example of one producer, 8 ---more consumers and one queue As you can see, I'm sending one 'None' per consumer, and hoping that no consumer will read more than one None. While this particular implementation You don't have to hope. You can write the consumers that way to guarantee it. I did. But that solution is not very reusable (I _must_ remember that implementation detail every time) and most important, i'll have to remember it in a few months with I'm updating the code. ensures that, it is very fragile. Is there any way to signal the consumers? Signalling is not easy - you can signal a process, but I doubt if it is possible to signal a thread in a process. (or better yet, the queue itself, as it is shared by all consumers?) Should close work for this? (raise the exception when the queue is exhausted, not when it is closed by the producer). I haven't the foggiest if this will work, and it seems to me to be kind of involved compared to passing a sentinel or sentinels. Well, that would be a vaild signal. Too bad I have to pass it by hand, instead of the queue class taking care of it for me. I have always wondered why people do the one queue many getters thing. Given that the stuff you pass is homogenous in that it will require a similar amount of effort to process, is there not a case to be made to have as many queues as consumers, and to round robin the work? Abstraction. This problem is modeled nicely as a producer-consumer (it would be in fact a classic producer-consumer). I could take care of the scheduling myself, but there are already good scheduling algorithms written for my OS, that take into account both the available CPU and IO. A solution may not be a queue (in my case, I don't care the order in which the elements are processed, only that they are), but ideally I would just be 'yielding' results on my producer(s), and receiving them on my consumer(s), leaving the IPC mechanism to deal with how to move the data from producers to consumers (and to which consumers). And if the stuff you pass around needs disparate effort to consume, it seems to me that you can more easily balance the load by having specialised consumers, instead of instances of one humungous I can eat anything consumer. Not necessarily. The load may depend on the size of the data that was sent. The consumers are receiving the same kind of data, only the sizes are different (non-predictable different). Again, I could try to implement some heuristics to try and guess what processor has lower load, but I'd rather delegate that to the OS. I also think that having a queue per consumer thread makes it easier to replace the threads with processes and the queues with pipes or sockets if you need to do serious scaling later. This is already multiprocess. It could be nice to extend it to multi-computers later, but the complexity is not worth it right now. In fact I happen to believe that anything that does any work needs one and only one input queue and nothing else, but I am peculiar that way. Well, I also need some output. In my case, the outputs are files with the result of the processing, that can be summarized later (hence the need to 'join' the processes, to know when I can summarize them). Thank you. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue - I want to end.
Quoting Dennis Lee Bieber wlfr...@ix.netcom.com: I'm not familiar with the multiprocessing module and its queues but, presuming it behaves similar to the threading module AND that you have design control over the consumers (as you did in the sample) make a minor change. queue.put(None) ONCE in the producer Then, in the consumer, after it sees the None and begins shutdown processing, have the consumer ALSO do queue.put(None) Thank you. I went with this idea, only that instead of modifying the consumer, I modified the queue itself... Well, Cameron Simpson did :D. It's working nicely now. -- Luis Zarrabeitia Facultad de Matemática y Computación, UH http://profesores.matcom.uh.cu/~kyrie -- Participe en Universidad 2010, del 8 al 12 de febrero de 2010 La Habana, Cuba http://www.universidad2010.cu -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 3, 11:29 pm, Chris Rebert c...@rebertia.com wrote: Probably not the cause of the problem, but where did the magic numbers 1.072 and 1.08 come from? It is perhaps not the most direct cause of the problem, in the sense that the magic numbers could take various values and the problem would still be there. But the magic numbers appear to be used for spreading out bye selection, and that's broken. The extended slice as written will always pick the first element, since the step is guaranteed to be positive. Since the first player (or None, when there are an odd number of players) stays put in the first position during the round_robin shuffle, that player will always be selected for a bye. Further, as written, the calculated number of byes has no bearing on the actual number of byes selected. I think what I would do is adjust the shuffling algorithm in such a way that everyone moves through the various positions in the list (would it be as simple as adding a shift at the end of round_robin???). Then I could simply select the byes from one end of the list (with a regular slice instead of an extended slice). John -- http://mail.python.org/mailman/listinfo/python-list
Re: smtplib send email by using gmail smtp server
I've tested with 3.0.1 on Windows XP and worked fine. Seems to be a problem in the SSL support, but that's all I could say. -- Gabriel Genellina thanks, I'll check SSL support on my system Tiefeng Wu 2009-05-04 -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue - I want to end.
You may have to write the consumer loop by hand, rather than using 'for'. In the same-process case, you can do this. producer: sentinel= object( ) consumer: while True: item= queue.get( ) if item is sentinel: break etc. Then, each consumer is guaranteed to consume no more than one sentinel, and thus producing one sentinel per consumer will halt them all. However, with multiple processes, the comparison to 'sentinel' will fail, since each subprocess gets a copy, not the original, of the sentinel. Rather than use object() you can create a type whose instances are equal. class Stopper(object): def __eq__(self, other): return type(other) == type(self) producer's stop(): queue.put(Stopper()) consumers main loop: for item in iter(queue.get, Stopper()): ... -- http://mail.python.org/mailman/listinfo/python-list
Re: python docs for beginner programmer?
In article 87vdohk791@benfinney.id.au, ben+pyt...@benfinney.id.au says... Deep_Feelings doctore...@gmail.com writes: should i try them then after a month of reading i discover that they are - for example - not suitable for beginners OR should i ask here first ? :) You should take on the task of educating yourself. The official Python docs are an excellent resource. If you're self-admittedly someone who gets bored quickly, though, that's not a problem anyone but you can solve. Been doing Python for a week or so now and I must agree that the official python docs are a fantastic resource. I'm not sure how good they would be for someone with no previous programming language experience but they seem to be pretty thourough, at least for one beginning the language. http://docs.python.org/tutorial/index.html -- http://mail.python.org/mailman/listinfo/python-list
Threaded alternatives to smtplib?
Hi all, I'm writing a Python script to do a mail merge style email distribution. I create a few python threads and in each one I call `smtpserver = smtplib.SMTP(our.smtpserver.com)`. However, during the sending process, there seems to be only one connection open to our mail server at any one time. In other words, all these threads gain me no speed benefit at all! I seem to be running into the issue where smtplib is not fully thread-safe, as mentioned in this thread: http://mail.python.org/pipermail/python-list/2007-March/429067.html http://mail.python.org/pipermail/python-list/2007-March/429172.html Does anyone have suggestions as to a suitable workaround for this issue? I was looking at the Twisted library, which seems possible but significantly more complex. Thanks, Alex Jurkiewicz -- http://mail.python.org/mailman/listinfo/python-list
[issue3959] Add Google's ipaddr.py to the stdlib
Gregory P. Smith g...@krypto.org added the comment: r72210 pep8-ified the test names. -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3959 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5902] Stricter codec names
Ezio Melotti ezio.melo...@gmail.com added the comment: Actually I'd like to have some kind of convention mainly when the user writes the encoding as a string, e.g. s.encode('utf-8'). Indeed, if the encoding comes from a webpage or somewhere else it makes sense to have some flexibility. I think that 'utf-8' is the most widely used name for the UTF-8 codec and it's not even mentioned in the table of the standard encodings. So someone will use 'utf-8', someone else 'utf_8' and some users could even pick one of the aliases, like 'U8'. Probably is enough to add 'utf-8', 'iso-8859-1' and similar as preferred form and explain why and how the codec names are normalized and what are the valid aliases. Regarding the ambiguity of 'UTF', it is not the only one, there's also 'LATIN' among the aliases of ISO-8859-1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5902 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5559] IDLE Output Window 's goto fails when path has spaces
Claudio Canepa ccanep...@gmail.com added the comment: On Sat, May 2, 2009 at 11:31 PM, Kurt B. Kaiser rep...@bugs.python.orgwrote: Kurt B. Kaiser k...@shore.net added the comment: r72227. How's your test code coming? A relative Win filename with leading spaces should be found even when there's a file of same name but no spaces. -- keywords: +26backport ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5559 ___ Sorry for the delay, Kurt. Test with rev 72227 , ok. test cases: (one space betwwen a and b , one before second tmp, one before first x) Searching 'hello' in d:\tmp\*.tmp ... d:\tmp\ xx.tmp: 1: hello # see woot.py:24 :24 d:\tmp\a b\ tmp\ xx.tmp: 1: hello # see woot.py:24 :24 d:\tmp\a b\ xx.tmp: 1: hello # see woot.py:24 :24 Found 3 hits. ( all three opens the correct file) Same changing the target lines to stress the regex: d:\tmp\ xx.tmp: 1: hello # see woot.py: 24:24 d:\tmp\a b\ tmp\ xx.tmp: 1: hello # see woot.py: 24:24 d:\tmp\a b\ xx.tmp: 1: hello # see woot.py: 24:24 Found 3 hits. ( all three opens the correct file) Non absolute path: xx.py: 1: hello # see woot.py: 24:24 xx.py: 1: hello # see woot.py: 24:24 Found 2 hits. ( both opens the correct file) others; not listed: ok. Thanks for taking care Kurt. -- Added file: http://bugs.python.org/file13848/unnamed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5559 ___brbr div class=gmail_quoteOn Sat, May 2, 2009 at 11:31 PM, Kurt B. Kaiser span dir=ltrlt;a href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;/span wrote:br blockquote class=gmail_quote style=PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid div class=imbrKurt B. Kaiser lt;a href=mailto:k...@shore.net;k...@shore.net/agt; added the comment:brbr/divr72227.brbrHow#39;s your test code coming?  A relative Win filename with leadingbrspaces should be found even when there#39;s a file of same name but nobr spaces.brbr--/blockquote blockquote class=gmail_quote style=PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solidspan id=/spanbrkeywords: +26backportbr div div/div div class=h5br___brPython tracker lt;a href=mailto:rep...@bugs.python.org;rep...@bugs.python.org/agt;brlt;a href=http://bugs.python.org/issue5559; target=_blankhttp://bugs.python.org/issue5559/agt;br ___br/div/div/blockquote/div divbr /div div /div divSorry for the delay, Kurt./div divTest with rev 72227 , ok./div div /div divtest cases:/div div(one space betwwen a and b , one before second tmp, one before first x)/div divSearching #39;hello#39; in d:\tmp\*.tmp ...brd:\tmp\ xx.tmp: 1: hello # see woot.py:24 :24 brd:\tmp\a b\ tmp\ xx.tmp: 1: hello # see woot.py:24 :24 brd:\tmp\a b\ xx.tmp: 1: hello # see woot.py:24 :24 brFound 3 hits.br ( all three opens the correct file)/div div /div divSame changing the target lines to stress the regex:/div divd:\tmp\ xx.tmp: 1: hello # see woot.py: 24:24 brd:\tmp\a b\ tmp\ xx.tmp: 1: hello # see woot.py: 24:24 brd:\tmp\a b\ xx.tmp: 1: hello # see woot.py: 24:24 brFound 3 hits.br( all three opens the correct file)/div div /div divNon absolute path:/div div xx.py: 1: hello # see woot.py: 24:24 brxx.py: 1: hello # see woot.py: 24:24 brFound 2 hits.br( both opens the correct file)/div div /div divothers; not listed: ok./div div /div divThanks for taking care Kurt./div divspan lang=ES-MODERN/span /div divspan lang=ES-MODERN--/span/div divccanepa/div ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5908] I need to import the module in the same thread
Changes by tyoc z...@alum.com: -- title: I need to import the module in the same thread? - I need to import the module in the same thread ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5908 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Georg Brandl ge...@python.org added the comment: Interestingly, my setlocale(3p) man page says: ERRORS No errors are defined. So isn't it debatable if returning the NULL pointer really is an error? -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Jeroen Ruigrok van der Werven asmo...@in-nomine.org added the comment: On the subject whether or not returning a null pointer should be considered he said: - On the subject whether or not returning a null pointer should be considered an error he said: -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Changes by Jeroen Ruigrok van der Werven asmo...@in-nomine.org: Removed file: http://bugs.python.org/file13843/locale.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Changes by Jeroen Ruigrok van der Werven asmo...@in-nomine.org: Removed file: http://bugs.python.org/file13849/locale.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Jeroen Ruigrok van der Werven asmo...@in-nomine.org added the comment: Really correct this time. -- Added file: http://bugs.python.org/file13850/locale.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5909] Segfault in typeobject.c
Mark Dickinson dicki...@gmail.com added the comment: This doesn't look like a Python issue to me; it also looks like it's nothing to do with ctypes, so I've unselected that from the components. The bug may well be in gobjectmodule.c, which isn't part of core Python AFAIK. Any chance you could narrow down the cause of the failure? -- assignee: theller - components: -ctypes nosy: +marketdickinson -theller ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Jeroen Ruigrok van der Werven asmo...@in-nomine.org added the comment: Georg pointed out a mistake I introduced in my patch, updated now. -- Added file: http://bugs.python.org/file13849/locale.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1443504] locale.getpreferredencoding() dies when setlocale fails
Jeroen Ruigrok van der Werven asmo...@in-nomine.org added the comment: I asked that as well on the POSIX/SUS list and Don Cragun responded with: If you make the last argument to setlocale() be a pointer to unallocated memory, implementations would be allowed to set errno to EFAULT and terminate the process with a core dump even when this section says No errors are defined. An implementation could also set errno to ENOENT (e.g., if the B locale wasn't known) or to EINVAL (e.g., if the B locale existed but the LC_CTYPE portion of the locale was not in the proper format). That wording just means that the standard doesn't require implementations to detect errors like these nor to report specific error values for different possible errors. On the subject whether or not returning a null pointer should be considered he said: The standard is silent on this issue. Why does it make any difference to an application? If setlocale(LC_CTYPE, B) returns a null pointer, the LC_CTYPE portion of the locale was not changed. If setlocale(LC_CTYPE, B) does not return a null pointer, the LC_CTYPE portion of the locale was successfully changed. I am just wondering why we want to be quite different from how many other languages are approaching the issue. Sure enough, we can use a try: construct, but it kind of defeats the principle of least astonishment by being different from the rest on this issue. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1443504 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5907] repr of time.struct_time type does not eval
John Morton j...@angrymonkey.net.nz added the comment: While it's true that repr() methods cannot generally be expected to eval back into an object of the same type, the old repr behaviour of the struct_time object did effectively do so. Admittedly it was a kludge due to the time module functions originally producing a tuple before the advent of the struct_time type, but code that expected repr-eval behaviour worked up to 2.5. It's also evident that who ever changed the behaviour of time.struct_time.__repr__ intended that to sill be the case, otherwise it would have produced a string of the form time_struct ... So I would describe this as a bug, otherwise you'd have to call it an undocumented behaviour change :-) The question remains, how to fix it? Should the repr output change to time.struct_time((tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)) or implement the keyword argument form? (Note: python3.0 shares this new behaviour) -- versions: +Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5907 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5909] Segfault in typeobject.c
Gerald Britton gerald.brit...@gmail.com added the comment: This bug reports corresponds to one opened on Gnome: http://bugzilla.gnome.org/show_bug.cgi?id=578419 According to the devs there: As far as I can tell this is a Python/C bug. PyGObject is doing everything by the book, and it is Python that is giving us corrupted base objects. I debugged long and hard but was unable to fix a bug that just isn't there, nor was I able to figure out a workaround. I sure don't want this to get into a finger-pointing battle! All I know is that I can reproduce this at will. If the backtrace is not enough to narrow down the cause of failure, please let me know what you would need. I'll be glad to help solve the problem. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5909 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5912] import deadlocks when using fork
New submission from ayal baron ayal.ba...@rocketier.com: While running 2 or more threads, if one thread is importing anything (i.e. has the import lock) and the other thread runs fork and then the child process runs import then the child and parent will hang forever (the child waits on the import lock but the parent receives the signal). see Issue1590864 for another example of this. Following is a simple way to reproduce this behavior: mysleep.py: import time time.sleep(1) run_me_and_hang.py: import os import threading import subprocess class F(threading.Thread): def run(self): import mysleep print f is out f = F() f.start() a = subprocess.call([echo, DONE]) print exit -- components: None messages: 87044 nosy: abaron severity: normal status: open title: import deadlocks when using fork type: crash versions: Python 2.4, Python 2.5, Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5912 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5913] On Windows os.listdir('') - cwd and os.listdir(u'') - C:\
New submission from Ezio Melotti ezio.melo...@gmail.com: On Windows, with Python2/Python3, os.listdir('')/os.listdir(b'') list the content of the current working directory and os.listdir(u'')/os.listdir('') the content of C:\. On Linux the error OSError: [Errno 2] No such file or directory: '' is raised. I also noticed that os.listdir('C:') (without the \) lists the content of the cwd too. -- components: Library (Lib), Windows messages: 87045 nosy: ezio.melotti severity: normal status: open title: On Windows os.listdir('') - cwd and os.listdir(u'') - C:\ type: behavior versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4305] ctypes fails to build on mipsel-linux-gnu (detects mips instead of mipsel)
Thomas Heller thel...@ctypes.org added the comment: Tested myself, on a mipsel debian qemu instance. -- resolution: accepted - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4305 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5379] Multicast example mcast.py is outdated and ugly
Philipp Hagemeister phi...@phihag.de added the comment: Updated patch to use the new ipaddr module instead of the platform-specific socket.inet_pton (unavailable on some platforms, including Windows XP) Updated formatting -- Added file: http://bugs.python.org/file13851/mcast-example.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5379 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5379] Multicast example mcast.py is outdated and ugly
Changes by Philipp Hagemeister phi...@phihag.de: Removed file: http://bugs.python.org/file13198/mcast-example.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5379 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5914] Add PyOS_string_to_double function to C API
New submission from Mark Dickinson dicki...@gmail.com: Here's a patch that adds a PyOS_string_to_double function to complement the recently added PyOS_double_to_string function. This is supposed to be a more Pythonic version of PyOS_ascii_strtod. It raises Python exceptions to correspond to the various possible errors (malformed string, overflowing number, malloc failure...) instead of requiring the caller to examine errno. It's intended for both internal and external use; if this goes in, I intend to use it in the Python core in places where PyOS_ascii_strtod or PyOS_ascii_atof are currently used. -- assignee: marketdickinson components: Interpreter Core files: string_to_double.patch keywords: patch messages: 87048 nosy: eric.smith, marketdickinson severity: normal status: open title: Add PyOS_string_to_double function to C API type: feature request versions: Python 3.1 Added file: http://bugs.python.org/file13852/string_to_double.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5914] Add PyOS_string_to_double function to C API
Eric Smith e...@trueblade.com added the comment: This looks okay to me (although since it's not hooked up I haven't tested it). I particularly like that it doesn't allow leading whitespace, and that the caller no longer has to remember errno (forgetting to set and/or test it have both caused me problems in the past). Does the whitespace change cause any problems for any internal code? I wouldn't think so, but I haven't looked at it. As long as you're at it, I'd suggest deprecating PyOS_ascii_*. -- stage: - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5914 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3286] IDLE opens window too low on Windows
Kurt B. Kaiser k...@shore.net added the comment: IDLE doesn't control window placement - that's left to Tk to handle. Hopefully it will get better with time. Once you take control, you have to handle all the window placement, which is one of the things that window managers are expert at, supposedly. You could try taking your issue to the Tcl/Tk devs. I'm running 8.5 here on a netbook with XP and a 1024x800 screen. I simply reduced the initial height to 33 using the Configure dialog. Zooming the window height is also helpful. Use the hotkey. Some attempt to control position by platform has been made in ZoomHeight.py, where you'll find some magic numbers. On Linux, some people have panels at the top, some at the bottom, some hide them, and some don't have any. Maybe we'll look at this config again once we get the extension parameters on the Config dialog. We could move some of those magic numbers to the config file. -- assignee: - kbk nosy: +kbk resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3286 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com