Re: How can I speed up a script that iterates over a large range (600 billion)?
Now that the exercise has been solved... Instead of really short code to solve the problem, how about some really long code? :-) I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the factors, and doing memoization of the generated primes to produce a program that does what factor does, e.g.: $ factor 9 9: 3 3 2071723 5363222357 The python code is rather too slow for this particular number (I gave up on it finding 5363222357) but works quite well on 600851475143, or even, e.g., 12186606004219: $ python factor.py 600851475143 12186606004219 600851475143: 71 839 1471 6857 12186606004219: 2071723 5882353 While searching for speed hacks I came across a few interesting tricks, particularly TZomegaTZIOY's mod-30 scheme (erat3) at stackoverflow.com (see URLs in the comments), which only really works well in Python 2.7 and later (using itertools.compress). Here is the end result (run with 2.5 and 2.7, I have no 3.x installed anywhere convenient, and of course the print calls would change): import itertools import sys def count(start = 0, step = 1): Yield count starting from start and counting up by step. Same as itertools.count() except for the step argument, and allowing non-int arguments. Python 2.7 and later provides this directly, via itertools. Note: it's usually faster to use itertools.islice(itertools.count(...)) than to run the while True loop below, so we do that if we can. if (sys.version_info[0] 2 or (sys.version_info[0] == 2 and sys.version_info[1] = 7)): return itertools.count(start, step) if isinstance(start, int) and isinstance(step, int): if step == 1: return itertools.count(start) if 1 step 5: # 5 upper bound is a guess return itertools.islice(itertools.count(start), 0, None, step) def f(start, step): while True: yield start start += step return f(start, step) # Sieve of Eratosthenes-based prime-number generator. # # Based on David Eppstein's for python 2.3(?) and subsequent # discussion -- see # http://code.activestate.com/recipes/117119-sieve-of-eratosthenes/ # # See also: # http://oreilly.com/pub/a/python/excerpt/pythonckbk_chap1/index1.html?page=last # # http://stackoverflow.com/questions/2211990/how-to-implement-an-efficient-infinite-generator-of-prime-numbers-in-python/3796442#3796442 def primes(): Yields sequence of prime numbers via Sieve of Eratosthenes. # Keep the state from the last time we abandoned the # generator, in primes.primes and primes.D. We can then # very quickly re-yield previously-saved primes. We're # going to skip even numbers below, we so prime the # primes so far list with 2. # # For the fancy (erat3) version, we need to pre-provide # 2, 3, and 5, and pre-load D. Having done that we can # start either version at 7. try: primes.primes except AttributeError: primes.primes = [2, 3, 5] for p in primes.primes: yield p # OK, now we need a mapping holding known-composite values # (numbers struck from the sieve). try: D = primes.D except AttributeError: D = primes.D = { 9: 3, 25: 5 } # D[q] exists if q is composite; its value is the first prime # number that proves that q is composite. (However, only odd # numbers appear in D.) q = p + 2 # where we start sieve-ing, below if sys.version_info[0] == 2 and sys.version_info[1] 7: for q in count(q, 2): p = D.pop(q, None) if p is None: # q was not marked composite, so it's prime; moreover, # q-squared is composite (and odd) and its first prime # factor is q. primes.primes.append(q) D[q * q] = q yield q else: # q is composite, p is its first prime factor -- e.g., # q=9 and p=3, or q=15 and p=3. Extend the sieve: # find first natural number k where q + 2kp is not already # already known as composite. (e.g., if q=9 and p=3, k=1 # so that we mark D[15] as composite, with 3 as its first # prime factor.) Note that we are skipping even numbers, # so p and q are both odd, so q+p is even, q+2p is odd, # q+3p is even, q+4p is odd, etc. We don't need to mark # even-numbered composites in D, which is why we only look # at q + 2kp. twop = p + p x = q + twop # next odd multiple of p while x in D: # skip already-known composites x += twop D[x] = p else: # 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 MASK = (1, 0, 1, 1, 0, 1, 1,
Re: How can I speed up a script that iterates over a large range (600 billion)?
Chris Torek nos...@torek.net writes: def primes(): Yields sequence of prime numbers via Sieve of Eratosthenes. I think this has the same order-complexity but is enormously slower in practice, and runs out of recursion stack after a while. Exercise: spot the recursion. from itertools import islice, ifilter, count def primes(): a = count(2) while True: p = a.next() yield p a = ifilter(lambda t,p=p: t%p, a) # print first 100 primes print list(islice(primes(), 100)) -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On Tue, Jun 21, 2011 at 11:58 PM, Chris Torek nos...@torek.net wrote: I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the factors, and doing memoization of the generated primes to produce a program that does what factor does, e.g.: This is a generator-based sieve I wrote a while back to solve the PRIME1 problem at SPOJ. The problem is to generate all the prime numbers within specified ranges, where the numbers are great enough that a full sieve would run out of memory, and the ranges are wide enough that a O(sqrt(n)) test on each number would simply take too long: https://www.spoj.pl/problems/PRIME1/ The script is not terribly impressive from a technical standpoint, but what tickles me about it is its bootstrappiness; the set that the primes generator checks to determine whether each number is prime is actually built from the output of the generator, which itself contains no actual primality-testing logic. Hope you like it: 8 import math def primes(m, n): # Yield all the primes in the range [m, n), using the nonprimes set # as a reference. Except for 2, only odd integers are considered. if m = 2: yield 2 m = 3 elif m % 2 == 0: m += 1 # Force m to be odd. for p in xrange(m, n, 2): if p not in nonprimes: yield p # Read all the bounds to figure out what we need to store. bounds = [map(int, raw_input().split(' ')) for t in xrange(input())] limit = max(n for (m, n) in bounds) sqrt_limit = int(math.sqrt(limit)) # Mark odd multiples of primes as not prime. Even multiples # do not need to be marked since primes() won't try them. nonprimes = set() for p in primes(3, sqrt_limit+1): # Mark odd nonprimes within the base range. p*3 is the first # odd multiple of p; p+p is the increment to get to the next # odd multiple. nonprimes.update(xrange(p*3, sqrt_limit+1, p+p)) # Mark odd nonprimes within each of the requested ranges. for (m, n) in bounds: # Align m to the first odd multiple of p in the range # (or the last odd multiple before the range). m -= (m % (p + p) - p) m = max(m, p*3) nonprimes.update(xrange(m, n+1, p+p)) # Generate and write the primes over each input range. first = True for (m, n) in bounds: if not first: print first = False for p in primes(m, n+1): print p 8 -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't understand SequenceMatcher from difflib
On Tue, Jun 21, 2011 at 03:02:57PM -0400, Terry Reedy wrote: On 6/21/2011 9:43 AM, Antoon Pardon wrote: matcher = SequenceMatcher(ls1, ls2) ... What am I doing wrong? Read the doc, in particular, the really stupid signature of the class: class difflib.SequenceMatcher(isjunk=None, a='', b='', autojunk=True) You are passing isjunk = ls1, a = ls2, and by default, b=''. So there are no matches, len(a) = 36, len(b) = 0, and the dummy match is (36,0,0) as you got. Yes my penny dropped an hour after I send the question. But reading the doc in itself didn't help. I head read and reread it a number of times, before I finaly posted the question. Somehow this signature reminded me of the range function where if you only provide one argument, this is considered to be the second parameter with the first parameter taking on a default value. So somehow I assumed that if you only provided two parameters, these would be shifted as in range and the first parameter would default to None. I know if you read the documentation carefully, it contradicts this, but my assumption blinded me for seeing it. There are also several example in the doc, all like s = SequenceMatcher(None, abcd, abcd abcd) # or s = SequenceMatcher(lambda x: x== , abcd, abcd abcd) So you will get better results with matcher = SequenceMatcher(None, ls1, ls2) # or matcher = SequenceMatcher(a=ls1, b=ls2) In the future, please try to simply examples before posting for help. Yes my bad here. I should have prepared the question better. Frustration got the better of me. Thanks for responding anyway. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
2011/6/22 Saul Spatz saul.sp...@gmail.com: Hi, I'm just starting to learn a bit about Unicode. I want to be able to read a utf-8 encoded file, and print out the codepoints it encodes. After many false starts, here's a script that seems to work, but it strikes me as awfully awkward and unpythonic. Have you a better way? def codePoints(s): ''' return a list of the Unicode codepoints in the string s ''' answer = [] skip = False for k, c in enumerate(s): if skip: skip = False answer.append(ord(s[k-1:k+1])) continue if not 0xd800 = ord(c) = 0xdfff: answer.append(ord(c)) else: skip = True return answer if __name__ == '__main__': s = open('test.txt', encoding = 'utf8', errors = 'replace').read() code = codePoints(s) for c in code: print('U+'+hex(c)[2:]) Thanks for any help you can give me. Saul -- http://mail.python.org/mailman/listinfo/python-list Hi, what functionality should codePoints(...) add over just iterating through the characters in the unicode string directly (besides filtering out the surrogates)? It seems, that you can just use s = open(r'C:\install\filter-utf-8.txt', encoding = 'utf8', errors = 'replace').read() for c in s: print('U+'+hex(ord(c))[2:]) or eventually add the condition before the print: if not 0xd800 = ord(c) = 0xdfff: you can also use string formatting to do the hex conversion and a more usual zero padding; the print(...) calls would be: older style formatting print(U+%04x%(ord(c),)) or the newer, potentially more powerful way using format(...) print(U+{:04x}.format(ord(c))) hth, vbr -- http://mail.python.org/mailman/listinfo/python-list
coverage.py: Highlight hot spots in source code
Hi, I just used coverage.py for the first time, and like it very much. Is it possible to display how many times a line was executed? I want to see lines which are executed very often red and lines which are executed not often green. I know there are other tools like hotshot, but AFAIK they don't have a nice HTML output for every python source file. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
Saul Spatz wrote: Hi, I'm just starting to learn a bit about Unicode. I want to be able to read a utf-8 encoded file, and print out the codepoints it encodes. After many false starts, here's a script that seems to work, but it strikes me as awfully awkward and unpythonic. Have you a better way? def codePoints(s): ''' return a list of the Unicode codepoints in the string s ''' answer = [] skip = False for k, c in enumerate(s): if skip: skip = False answer.append(ord(s[k-1:k+1])) continue if not 0xd800 = ord(c) = 0xdfff: answer.append(ord(c)) else: skip = True return answer if __name__ == '__main__': s = open('test.txt', encoding = 'utf8', errors = 'replace').read() code = codePoints(s) for c in code: print('U+'+hex(c)[2:]) Thanks for any help you can give me. Saul Here's an alternative implementation that follows Chris' suggestion to use a generator: def codepoints(s): s = iter(s) for c in s: if 0xd800 = ord(c) = 0xdfff: c += next(s, ) yield ord(c) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.2 for Windows reports version as 2.7.0?
En Sun, 19 Jun 2011 12:35:38 -0300, pyt...@bdurham.com escribió: The version info comes from the DLL - I wonder if the DLL being found is somehow old? Make sure: import sys win32api.GetModuleFileName(sys.dllhandle) Is the DLL you expect. After uninstalling and reinstalling for the current user only (vs. all users), Python now reports the correct version number. And running your code above confirms that the proper DLL is being loaded (c:\Python27\Python27.dll). My original version of Python 2.7.0 was installed for all users and when I ran the 2.7.2 MSI I chose to install for all users as well. After running the 2.7.2 MSI, my Python exe's had the correct timestamps, but I failed to check the python27.dll timestamp to see if this file was out-of-date. I wonder if changing my install method to current user forced the installation of the updated python27.dll? And perhaps the default 2.7.2 installation in all users mode (when one is updating an existing 2.7 installation) doesn't update the Python27.dll under some conditions? In a for all users install, python27.dll goes into c:\windows\system32, not c:\python27 Maybe you installed 2.7.0 twice, for all users and also for current user only, and both in the same directory (c:\python27). That could explain the old .dll in the install directory; the new one goes into system32, but the old one takes precedence. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
That seems to me correct. '\\u{:04x}'.format(ord(u'é')) \u00e9 '\\U{:08x}'.format(ord(u'é')) \U00e9 because u'\U00e9' File eta last command, line 1 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-5: end of string in escape sequence u'\U00e9' é u'\u00e9' é from this: u'éléphant\N{EURO SIGN}' éléphant u = u'éléphant\N{EURO SIGN}' ''.join(['\\u{:04x}'.format(ord(c)) for c in u]) \u00e9\u006c\u00e9\u0070\u0068\u0061\u006e\u0074\u20ac Skipping surrogate pairs is a little bit a non sense, because the purpose is to display code points! -- http://mail.python.org/mailman/listinfo/python-list
Re: Using django ORM from web browser and from command line apps
On Jun 22, 2:21 am, News123 news1...@free.fr wrote: Out of curiousity: Do you know whether the imports would be executed for each potential command as soon as I call manage.py or only 'on demand'? Why would you care ? Just importing the module shouldn't have any side effect. -- http://mail.python.org/mailman/listinfo/python-list
Re: Emails backup in python 3.2
Michael Hrivnak wrote: Do you have a special reason for wanting to implement your own email storage? Learning python :) It seems very easy to get my mails with the poplib help. Usually I work with Kmail which imports mbox files. I'm not prone to set up a SMTP server on my PC. -- goto /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
Chris Torek wrote: Now that the exercise has been solved... Instead of really short code to solve the problem, how about some really long code? :-) I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the factors, and doing memoization of the generated primes to produce a program that does what factor does, e.g.: $ factor 9 9: 3 3 2071723 5363222357 The python code is rather too slow for this particular number (I gave up on it finding 5363222357) It shouldn't take more than a few seconds to factorise 10**17-1 even in pure Python. On my not-very-powerful PC, using a home-brew pure-Python function (code to follow), I get all four factors in under four seconds. In comparison, I ran your script for over five minutes before giving up, it still hadn't found the fourth factor. Don't be disappointed though, you're in illustrious company. Getting the Sieve of Eratosthenes *badly* wrong is one of the most common mistakes, second only to getting involved in land wars in Asia. See this paper by Melissa O'Neill: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf What people often describe as the Sieve of Eratosthenes is frequently the Sieve of Euler, which while mathematically elegant, is computationally crap. As O'Neill calls it, the Unfaithful Sieve. In my home-brew primes module, I have this to say about three common algorithms, including the classic Unfaithful Sieve, Turner's algorithm: # === Prime number generators to avoid === # The following three prime generators are supplied for educational # purposes, specifically as a terrible warning on how NOT to do it. # # Their performance starts at bad in the case of trial_division(), falls to # terrible with turner(), and ends up with the utterly awful # naive_division(). None of these three have acceptable performance; they # are barely tolerable even for the first 100 primes. Their only advantage # is that they are somewhat easy to understand. Here's my factors() function. Adapting it to be a generator is left as an exercise. def factors(n): factors(integer) - [list of factors] factors(231) [3, 7, 11] Returns the (mostly) prime factors of integer n. For negative integers, -1 is included as a factor. If n is 0 or 1, [n] is returned as the only factor. Otherwise all the factors will be prime. if n != int(n): raise ValueError('argument must be an integer') elif n in (0, 1, -1): return [n] elif n 0: return [-1] + factors(-n) assert n = 2 result = [] for p in sieve(): if p*p n: break while n % p == 0: result.append(p) n //= p if n != 1: result.append(n) return result def sieve(): Yield prime integers efficiently. This uses the Sieve of Eratosthenes, modified to generate the primes lazily rather than the traditional version which operates on a fixed size array of integers. # This implementation based on a version by Melissa E. O'Neill, # as reported by Gerald Britton: # http://mail.python.org/pipermail/python-list/2009-January/1188529.html innersieve = sieve() prevsq = 1 table = {} i = 2 while True: if i in table: prime = table[i] del table[i] nxt = i + prime while nxt in table: nxt += prime table[nxt] = prime else: yield i if i prevsq: j = next(innersieve) prevsq = j**2 table[prevsq] = j i += 1 I don't claim that my version of the sieve above will break any computational records, but it performs quite well for my needs. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter/scrollbar/canvas question
Saul Spatz wrote: very helpful stuff snipped You need to do the update_idletasks to force the canvas to be mapped before you figure out the bounding box. Until the canvas is mapped to the screen, the bounding box is (0,0,1,1) so there no scrolling possible. (You can call update_ideltasks through any widget.) Many thanks--this fixed the issue. That said, I wonder why you're putting widgets in the frame instead of putting objects directly on the canvas. The way you're doing it you can't use tags, which are what really give the canvas its power. The power of canvas is not really what I'm after. What I would like is a list of checkboxes (and, in a few other frames, several buttons); if a scrollable frame were available in tkinter, I'd use that. While canvas is powerful, its power is not needed for my purposes. Saul -- http://gall.mine.nu free to get comics,free chat-1,dc++ (dcplusplus), mute webcache,group update program,torrent,atomic time server,tool to find your ip -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On Wed, Jun 22, 2011 at 10:01 PM, Anny Mous b1540...@tyldd.com wrote: prime = table[i] del table[i] I don't fully understand your algorithm, but I think these two lines can be rewritten as: prime=table.pop(i) Interesting algo. A recursive generator, not sure I've seen one of those before. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
free computer ebooks updated 5 ebooks every day or more
Denodev eBook - Blog PDF eBook. Free download eBook. Newest eBooks updated everyday. All eBooks are completely free. Come and stay here. subscribe for newsletters. subscribe for rss. www.denodev.com -- http://mail.python.org/mailman/listinfo/python-list
User Authentication
Hi All, I am working on application which needs to do a authentication against LDAP, if LDAP not installed then local system account (administrator user in windows and root user in Linux). This should work on both Windows and Linux. Which library I should use for that. Regards, Anurag -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
Thanks. I agree with you about the generator. Using your first suggestion, code points above U+ get separated into two surrogate pair characters fron UTF-16. So instead of U=10 I get U+DBFF and U+DFFF. -- http://mail.python.org/mailman/listinfo/python-list
Re: User Authentication
On 22/06/2011 14:34, Anurag wrote: Hi All, I am working on application which needs to do a authentication against LDAP, if LDAP not installed then local system account (administrator user in windows and root user in Linux). This should work on both Windows and Linux. Which library I should use for that. python-ldap seems the obvious choice: http://www.python-ldap.org/ TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: User Authentication
On Wed, 2011-06-22 at 06:34 -0700, Anurag wrote: Hi All, I am working on application which needs to do a authentication against LDAP, if LDAP not installed then local system account (administrator user in windows and root user in Linux). This should work on both Windows and Linux. See python-ldap -- http://mail.python.org/mailman/listinfo/python-list
Python Regular Expressions
Hi, I am hoping someone here can help me with a problem I'd like to resolve with Python. I have used it before for some other projects but have never needed to use Regular Expressions before. It's quite possible I am following completley the wrong tack for this task (so any advice appreciated). I have a source file in csv format that follows certain rules. I basically want to parse the source file and spit out a second file built from some rules and the content of the first file. Source File Format: Name, Type, Create, Study, Read, Teach, Prerequisite # column headers Distil Mana, Lore, n/a, 70, 38, 21 Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana Talismantic Lore, Lore, n/a, 150, 100, 50 Advanced Talismantic Lore, Lore, n/a, 100, 60, 30, Talismantic Lore, Theurgic Lore The input file I have has over 700 unique entries. I have tried to cover the four main exceptions above. Before I detail them - this is what I would like the above input file, to be output as (dot diagramming language incase anyone recognises it): Name, Type, Create, Study, Read, Teach, Prerequisite # column headers DistilMana [label={ Distil Mana |{Type|7}|{70|38|21}}]; TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; DistilMana - TheurgicLore; TalismanticLore [label={ Talismantic Lore |{Lore|n/a}|{150|100| 50}}]; AdvanvedTalismanticLore [label={ Advanced Talismantic Lore |{Lore|n/ a}|{100|60|30}}]; TalismanticLore - AdvanvedTalismanticLore; TheurgicLore - AdvanvedTalismanticLore; It's quite a complicated find and replace operation that can be broken down into some easy stages. The main thing the sample above showed was that some of the entries won't list any prerequisits - these only need the descriptor entry creating. Some of them have more than one prerequisite. A line is needed for each prerequisite listed, linking it to it's parent. You can also see that the 'name' needs to have spaces removed and it's repeated a few times in the process. I Hope it's easy to see what I am trying to achieve from the above. I'd be very happy to accept assistance in automating the conversion of my ever expanding csv file, into the dot format described above. Andy -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
Thanks very much. This is the elegant kind of solution I was looking for. I had hoped there was a way to do it without even addressing the matter of surrogates, but apparently not. The reason I don't like this is that it depends on knowing that python internally stores strings in UTF-16. I expected that there would be some built-in iterator that would return the code points. (Actually, this all started when I realized that s[k] wouldn't necessarily give me the kth character of the string s.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Regular Expressions
to expand. I have parsed one of the lines manually to try and break the process I'm trying to automate down. source: Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana output: TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; DistilMana - TheurgicLore; This is the steps I would take to do this conversion manually: 1) Take everything prior to the first comma and remove all the spaces, insert it into a newline: TheurgicLore 2) append the following string ' [label={ ' TheurgicLore [label={ 3) append everything prior to the first comma (this time we don't need to remove the spaces) TheurgicLore [label={ Theurgic Lore 4) append the following string ' |{' TheurgicLore [label={ Theurgic Lore |{ 5) append everything between the 1st and 2nd comma of the source file followed by a '|' TheurgicLore [label={ Theurgic Lore |{Lore| 6) append everything between the 2nd and 3rd comma of the source file followed by a '}|{' TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{ 7) append everything between the 3rd and 4th comma of the source file followed by a '|' TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105| 8) append everything between the 4th and 5th comma of the source file followed by a '|' TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70| 9) append everything between the 5th and 6th comma of the source file followed by a '}}];' TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; Those 9 steps spit out my fist line of output file as above TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; I now have to parse the dependancies onto a newline. # this next process needs to be repeated for each prerequisite, so if there are two pre-requisites it would need to keep parsing for more comma's. 1a) take everything between the 6th and 7th comma and put it at the start of a new line (remove spaces) DistilMana 2a) append '- ' DistilMana - 3a) append everything prior to the first comma, with spaces removed DistilMana - TheurgicLore This should now be all the steps to spit out: TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; DistilMana - TheurgicLore; -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Regular Expressions
On 2011-06-22, Andy Barnes andy.bar...@gmail.com wrote: to expand. I have parsed one of the lines manually to try and break the process I'm trying to automate down. source: Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana output: TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; DistilMana - TheurgicLore; This is the steps I would take to do this conversion manually: It seems to me that parsing the file into an intermediate model and then using that model to serialize your output would be easier to understand and more robust than modifying the csv entries in place. It decouples deciphering the meaning of the data from emitting the data, which is more robust and expansable. The amount of ingenuity required is less, though. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Regular Expressions
Andy Barnes wrote: Hi, I am hoping someone here can help me with a problem I'd like to resolve with Python. I have used it before for some other projects but have never needed to use Regular Expressions before. It's quite possible I am following completley the wrong tack for this task (so any advice appreciated). I have a source file in csv format that follows certain rules. I basically want to parse the source file and spit out a second file built from some rules and the content of the first file. Source File Format: Name, Type, Create, Study, Read, Teach, Prerequisite # column headers Distil Mana, Lore, n/a, 70, 38, 21 Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana Talismantic Lore, Lore, n/a, 150, 100, 50 Advanced Talismantic Lore, Lore, n/a, 100, 60, 30, Talismantic Lore, Theurgic Lore The input file I have has over 700 unique entries. I have tried to cover the four main exceptions above. Before I detail them - this is what I would like the above input file, to be output as (dot diagramming language incase anyone recognises it): Name, Type, Create, Study, Read, Teach, Prerequisite # column headers DistilMana [label={ Distil Mana |{Type|7}|{70|38|21}}]; TheurgicLore [label={ Theurgic Lore |{Lore|n/a}|{105|70|30}}]; DistilMana - TheurgicLore; TalismanticLore [label={ Talismantic Lore |{Lore|n/a}|{150|100| 50}}]; AdvanvedTalismanticLore [label={ Advanced Talismantic Lore |{Lore|n/ a}|{100|60|30}}]; TalismanticLore - AdvanvedTalismanticLore; TheurgicLore - AdvanvedTalismanticLore; It's quite a complicated find and replace operation that can be broken down into some easy stages. The main thing the sample above showed was that some of the entries won't list any prerequisits - these only need the descriptor entry creating. Some of them have more than one prerequisite. A line is needed for each prerequisite listed, linking it to it's parent. You can also see that the 'name' needs to have spaces removed and it's repeated a few times in the process. I Hope it's easy to see what I am trying to achieve from the above. I'd be very happy to accept assistance in automating the conversion of my ever expanding csv file, into the dot format described above. Forget about regexes. If there's any complexity it's in writing the output rather than reading the input file. You can tackle that by putting your data into a dictionary and using a format string: import sys def camelized(s): return .join(s.split()) template = %(camel)s [label={ %(name)s |{%(type)s|%(create)s}| {%(study)s|%(read)s|%(teach)s}}]; def process(instream, outstream): instream = (line for line in instream if not (line.isspace() or line.startswith(#))) rows = (map(str.strip, line.split(,)) for line in instream) headers = map(str.lower, next(rows)) for row in rows: rowdict = dict(zip(headers, row)) camel = rowdict[camel] = camelized(rowdict[name]) print template % rowdict for for_lack_of_better_name in row[len(headers)-1:]: print %s - %s; % (camelized(for_lack_of_better_name), camel) if __name__ == __main__: from StringIO import StringIO instream = StringIO(\ Name, Type, Create, Study, Read, Teach, Prerequisite # column headers Distil Mana, Lore, n/a, 70, 38, 21 Theurgic Lore, Lore, n/a, 105, 70, 30, Distil Mana Talismantic Lore, Lore, n/a, 150, 100, 50 Advanced Talismantic Lore, Lore, n/a, 100, 60, 30, Talismantic Lore, Theurgic Lore ) process(instream, sys.stdout) -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On 22/06/2011 06:58, Chris Torek wrote: Now that the exercise has been solved... Instead of really short code to solve the problem, how about some really long code? :-) I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the factors, and doing memoization of the generated primes to produce a program that does what factor does, e.g.: $ factor 9 9: 3 3 2071723 5363222357 The python code is rather too slow for this particular number (I gave up on it finding 5363222357) but works quite well on 600851475143, or even, e.g., 12186606004219: $ python factor.py 600851475143 12186606004219 600851475143: 71 839 1471 6857 12186606004219: 2071723 5882353 [snip] This code isn't particularly efficient, but it's fast enough: import math n = 9 limit = math.sqrt(n) test = 2 factors = [] while test = limit: if n % test == 0: factors.append(test) n //= test limit = math.sqrt(n) else: test += 1 factors.append(n) print(factors) -- http://mail.python.org/mailman/listinfo/python-list
what happens inside?
why tuples are immutable whereas list are mutable? why when we do x=y where y is a list and then change a element in x, y changes too( but the same is not the case when we change the whole value in x ), whereas, in tuples when we change x, y is not affected and also we cant change each individual element in tuple. Someone please clarify. -- echo Impossible | cat /dev/null -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens inside?
On 2011.06.22 10:45 AM, Chetan Harjani wrote: why tuples are immutable whereas list are mutable? Tuples are more efficient and more appropriate for a list of items that doesn't need to change. why when we do x=y where y is a list and then change a element in x, y changes too( but the same is not the case when we change the whole value in x ), whereas, in tuples when we change x, y is not affected and also we cant change each individual element in tuple. Someone please clarify. With x = y, x and y point to the same place in memory. Because lists are mutable, that place in memory can change, so both x and y will point to the same changed spot in memory. Because tuples are immutable, that place in memory cannot change, so Python must make a new spot in memory for the changed object. This is true for all immutable objects. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On Wed, Jun 22, 2011 at 6:01 AM, Anny Mous b1540...@tyldd.com wrote: def sieve(): Yield prime integers efficiently. This uses the Sieve of Eratosthenes, modified to generate the primes lazily rather than the traditional version which operates on a fixed size array of integers. # This implementation based on a version by Melissa E. O'Neill, # as reported by Gerald Britton: # http://mail.python.org/pipermail/python-list/2009-January/1188529.html innersieve = sieve() prevsq = 1 table = {} i = 2 while True: if i in table: prime = table[i] del table[i] nxt = i + prime while nxt in table: nxt += prime table[nxt] = prime else: yield i if i prevsq: j = next(innersieve) prevsq = j**2 table[prevsq] = j i += 1 This appears to have a small bug in it, but perhaps it doesn't matter. At the yield i statement, it is possible that i prevsq. It could be that i == next(innersieve)**2, in which case i is yielded as prime despite being composite. This would then cause additional errors further along. The only way this could happen would be if there were two consecutive primes such that all the numbers between their squares are composite, thereby failing to add the next prime to the table until after its square has been reached. This seems a rather unlikely scenario, but I can't say for certain that it never happens. The Haskell version does not contain this flaw, as far as I can tell. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens inside?
On Wed, Jun 22, 2011 at 4:45 PM, Chetan Harjani chetan.harj...@gmail.com wrote: why tuples are immutable whereas list are mutable? Because an immutable data type was needed, and a mutable type was also needed ;) why when we do x=y where y is a list and then change a element in x, y changes too( but the same is not the case when we change the whole value in x ), whereas, in tuples when we change x, y is not affected and also we cant change each individual element in tuple. Someone please clarify. That's because y points to an object. When you assign x = y, you say assign name x to object that's also pointed to by name y. When you change the list using list methods, you're changing the actual object. Since x and y both point to the same object, they both change. However, if you then assign y = [1], name y no longer points to the original object. x still remains pointing to the original object. a = [1,2] # assign name a to object [1,2] b = a # assign name b to object referred to by name a b [1, 2] a = [3,4] # assign name a to object [3,4] b [1, 2] a [3, 4] -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens inside?
On 22 June 2011 16:53, Andrew Berg bahamutzero8...@gmail.com wrote: On 2011.06.22 10:45 AM, Chetan Harjani wrote: why tuples are immutable whereas list are mutable? Tuples are more efficient and more appropriate for a list of items that doesn't need to change. And also it sometimes useful to be sure that something can't change. In particular, efficient dictionary implementations need the keys to be immutable, because it you change a key it /really/ fouls up the look-up. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
On Wed, Jun 22, 2011 at 8:54 AM, Adam Chapman adamchapman1...@hotmail.co.uk wrote: snip I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. No, it's a syntax error in the script itself, at least under the version of Python you're using. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax You're probably running Python 3.x, which changed `print` from a keyword to just a regular function; hence, `print foo` is illegal, and one must write `print(foo)` instead. Based on this, I'd say that nfold.py was written for Python 2.x rather than Python 3.x; so you'll either need to port it to Python 3.x, or install Python 2.x and run it under that. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
Adam Chapman wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax Looks like you are using Python 3, but nfold is Python 2. You're being tripped up by one of the non-compatible changes -- namely, print is now a function and so requires (). What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. Looking at nfold.py it seems that rounds and tree are optional, one of generate or dir is required, if dir is not given then data and spec must be, and booster and folds are required -- so I'm not really sure why they chose the mixture of and []. Also, on the version of jBoost I downloaded there is at least one error on nfolds.py on line 134 -- it should be indented one more level. Hope this helps. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
On Jun 22, 4:54 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful I just tried nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate --dir=C: \Users\Adam\Desktop\cvdata in the dos-style command prompt. It didn'g vive a syntax error this time, it just repeated my command back to me in text. I assume I called code correctly, but it didn't make a new folder full of data like it should have. -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
Adam Chapman wrote: On Jun 22, 4:54 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful I just tried nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate --dir=C: \Users\Adam\Desktop\cvdata in the dos-style command prompt. It didn'g vive a syntax error this time, it just repeated my command back to me in text. I assume I called code correctly, but it didn't make a new folder full of data like it should have. Which version of jBoost, and which version of Python? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Rant on web browsers
[I am biting only because this is my field of expertise, and I am really getting tired reading from people not having a shadow of a trace of a minimum clue what these languages that I like can and can't do.] Chris Angelico wrote: Random rant and not very on-topic. Feel free to hit Delete and move on. Why not post on-topic in the first place, and *ask* before being presumptuous? Get better. I've just spent a day coding in Javascript, There is no Javascript. and wishing browsers supported Python instead (or as well). Some browsers do in a way, because of the ECMAScript implementations they employ. Mozilla.org JavaScript 1.7+ is pretty pythonic as compared to, e.g. Microsoft JScript. Array comprehension, Array methods like filter(), and iterators/generators come to mind. This is not a coincidence; Brendan Eich has explicitly referred to Python in his blog. All I needed to do was take two dates (as strings), figure out the difference in days, add that many days to both dates, and put the results back into DOM Input objects (form entry fields). How that would be done would first depend on what you consider a day to be. (We have been over this elsewhere.) You can easily compute the difference between the time value of Date instances, which is stored as milliseconds since epoch, by subtraction (conversion to number is implicit, you do not have to call the getTime() method): var d1 = new Date(…, …, …, 12); var d2 = new Date(…, …, …, 12); var ms = d2 - d1; [I have been told that the 12 hours into the day can avoid problems with DST changes. You may use any hours value that you see fit, even none (which defaults to 0).] Dividing that by the number of milliseconds per day (which is conveniently written 864e5) would give you a good idea of the number of days (but watch out for floating-point precision). You can also write a method (of Date instances, if desired!) that can take calendar days into account – like saying that there are two days between `new Date(2011, 5, 22)' and `new Date(2011, 5, 24)' –, since overflow on Date instances is easily detected: Date.prototype.diff = function(d2) { // … }; var d = new Date(…); var diffInDays = d.diff(new Date(…)); Finally, adding or subtracting calendar days to a date is very simple, of course: var d = new Date(); d.setDate(d.getDate() + 2); Pretty simple, right? Javascript has a Date class, No, it does not. (Have you, by chance, read Flanagan's latest edition on the subject, full of misconceptions?) For your purposes, Javascript has no classes at all; if accepted as an umbrella term (which I strongly recommend against¹), then the programming *languages* it describes in your context all use *prototype-based* inheritance. it should be fine. But no. First, the date object can't be outputted as a formatted string. Yes, it can. There are several methods on the Date prototype object for that, and you can always write and add your own. The only way to output a date is Feb 21 2011. Wrong. So I have to get the three components (oh and the month is 0-11, not 1-12) and emit those. Not necessarily. (Yes, the month value is zero-based. This is not particular to ECMAScript implementations.) And Javascript doesn't have a simple format function that would force the numbers to come out with leading zeroes, But it is easily written, simplified: function leadingZero(n, width) { n = String(n); var len = n.length; if (len = width) return n; var a = []; a.length = width - len + 1; return a.join(0) + n; } so I don't bother with that. Your problem alone. What if I want to accept any delimiter in the date - slash, hyphen, or dot? The most simple way is to convert it so that the string format is understood by the Date constructor. There is precedence for the formats accepted by implementations in Web browsers as they are specified in ECMAScript Ed. 5. However, the most reliable way, unless you are using dates before 100 CE, is to parse the components and pass them as separate arguments to the Date constructor. There is even a way to use an Array instance for that (a construct method added to Function.prototype or Date), so you can reuse the return value of String.prototype.match(). Can I just do a simple translate, turn all slashes and dots into hyphens? Yes, you can, but it depends on the input format. Nope. Have to go regular expression if you want to change more than the first instance of something. Again, that depends on the input format. There's no nice string parse function (like sscanf with %d-%d-%d), so I hope every browser out there has a fast regex engine. I think sscanf() can be easily written (and is going to be [once again]; still working on an efficient sprintf()). But why accept the date as a string, which is known to be ambiguous, in the first place? Date input should be facilitated by three form controls, not one. The
Re: running an existing script
On Jun 22, 5:51 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: On Jun 22, 4:54 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful I just tried nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate --dir=C: \Users\Adam\Desktop\cvdata in the dos-style command prompt. It didn'g vive a syntax error this time, it just repeated my command back to me in text. I assume I called code correctly, but it didn't make a new folder full of data like it should have. Which version of jBoost, and which version of Python? ~Ethan~ jboost 2.2, python 2.7 somehow I've just managed to delete all of the code in nfold.py, now downloading it again... -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
On Jun 22, 5:51 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 22, 5:51 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: On Jun 22, 4:54 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful I just tried nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate --dir=C: \Users\Adam\Desktop\cvdata in the dos-style command prompt. It didn'g vive a syntax error this time, it just repeated my command back to me in text. I assume I called code correctly, but it didn't make a new folder full of data like it should have. Which version of jBoost, and which version of Python? ~Ethan~ jboost 2.2, python 2.7 somehow I've just managed to delete all of the code in nfold.py, now downloading it again... Thanks a lot, must be getting close now... I changed the indentation one lines 136-168, and put in the command window: nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate no syntax errors this time, it just said: nfold.py: Your CLASSPATH is not set. You must place jboost.jar in your CLASSPATH. is that the chdir() command in python? and can I somehow set that in the dos command window? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
On 22 juin, 16:07, Saul Spatz saul.sp...@gmail.com wrote: Thanks very much. This is the elegant kind of solution I was looking for. I had hoped there was a way to do it without even addressing the matter of surrogates, but apparently not. The reason I don't like this is that it depends on knowing that python internally stores strings in UTF-16. I expected that there would be some built-in iterator that would return the code points. (Actually, this all started when I realized that s[k] wouldn't necessarily give me the kth character of the string s.) A character is not a code point. Beside this, a very few knows (correct English?) a character may have more than one code point. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
Adam Chapman wrote: Thanks a lot, must be getting close now... I changed the indentation one lines 136-168, and put in the command window: nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate no syntax errors this time, it just said: nfold.py: Your CLASSPATH is not set. You must place jboost.jar in your CLASSPATH. is that the chdir() command in python? and can I somehow set that in the dos command window? CLASSPATH is an environment variable, jboost.jar is a java file (which I'm sure you know ;) -- so make sure CLASSPATH is set appropriately for your system (e.g. 'set CLASSPATH=c:\java\source'), and jboost.jar is whereever CLASSPATH points to. (I'm not a Java fan, so can't provide much help in this area.) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Security test of embedded Python
On 22-6-2011 4:44, Chris Angelico wrote: Followup: The test box has been administratively taken offline after about an hour of testing. Thank you to everyone who participated; it seems we have a lot of changes to make! Monty failed the test. But it was an incredibly successful test. And hopefully, we'll be bringing things back online for another shot once things are sorted out! Chris Angelico Maybe you should have a look at sandboxed pypy? http://pypy.org/features.html#sandboxing (disclaimer: never used it myself) Irmen -- http://mail.python.org/mailman/listinfo/python-list
doing cross platform file work
Thanks for your responses to my student question about using OS paths in Python. For the more general case, I am a Linux user interested in making my scripts platform neutral, which would include Linux, Unix (including Mac), and Windows. I have looked at the python.org os segment and didn't get an answer. Is there a library (bonus would be some tutorial material) for making sure my Linux scripts access files and directories on the other platforms transparently? I don't need the information immediately, but at some point... -- http://mail.python.org/mailman/listinfo/python-list
Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?
On 22-6-2011 5:02, John Salerno wrote: Thanks. So far they are helping me with Python too, but definitely not as much as more general exercises would, I'm sure. The part about writing the code is fun, but once that's done, I seem to end up stuck with an inefficient implementation because I don't know the math tricks behind the problem. I'll check out rubyquiz.com. I've been searching for some Python exercises to do but haven't found too many sites with them, at least not in such a nice and organized way as Project Euler. There's also SPOJ; http://www.spoj.pl/problems/classical/ It has tons of problems, many math related, but also silly ones like this: https://www.spoj.pl/problems/JAVAC/ and perhaps even useful ones like this: https://www.spoj.pl/problems/ONP/ Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: doing cross platform file work
In mailman.292.1308764714.1164.python-l...@python.org Tim Hanson tjhan...@yahoo.com writes: For the more general case, I am a Linux user interested in making my scripts platform neutral, which would include Linux, Unix (including Mac), and Windows. I have looked at the python.org os segment and didn't get an answer. Is there a library (bonus would be some tutorial material) for making sure my Linux scripts access files and directories on the other platforms transparently? I don't need the information immediately, but at some point... Your code should work on multiple platforms as long as you use standard python functions like open(), print(), close(), etc. Filesystem paths are a little trickier, as different platforms disallow different characters in filenames, but as long as you stick to a common set of characters that are legal in all cases you should be fine. And of course use os.sep. Beyond that, what did you specifically have in mind? -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, The Gashlycrumb Tinies -- http://mail.python.org/mailman/listinfo/python-list
Re: running an existing script
On Jun 22, 6:13 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 22, 5:51 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 22, 5:51 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: On Jun 22, 4:54 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 9:12 pm, Adam Chapman adamchapman1...@hotmail.co.uk wrote: On Jun 21, 8:00 pm, Ethan Furman et...@stoneleaf.us wrote: Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it say something like Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. ? If yes, then what I wrote earlier should actually work (I downloaded jBoost and looked at the nfold.py script). Here it is again: -- import os -- os.chdir('path/to/nfold.py') # don't include nfold.py ;) -- import nfold -- import sys -- sys.argv = [nfold.py, --folds=5, --data=spambase.data, ... --spec=spambase.spec, --rounds=500, --tree=ADD_ALL, ... --generate ] ... -- nfold.main() I fixed the sys.argv line from last time. Good luck! ~Ethan~ Thanks to both of you for your help. It's getting late here, I'll give it another try tomorrow I've added the python directories to the environment variable path in my computer (http://showmedo.com/videotutorials/video? name=96fromSeriesID=96), which means I can now call python from the windows DOS-style command prompt. My formatting must be wrong when calling the nfold.py script to run. My connad prompt call and the computer's response look like this: C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py nfold.py File C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scripts \nfold.py, line 13 print 'Usage: nfold.py --booster=boosttype --folds=number [-- generate | --dir=dir] [--data=file --spec=file] [--rounds=number -- tree=treetype]' ^ SyntaxError: invalid syntax What I dont understand is that some of the parameters in the syntax it printed back are in brackets, and others in [] brackets. I assume this is something a regular python user could notice straight away. Please let me know, I'd be very grateful I just tried nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate --dir=C: \Users\Adam\Desktop\cvdata in the dos-style command prompt. It didn'g vive a syntax error this time, it just repeated my command back to me in text. I assume I called code correctly, but it didn't make a new folder full of data like it should have. Which version of jBoost, and which version of Python? ~Ethan~ jboost 2.2, python 2.7 somehow I've just managed to delete all of the code in nfold.py, now downloading it again... Thanks a lot, must be getting close now... I changed the indentation one lines 136-168, and put in the command window: nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate no syntax errors this time, it just said: nfold.py: Your CLASSPATH is not set. You must place jboost.jar in your CLASSPATH. is that the chdir() command in python? and can I somehow set that in the dos command window? Thanks again Ethan, It did begin to run nfold.py this time, after I added the environment variable CLASSPATH to my system. It threw back a java error, but I guess this isn;t the right place to be asking about that C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py -- booster=Adaboost --folds=5 --data=spambase.data --spec=spambase.spec -- rounds=500 --tree=ADD_ALL --generate nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate java.lang.NoClassDefFoundError: jboost/controller/Controller Caused by: java.lang.ClassNotFoundException: jboost.controller.Controller at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: jboost.controller.Controller. Program will exit. Exception in thread main k: 0 start:0 end:920 k: 1 start:920 end:1840 k: 2 start:1840 end:2760 k: 3 start:2760 end:3680 k: 4 start:3680 end:4600
Re: running an existing script
Adam Chapman wrote: Thanks again Ethan, It did begin to run nfold.py this time, after I added the environment variable CLASSPATH to my system. It threw back a java error, but I guess this isn;t the right place to be asking about that C:\Users\Adam\Desktop\JBOOST\jboost-2.2\jboost-2.2\scriptsnfold.py -- booster=Adaboost --folds=5 --data=spambase.data --spec=spambase.spec -- rounds=500 --tree=ADD_ALL --generate nfold.py --booster=Adaboost --folds=5 --data=spambase.data -- spec=spambase.spec --rounds=500 --tree=ADD_ALL --generate java.lang.NoClassDefFoundError: jboost/controller/Controller Caused by: java.lang.ClassNotFoundException: jboost.controller.Controller at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: jboost.controller.Controller. Program will exit. Exception in thread main k: 0 start:0 end:920 Looking at the batch file I see a line that modifies the CLASSPATH, so try this before you run nfold.py (cut across two lines, but it's really just one): set CLASSPATH= %CLASSPATH%;../dist/jboost.jar;../lib/jfreechart-1.0.10.jar;../lib/jcommon-1.0.8.jar Good luck! ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
connect windows share
I want to be able to connect to a windows share via python. My end goal is to be able to recursively search through windows shares. I want to do this in Linux as well. So given a share such as \\computer\test I would like to search through the test directory and any sub directories for any file names of interest. What's the best way of going about this? I know LDAP / AD creds may play an essential part in this as well. Thanks for your input. -- http://mail.python.org/mailman/listinfo/python-list
python 3 constant
How to declare a constant in python 3? -- http://mail.python.org/mailman/listinfo/python-list
Re: connect windows share
On 22/06/2011 19:38, Travis Altman wrote: I want to be able to connect to a windows share via python. My end goal is to be able to recursively search through windows shares. I want to do this in Linux as well. So given a share such as \\computer\test I would like to search through the test directory and any sub directories for any file names of interest. What's the best way of going about this? I know LDAP / AD creds may play an essential part in this as well. Thanks for your input. Unless there's more to this than meets the eye, the answer's really easy: just do it. On Windows, you just do, eg: import os for dirpath, dirnames, filenames in os.walk (r\\computer\test): # do stuff with stuff Presumably on Linux you have to use whatever mechanism allows you to address Windows shares in the equivalent way. Maybe os.walk (smb://computer/test) ?? I'm not really a Linux person, I'm afraid TJG -- http://mail.python.org/mailman/listinfo/python-list
writable iterators?
AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? No. e = blah will rebind the indentifier 'e' with 'blah' whatever that is. That is how python works. Now, if e is mutable, say a list, you can do e.append(blah) and, since the name 'e' is not being rebound, you would see the change in 'sequence'. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On Jun 22, 2011 12:31 PM, Neal Becker ndbeck...@gmail.com wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? consider the following code x = [1,2,3] y = x[0] y = 5 Would you expect x to be [5,2,3] now? Assignment in python assigns a name to an object. It doesn't change the value of a variable. If you have a generator, you can use send() to put data in you need the actual generator itself to do that. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: connect windows share
On Jun 22, 2011 11:44 AM, Travis Altman travisalt...@gmail.com wrote: I want to be able to connect to a windows share via python. My end goal is to be able to recursively search through windows shares. I want to do this in Linux as well. So given a share such as \\computer\test I would like to search through the test directory and any sub directories for any file names of interest. What's the best way of going about this? I know LDAP / AD creds may play an essential part in this as well. Thanks for your input. -- I haven't done anything with this myself, but my guess would be that there's a Python samba wrapper somewhere that you'll want to use for this. http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: python 3 constant
On Jun 22, 2011 12:03 PM, sidRo slacky2...@gmail.com wrote: How to declare a constant in python 3? -- You don't. Python doesn't have declarations (other than global and nonlocal). Convention is that anything in all caps should be considered a constant but there's no language-level enforcement of it. -- http://mail.python.org/mailman/listinfo/python-list
Re: python 3 constant
On Wed, Jun 22, 2011 at 7:54 PM, sidRo slacky2...@gmail.com wrote: How to declare a constant in python 3? There aren't true constants in Python, but instead we use a standard defined by PEP 8, which states constants are in all caps, for example, PI = 3.14, as opposed to pi = 3.14 which could change (according to PEP 8, that is) -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. seq = [1, 2] for e in seq: ... print(e) ... e = 42 ... print(e) ... 1 42 2 42 I *guess* that what you mean by writable iterators is that rebinding e should change seq in place, i.e. you would expect that seq should now equal [42, 42]. Is that what you mean? It's not clear. Fortunately, that's not how it works, and far from being a limitation, it would be *disastrous* if iterables worked that way. I can't imagine how many bugs would occur from people reassigning to the loop variable, forgetting that it had a side-effect of also reassigning to the iterable. Fortunately, Python is not that badly designed. If you want to change the source iterable, you have to explicitly do so. Whether you can or not depends on the source: * iterators are lazy sequences, and cannot be changed because there's nothing to change (they don't store their values anywhere, but calculate them one by one on demand and then immediately forget that value); * immutable sequences, like tuples, are immutable and cannot be changed because that's what immutable means; * mutable sequences like lists can be changed. The standard idiom for that is to use enumerate: for i, e in enumerate(seq): seq[i] = e + 42 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. seq = [1, 2] for e in seq: ... print(e) ... e = 42 ... print(e) ... 1 42 2 42 I *guess* that what you mean by writable iterators is that rebinding e should change seq in place, i.e. you would expect that seq should now equal [42, 42]. Is that what you mean? It's not clear. Fortunately, that's not how it works, and far from being a limitation, it would be *disastrous* if iterables worked that way. I can't imagine how many bugs would occur from people reassigning to the loop variable, forgetting that it had a side-effect of also reassigning to the iterable. Fortunately, Python is not that badly designed. And for an iterator like def things(): yield 1 yield 11 yield 4 yield 9 I don't know what it could even mean. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode codepoints
2011/6/22 Saul Spatz saul.sp...@gmail.com: Thanks. I agree with you about the generator. Using your first suggestion, code points above U+ get separated into two surrogate pair characters fron UTF-16. So instead of U=10 I get U+DBFF and U+DFFF. -- http://mail.python.org/mailman/listinfo/python-list Hi, If you realy need the wide unicode functionality on a narrow unicode python build and only need to get the string index of characters including surrogate pairs counting as one item, you can build a list of single characters or surrogate pairs, e.g.: surrog_txt=ua̰ ̱ ̲ ̳ surrog_txt u'a\U00010330 \U00010331 \U00010332 \U00010333' print surrog_txt a̰ ̱ ̲ ̳ list(surrog_txt) [u'a', u'\ud800', u'\udf30', u' ', u'\ud800', u'\udf31', u' ', u'\ud800', u'\udf32', u' ', u'\ud800', u'\udf33'] import re re.findall(ur(?s)(?:[\ud800-\udbff][\udc00-\udfff])|., surrog_txt) [u'a', u'\U00010330', u' ', u'\U00010331', u' ', u'\U00010332', u' ', u'\U00010333'] this way, the indices, slices and len() would work on the supplementary list as expected for a normal string; however it probably won't be very efficient for longer texts. Note that surrogates are not the only asymmetry between code points, characters (and glyphs - to take the visual representation of those into account) - there are combining diacritical marks, in various combinations with precomposed diacritical characters, multiple normalisation modes etc. regards, vbr -- http://mail.python.org/mailman/listinfo/python-list
PyPad 2.7.1 Update 4
Hi All, I'm pleased to announce that PyPad 2.7.1 (Update 4), a simple python environment for the iPad / iPhone, is now available in the iTunes store. It can be found at: http://itunes.apple.com/au/app/pypad/id428928902?mt=8 Update 4 adds the ability to create multiple modules and import them into one another. The documentation is lagging a bit but the functionality can be found in the action menu of the accessory bar. Further updates planed include: Updated documentation Improving cursor interaction in interactive mode Providing access to interactive mode command history Adding iOS specific modules Syntax highlighting and more... Regards, Jon Dowdall -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed up a script that iterates over a large range (600 billion)?
On 6/22/2011 1:32 AM, Paul Rubin wrote: Terry Reedytjre...@udel.edu writes: If the best C program for a problem takes 10 seconds or more, then applying the same 1 minute limit to Python is insane, and contrary to the promotion of good algorithm thinking. The Euler problems are not the only algorithm problems posted on the web. the Euler project started in 2001, when personal computers were probably 10x slower than they are today. Yes, and I am still using a 2003 XP/Athlon machine, which is adequate for running my Python programs, though not recent games. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens inside?
On 6/22/2011 11:45 AM, Chetan Harjani wrote: why tuples are immutable whereas list are mutable? Because tuples do not have mutation methods, which lists do. Tuple and lists both have .__getitem__ but tuples do not have .__setitem__ or .__delitem__ (or .append, .extend, .sort, or .reverse). why when we do x=y where y is a list and then change a element in x, y changes too( but the same is not the case when we change the whole value in x ), whereas, in tuples when we change x, y is not affected and also we cant change each individual element in tuple. Someone please clarify. For specific answers, you should give specific examples. (1,2)[0] = 3 does not work because there is no tuple.__setitem__. But note: a = ([1,2], 3) b = a a[0][0] = 4 b ([4, 2], 3) Tuples containing mutables are not immutable all the way down. They are also not hashable (if any element is not hashable) and cannot be used as dict keys. hash(a) Traceback (most recent call last): File pyshell#5, line 1, in module hash(a) TypeError: unhashable type: 'list' -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. Yes, I understand that e = blah just rebinds e. I did not mean this as an example of working code. I meant to say, does Python have any idiom that allows iteration over a sequence such that the elements can be assigned? ... * iterators are lazy sequences, and cannot be changed because there's nothing to change (they don't store their values anywhere, but calculate them one by one on demand and then immediately forget that value); * immutable sequences, like tuples, are immutable and cannot be changed because that's what immutable means; * mutable sequences like lists can be changed. The standard idiom for that is to use enumerate: for i, e in enumerate(seq): seq[i] = e + 42 AFAIK, the above is the only python idiom that allows iteration over a sequence such that you can write to the sequence. And THAT is the problem. In many cases, indexing is much less efficient than iteration. -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
You could probably implement something like this using generators and the send method (note the example is untested and intended for 2.6: I lack Python on this machine): def gen(list_): for i, v in enumerate(list_): list_[i] = yield v def execute(): data = range(10) iterator = gen(data) lastValue = iterator.next() while True: print lastValue try: lastValue = iterator.send(lastValue + 1) except StopIteration: break print data execute() 0 1 2 3 4 5 6 7 8 9 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Chris On Wed, Jun 22, 2011 at 4:10 PM, Neal Becker ndbeck...@gmail.com wrote: Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. Yes, I understand that e = blah just rebinds e. I did not mean this as an example of working code. I meant to say, does Python have any idiom that allows iteration over a sequence such that the elements can be assigned? ... * iterators are lazy sequences, and cannot be changed because there's nothing to change (they don't store their values anywhere, but calculate them one by one on demand and then immediately forget that value); * immutable sequences, like tuples, are immutable and cannot be changed because that's what immutable means; * mutable sequences like lists can be changed. The standard idiom for that is to use enumerate: for i, e in enumerate(seq): seq[i] = e + 42 AFAIK, the above is the only python idiom that allows iteration over a sequence such that you can write to the sequence. And THAT is the problem. In many cases, indexing is much less efficient than iteration. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
Mel wrote: Steven D'Aprano wrote: I *guess* that what you mean by writable iterators is that rebinding e should change seq in place, i.e. you would expect that seq should now equal [42, 42]. Is that what you mean? It's not clear. Fortunately, that's not how it works, and far from being a limitation, it would be *disastrous* if iterables worked that way. I can't imagine how many bugs would occur from people reassigning to the loop variable, forgetting that it had a side-effect of also reassigning to the iterable. Fortunately, Python is not that badly designed. And for an iterator like def things(): yield 1 yield 11 yield 4 yield 9 I don't know what it could even mean. http://docs.python.org/reference/simple_stmts.html#the-yield-statement You could have tried to debug. Please trim your quotes to the relevant minimum. -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc: me. -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On 23/06/2011 00:10, Neal Becker wrote: Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. Yes, I understand that e = blah just rebinds e. I did not mean this as an example of working code. I meant to say, does Python have any idiom that allows iteration over a sequence such that the elements can be assigned? [snip] Python has references to objects, but not references to references. -- http://mail.python.org/mailman/listinfo/python-list
Why are my signals being ignored?
Hello Everyone, So I figured out the last problem about why I couldn't load my UI files but now I've got something that has be totally stumped. I've worked on it most of the day yesterday, Google'd it, and fought with it today and I'm admitting defeat and coming to the group with hat in hand asking for help. For some reason, in the code below, my signals are being completely ignored. For example, you'll notice that I connected the 'btnExit' to the method called 'clickedButton()' but, for some reason, when the button is clicked, the method is never called. I've been following tutorials and this seems to be the proper way to wire signals yet mine simply don't work. Would anyone be so kind as to look over the following code and give me a bit of advice (or direction) as to what I might be doing wrong? Thanks! Anthony Code: #!/usr/bin/env python import sys try: import pygtk pygtk.require(2.0) except: print Error. PYGTK could not be loaded. sys.exit(1) try: import gtk import gtk.glade except: print GTK not present or not loaded. sys,exit(1) class TestClass(object): def __init__(self): self.uiFile = MainWindow.glade self.wTree = gtk.Builder() self.wTree.add_from_file(self.uiFile) self.window = self.wTree.get_object(winMain) if self.window: self.window.connect(destroy, gtk.main_quit) dic = { on_btnExit_clicked : self.clickButton, on_winMain_destroy : gtk.main_quit } self.wTree.connect_signals(dic) self.window.show() else: print Could not load window sys.exit(1) def clickButton(self, widget): print You clicked exit! def exit(self, widget): gtk.main_quit() def update_file_selection(self, widget, data=None): selected_filename = FileChooser.get_filename() print selected_filename if __name__ == __main__: Tester = TestClass() gtk.main() -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On Thu, 23 Jun 2011 09:10 am Neal Becker wrote: Steven D'Aprano wrote: On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: AFAICT, the python iterator concept only supports readable iterators, not write. Is this true? for example: for e in sequence: do something that reads e e = blah # will do nothing I believe this is not a limitation on the for loop, but a limitation on the python iterator concept. Is this correct? Have you tried it? e = blah certainly does not do nothing, regardless of whether you are in a for loop or not. It binds the name e to the value blah. Yes, I understand that e = blah just rebinds e. I did not mean this as an example of working code. I meant to say, does Python have any idiom that allows iteration over a sequence such that the elements can be assigned? Yes. I already gave one: for i, e in enumerate(seq): seq[i] = e + 42 If you look at code written before the enumerate built-in, you will often find code like this: for i in range(len(seq)): e = seq[i] seq[i] = e + 42 Sometimes you'll find code that does this: i = 0 while i len(seq): e = seq[i] seq[i] = e + 42 i += 1 but don't do that, it's slow. Or you can do this: seq[:] = [e+42 for e in seq] There are others. [...] AFAIK, the above is the only python idiom that allows iteration over a sequence such that you can write to the sequence. And THAT is the problem. In many cases, indexing is much less efficient than iteration. Are you aware that iteration is frequently based on indexing? In the cases that it isn't, that's because the iterator generates values lazily, without ever storing them. You *can't* write to them because there's nowhere to write to! If you want to store the values so they are writable, then you have to use indexing. What makes you think that this is a problem in practice? Can you give an example of some task you can't solve because you (allegedly) can't write to a sequence? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote: Mel wrote: Steven D'Aprano wrote: I *guess* that what you mean by writable iterators is that rebinding e should change seq in place, i.e. you would expect that seq should now equal [42, 42]. Is that what you mean? It's not clear. Fortunately, that's not how it works, and far from being a limitation, it would be *disastrous* if iterables worked that way. I can't imagine how many bugs would occur from people reassigning to the loop variable, forgetting that it had a side-effect of also reassigning to the iterable. Fortunately, Python is not that badly designed. And for an iterator like def things(): yield 1 yield 11 yield 4 yield 9 I don't know what it could even mean. http://docs.python.org/reference/simple_stmts.html#the-yield-statement You could have tried to debug. I think you have missed the point of Mel's comment. He knows what the yield statement does. He doesn't know what it would mean to write to an iterator like things(). Neither do I. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Handling import errors
I did not think about using a global variable, and the top-level try...except solution is interesting. After further thinking, I have to reformulate my initial question: How do I manage to run code before my imports? For example, I want to make sure that I can use the logging module in the case an import fails, so I want to call logging.basicConfig() before this particular import. Likewise, I could want to import a module whose path is relative to an environment variable, and would want to test if this variable is set before doing so. I have come up with 2 solution templates : import logging main() def pre_import(): ... logging.basicConfig(format='%(message)s') def import(): ... global foo ... import foo def main(): ... pre_import() ... import() import logging logging.basicConfig(format='%(message)s') import foo main() def main(): ... pass To me, the latter looks better, but I could be missing something. In any case, surrounding the entire program with try...except would look like the following? try: ... import logging ... logging.basicConfig(format='%(message)s') ... import foo ... ... main() except Exception: ... # Display simple error message def main(): ... pass -- http://mail.python.org/mailman/listinfo/python-list
How to run a function in SPE on Python 2.5
I have a program: decrypt2.py which contains this function: def scramble2Decrypt(cipherText): halfLength = len(cipherText) // 2 oddChars = cipherText[:halfLength] evenChars = cipherText[halfLength:] plainText = for i in range(halfLength): plainText = plainText + evenChars[i] plainText = plainText + oddChars[i] if len(oddChars) len(evenChars): plainText = plainText + evenChars[-1] return plainText When I load this program in SPE and click on debug with winpdb i'm not sure what to do next. In Idle I would just type in scramble2Decrypt(), hit enter an get a result. I have tried to call this function from the Command box in winpdb and also at the in SPE with no luck. I want to be able to step through the program one line at a time. Any help would be appreciated for this nube. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a function in SPE on Python 2.5
On 23/06/2011 03:19, bill lawhorn wrote: I have a program: decrypt2.py which contains this function: def scramble2Decrypt(cipherText): halfLength = len(cipherText) // 2 oddChars = cipherText[:halfLength] evenChars = cipherText[halfLength:] plainText = for i in range(halfLength): plainText = plainText + evenChars[i] plainText = plainText + oddChars[i] [snip] FYI, this can be shortened to: plainText = cipherText[0 : : 2] + cipherText[1 : : 2] -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
On Wednesday, June 22, 2011 4:10:39 PM UTC-7, Neal Becker wrote: AFAIK, the above is the only python idiom that allows iteration over a sequence such that you can write to the sequence. And THAT is the problem. In many cases, indexing is much less efficient than iteration. Well, if your program is such that you can notice a difference between indexing and iteration, you probably have better things to worry about. But whatever. You can get the effect you're asking for like this: class IteratorByProxy(object): def __init__(self,iterable): self.set(iterable) def __iter__(self): return self def next(self): return self.current_iter.next() def set(self,iterable): self.current_iter = iter(iterable) s = IteratorByProxy(xrange(10)) for i in s: print i if i == 6: s.set(xrange(15,20)) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run a function in SPE on Python 2.5
Not tried SPE. But in PyScripter, as simple as that. import sys def scramble2Decrypt(cipherText): halfLength = len(cipherText) // 2 oddChars = cipherText[:halfLength] evenChars = cipherText[halfLength:] plainText = for i in range(halfLength): plainText = plainText + evenChars[i] plainText = plainText + oddChars[i] if len(oddChars) len(evenChars): plainText = plainText + evenChars[-1] return plainText if __name__ == '__main__': print sys.argv[1] print scramble2Decrypt(sys.argv[1]) Run as inside the scripter in debug mode either or run from command line as: Run-1 UserXP@prive-9dc0b2aec ~/PLScripts $ python encrypt.py asdf asdf dafs Run-2 UserXP@prive-9dc0b2aec ~/PLScripts $ python encrypt.py babababa -- http://mail.python.org/mailman/listinfo/python-list
Re: parse date string having EDT
Ben Finney ben+pyt...@benfinney.id.au wrote: Tim Roberts t...@probo.com writes: Right, because strptime doesn't support %Z. Au contraire: Support for the %Z directive is based on the values contained in tzname and whether daylight is true. Because of this, it is platform-specific except for recognizing UTC and GMT which are always known (and are considered to be non-daylight savings timezones). I do keep forgetting that Python's strptime does not just pass through to the C library. C's strptime does not support %Z. -- Tim Roberts, t...@probo.com Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: writable iterators?
Don't relate it anyhow to foreach of perl I would say, although the behaviour may be same in some aspect -- http://mail.python.org/mailman/listinfo/python-list
Re: User Authentication
On Jun 22, 7:01 pm, Adam Tauno Williams awill...@whitemice.org wrote: On Wed, 2011-06-22 at 06:34 -0700, Anurag wrote: Hi All, I am working on application which needs to do a authentication against LDAP, if LDAP not installed then local system account (administrator user in windows and root user in Linux). This should work on both Windows and Linux. See python-ldap I looked into python-ldap, it supports ldap authentication. But I didn't find anything that support local system account authentication when no LDAP both in windows and Linux. Ond more thing, somebody suggested me to use PAM. Is it a good choice and whether it supports both Windows and Linux? Please let me know which is best to use. Regards, Anurag -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens inside?
Do the same thing with an interconversion of tuple and list and you will be off to the older way: a=(1,2,3) b=list(a) b[0]=11 print a print b Output: (1, 2, 3) [11, 2, 3] -- http://mail.python.org/mailman/listinfo/python-list
Re: connect windows share
On my cygwin system I just do the following for my network drive 'q' import commands print commands.getoutput('ls /cygdrive/q') Run it as - python fileList.py Here is the output: DataTables Functions Object_Repositories Recovery_Scenarios Scripts -- http://mail.python.org/mailman/listinfo/python-list
[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'
Martin v. Löwis mar...@v.loewis.de added the comment: What are these directories? Look and see for yourself. Are they still used? Sure. If you do import DLFCN, it will come from that directory. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'
Changes by Petri Lehtinen pe...@digip.org: -- nosy: +petri.lehtinen ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12380] bytearray methods center, ljust, rjust don't accept a bytearray as the fill character
Changes by Petri Lehtinen pe...@digip.org: -- nosy: +petri.lehtinen ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'
Antoine Pitrou pit...@free.fr added the comment: So people who say sys.platform shouldn't be used: what do you propose to do with Lib/plat-linux2 (or, more generally, Lib/plat-*)? These directories look useless to me. (IIRC, putting an obvious syntax error there does not trigger any failure in the regression suite, showing that they are never imported) That's orthogonal to whether sys.platform should be used or not, however. During the language summit, someone (Marc-André) brought an interesting point: the platform does external calls to system commands such as uname, which can be time-consuming. We should at least document an example of using sys.platform.startswith() rather than exact comparison. Regards Antoine. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7434] general pprint rewrite
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- nosy: +aronacher ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7434 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7434] general pprint rewrite
Raymond Hettinger raymond.hettin...@gmail.com added the comment: Link to Armin's work on a pprint improvement based on a Ruby pprint tool: https://github.com/mitsuhiko/prettyprint -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7434 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7434] general pprint rewrite
Łukasz Langa luk...@langa.pl added the comment: Mine still lies here: https://bitbucket.org/langacore/nattyprint -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7434 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9561] distutils: set encoding to utf-8 for input and output files
Michał Górny mgo...@gentoo.org added the comment: Now that installing scripts with unicode characters was fixed, shall I open a separate bug for writing egg files with utf8 chars in author name? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9561 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12386] packaging fails in install_distinfo when writing RESOURCES
New submission from Vinay Sajip vinay_sa...@yahoo.co.uk: This part of install_distinf.run(): if install_data.get_resources_out() != []: resources_path = os.path.join(self.distinfo_dir, 'RESOURCES') logger.info('creating %s', resources_path) with open(resources_path, 'wb') as f: writer = csv.writer(f, delimiter=',', lineterminator='\n', quotechar='') for tuple in install_data.get_resources_out(): writer.writerow(tuple) fails at the writerow line: creating /tmp/venv/lib/python3.3/site-packages/nemo-0.1.dist-info/METADATA creating /tmp/venv/lib/python3.3/site-packages/nemo-0.1.dist-info/INSTALLER creating /tmp/venv/lib/python3.3/site-packages/nemo-0.1.dist-info/REQUESTED creating /tmp/venv/lib/python3.3/site-packages/nemo-0.1.dist-info/RESOURCES Traceback (most recent call last): File /tmp/venv/bin/pysetup3, line 5, in module sys.exit(main()) File /usr/local/lib/python3.3/packaging/run.py, line 678, in main return dispatcher() File /usr/local/lib/python3.3/packaging/run.py, line 667, in __call__ return func(self, self.args) File /usr/local/lib/python3.3/packaging/run.py, line 204, in wrapper return f(*args, **kwargs) File /usr/local/lib/python3.3/packaging/run.py, line 247, in _install if install_local_project(target): File /usr/local/lib/python3.3/packaging/install.py, line 125, in install_local_project return _run_install_from_dir(path) File /usr/local/lib/python3.3/packaging/install.py, line 160, in _run_install_from_dir func(source_dir) File /usr/local/lib/python3.3/packaging/install.py, line 90, in _run_packaging_install dist.run_command('install_dist') File /usr/local/lib/python3.3/packaging/dist.py, line 761, in run_command cmd_obj.run() File /usr/local/lib/python3.3/packaging/command/install_dist.py, line 526, in run self.run_command(cmd_name) File /usr/local/lib/python3.3/packaging/command/cmd.py, line 329, in run_command self.distribution.run_command(command) File /usr/local/lib/python3.3/packaging/dist.py, line 761, in run_command cmd_obj.run() File /usr/local/lib/python3.3/packaging/command/install_distinfo.py, line 116, in run writer.writerow(tuple) TypeError: 'str' does not support the buffer interface I think the open(resources_path) should use 'w' rather than 'wb' as the open mode. Relevant part of setup.cfg: resources = virtualenvwrapper.sh = {scripts} I know I can put it in the scripts = section, but I'm testing having something in resources, which ought to work ... -- assignee: tarek components: Distutils2, Library (Lib) messages: 138821 nosy: alexis, eric.araujo, tarek, vinay.sajip priority: normal severity: normal status: open title: packaging fails in install_distinfo when writing RESOURCES versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12386 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9561] distutils: set encoding to utf-8 for input and output files
Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com added the comment: Please file a separate issue. -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9561 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12087] install_egg_info fails with UnicodeEncodeError depending on locale
Changes by Michał Górny mgo...@gentoo.org: -- nosy: +mgorny ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12087 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'
R. David Murray rdmur...@bitdance.com added the comment: Indeed, the lib/plat- directories should continue to work just fine using linux3, correct? Or using linux, if we change sys.platform. (Note: just because we don't import them in the test suite doesn't mean that user code in the field isn't using them...I got a few (trivial it is true, but...) hits from google code search on DLFCN.) Changing sys.platform as Martin suggests seems like the least painful solution to me. Note, however, that we have skips in the tests suite that do care about, for example, the FreeBSD OS major version. FreeBSD does sometimes fix the bugs we've discovered...but as someone else pointed out, this doesn't necessarily happen at a major release boundary, we just use that in the test skipping because it is the easiest thing for us to do. If sys.platform no longer included the OS major version, the test skips would probably end up being made more accurate. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12326] Linux 3: tests should avoid using sys.platform == 'linux2'
Éric Araujo mer...@netwok.org added the comment: the platform does external calls to system commands such as uname, I guess it’s the platform module. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12326 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12181] SIGBUS error on OpenBSD (sparc64)
Charles-François Natali neolo...@free.fr added the comment: Here's a patch. -- keywords: +needs review, patch stage: - patch review Added file: http://bugs.python.org/file22423/kevent_openbsd.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12181 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12181] SIGBUS error on OpenBSD (sparc64)
Changes by Charles-François Natali neolo...@free.fr: Removed file: http://bugs.python.org/file22423/kevent_openbsd.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12181 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1874] email parser does not register a defect for invalid Content-Transfer-Encoding on multipart messages
Roundup Robot devnull@devnull added the comment: New changeset 5a2602939d5d by R David Murray in branch 'default': #1874: detect invalid multipart CTE and report it as a defect. http://hg.python.org/cpython/rev/5a2602939d5d -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1874 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1874] email parser does not register a defect for invalid Content-Transfer-Encoding on multipart messages
R. David Murray rdmur...@bitdance.com added the comment: Thanks for the patches. I didn't use them, but they were helpful references. This is in a grey area between a bug and a feature request. The fact is, though, that for the most part the email module currently doesn't make extra effort to detect defects, it just reports the ones it has to work around. The only exception I found to this was taking an extra step to report a defect that represented a defect in the constructed model of the message. Now, in the next version of email (targeted for 3.3), one of the design goals is to detect as many RFC conformance defects as practical. So, I'm treating this as a feature request, and have checked it in to 3.3 (default). -- resolution: - accepted stage: - committed/rejected status: open - closed type: behavior - feature request versions: +Python 3.3 -Python 2.7, Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1874 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12387] IDLE save hotkey problem
New submission from Jacob VB jacob.andrew...@gmail.com: IDLE (for Python 3.2) fails to save using the ctrl-s keyboard shortcut when caps-lock is enabled, and instead only saves when ctrl-shift-s is pressed. When caps-lock is disabled, all shortcuts work normally. -- components: IDLE messages: 138828 nosy: Jacob.VB priority: normal severity: normal status: open title: IDLE save hotkey problem type: behavior versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12387] IDLE save keyboard shortcut problem
Changes by Jacob VB jacob.andrew...@gmail.com: -- title: IDLE save hotkey problem - IDLE save keyboard shortcut problem ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12387] IDLE save keyboard shortcut problem
Jacob VB jacob.andrew...@gmail.com added the comment: IDLE (for Python 3.2) fails to save using the ctrl-s keyboard shortcut when caps-lock is enabled, and instead only saves when ctrl-shift-s is pressed. When caps-lock is disabled, all shortcuts work normally. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12387 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12313] make install misses test dirs for packaging and email modules
Vinay Sajip vinay_sa...@yahoo.co.uk added the comment: The changes have been checked in by Barry and David, so I'm closing this issue. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12313 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12383] subprocess.Popen(..., env={}) fails to pass empty env.
Roundup Robot devnull@devnull added the comment: New changeset da3af4b131d7 by Victor Stinner in branch '3.2': Issue #12383: fix test_empty_env() of subprocess on Mac OS X http://hg.python.org/cpython/rev/da3af4b131d7 New changeset 29819072855a by Victor Stinner in branch 'default': (merge 3.2) Issue #12383: fix test_empty_env() of subprocess on Mac OS X http://hg.python.org/cpython/rev/29819072855a -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12383 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com