Re: fastest data structure for retrieving objects identified by (x, y) tuple?
On Oct 4, 2012 3:02 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > # populate a random matrix using both dict and list > adict = {} > alist = [[None]*2400 for i in range(2400)] > from random import randrange > for i in range(1000): > x = randrange(2400) > y = randrange(2400) > adict[(x, y)] = "something" > alist[x][y] = "something" > > import sys > print(sys.getsizeof(adict)) > print(sys.getsizeof(alist) + sum(sys.getsizeof(L) for L in alist)) > > > The actual sizes printed will depend on how sparse the matrices are, but > for the same above (approximately half full), using Python 2.7, the > figures I get are: > > adict: 24712 > alist: 23127324 I make it 0.02% full. If it was half full the dict might not have a memory advantage. Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > Take care, > > Ty > > http://tds-solutions.net > > The aspen project: a barebones light-weight mud engine: > > http://code.google.com/p/aspenmud > > He that will not reason is a bigot; he that cannot reason is a fool; he that > dares not reason is a slave. I use pylint with NINJA IDE. NINJA IDE automatically shows common problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On 4 October 2012 04:11, Littlefield, Tyler wrote: > pHello all: > I've seen frameworks like django reload files when it detects that they've > been changed; how hard would it be to make my engine reload files that it > detects were changed? I tend to think that it's better to reload things explicitly. But if you do want to monitor your files for changes you can use something like this: http://packages.python.org/watchdog/ > I'm also curious how hard it would be to build in some > error recovery. For example right now when an exception occurs, the player > is sometimes just left hanging. The general idea is to try and make state changes atomic. In other words if an error occurs during an operation the previous state should be kept or restored. A simple way to do this is to ensure that anything that might generate an error is run before anything that changes state e.g.: def change_my_values(self, intvalue_string, floatvalue_string): # Do all processing first (might generate errors) iv = int(intvalue_string) fv = float(floatvalue_string) # Then change state self.intvalue = iv self.floatvalue = fv In this simple case, you can get the same effect with: def change_my_values(self, invalue_string, floatvalue_string): self.intvalue, self.floatvalue = in(intvalue_string), float(floatvalue_string) A more sophisticated way might use something like: oldstate = current_state() try: set_state(compute_new_state()) except: restore_state(oldstate) raise Naturally this is quite tedious if you have to put try/except everywhere, but this kind of exception handling can easily be factored out into a context manager. > It's a lot harder with Python for me, > because I don't get the compile-time errors that I would with c++ for > example to know that I did something wrong; while that's not always > useful/and by far it doesn't catch everything, it does help. Use unit tests. > I'm familiar > with things like pychecker, but it seems to be reporting a lot of issues > that aren't issues. You may find those useful but they are not a substitute for unit tests. > For example, I have a world module which is the core of > the engine; it handles players, as well as keeps tracks of all rooms that > are loaded in the game and that. Because player and world would have > circular imports, I just pass the world object into player functions like > logon/create. Pychecker tells me that the world parameter (which is a local > var at that point) shadows the world variable in world; world is a > singleton, so when you import world it just has a world = World() at the > bottom of the module. I would let the main script import World and create the world instance rather than placing a global variable in the world module. > > also: I have the following code: > logging.basicConfig(filename=path.join("logs", "mud.log"), > level=logging.DEBUG) > logger = logging.getLogger(__name__) > logger.addHandler(logging.StreamHandler()) > I like it displaying to stderr since usually when I'm doing this I'm in > screen bouncing back and forth between the output and the tt++ session, but > right now I can't get a couple of things; I'm not sure how to set it to log > and all other messages to stderr as I did for the file, and I'd like to use > a rotating log handler so that it'll rotate when the files are say above 16 > KB or something. Is it possible to do something like this; perhaps make it > compress the file before it writes to disk, or call a command to do so, so > that it wouldn't hang the entire mud while it compresses? Use a standard system tool to manage your server logs. For example logrotate(8) >From the manpage: ''' logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. ''' Oscar -- http://mail.python.org/mailman/listinfo/python-list
How to print html in python the normal way
Hi, I wrote a simple filter as: @register.filter() def html(value): return 'Check' when I use this filter in my template, it displays html as: Check I want to display as: Check am I missing something. - Thanks for your help Ashish -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print html in python the normal way
On Thu, Oct 4, 2012 at 9:24 PM, wrote: > am I missing something. The first thing you're missing is more detail in your question. My crystal ball tells me you're using some kind of web framework and viewing this in your browser. And my second crystal ball suggests that it's probably Django. But is this correct? Lots more detail, please! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 109, Issue 20
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=1, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest data structure for retrieving objects identified by (x, y) tuple?
On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: How do you know that? No offence, but if you can't even work out whether lookups in a dict or a list are faster, I can't imagine why you think you can intuit what the fastest way to retrieve the nearest neighbours would be. Whats wrong with the test below? # randomly select matrix coordinates to look-up from random import randrange test_coords = [] for i in range(1000): x = randrange(2400); y = randrange(2400); test_coords.append((x, y)) # build objects class Object():pass obj1 = Object(); obj2 = Object(); obj1.up = obj2 # build some test code from timeit import Timer setup = "from __main__ import test_coords, obj1, obj2" t = Timer("for p in test_coords: obj = obj1.up", setup) # run the test code print(min(t.repeat(number=1, repeat=7))) import platform print(platform.python_version()) On my system, I get: 0.719622326348 2.7.1 -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print html in python the normal way
On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote: > On Thu, Oct 4, 2012 at 9:24 PM, wrote: > > > am I missing something. > > > > The first thing you're missing is more detail in your question. My > > crystal ball tells me you're using some kind of web framework and > > viewing this in your browser. And my second crystal ball suggests that > > it's probably Django. But is this correct? Lots more detail, please! > > > > ChrisA +1 -- http://mail.python.org/mailman/listinfo/python-list
Re: design question:game skill system
On Wednesday, 3 October 2012 14:19:57 UTC+5:30, Jean-Michel Pichavant wrote: > - Original Message - > > > Hello all: > > > I'm looking at a skill/perk system, where the player builds up his > > > char > > > by using perk points to add abilities. > > > Each perk is under a category, and generally costs go up as you > > > increase > > > the perk. > > > So I'm trying to figure something out; first, I'd really like the > > > cost > > > calculation and all of that to be dynamic, so that I don't have to > > > write > > > a calculateCost per object. I'd also like to be able to specify > > > dependencies and say a level, as well as other factors before a > > > player > > > can obtain a perk and have them self documenting. The idea is that a > > > player could do something like: > > > data perk extended health > > > and it would tell them they require health at 50 before they can > > > purchase extended health, as well as the cost, the increase per level > > > and the total overall cost. > > > Any ideas on how to set this up would be really appreciated. > > > Finally, I'm curious how to store and calculate these. I thought > > > about > > > using a uid per perk, then storing something like: {uid:level} on the > > > player, but means that I have to lookup the name somehow still in the > > > main perk database, then use that uid to check if the player has it. > > > Are > > > there better ways of storing skills? I'm also thinking about > > > calculation; currently the CalculateMaxHp method would have to add up > > > all the possible perks for health, then add stats and all that. That > > > could get really rough on performance if it's called often; would > > > something like a cache work, where you have something like: > > > {attribute:dirty}? So if I call CalculateHealth, it checks for the > > > dirty > > > flag, and if it doesn't exist just returns the previous max HP, but > > > if > > > the dirty flag is set, it recalculates? Then anything modifying > > > health > > > (level gains, perks, stat increases/etc) would just set the dirty > > > flag > > > and call calculate? > > > Thoughts/ideas would be welcome. > > > Thanks, > > > > Hi, > > > > Again, do not think about performances before actually having an issue with > them. What's the point to optimize something that doesn't need it ? > > > > For your cache problem, google "python memoize decorator" for a bunch of > decorators that will allow you to cache your data without any effort. > > > > JM True, but I always have an irresistible urge to optimize to every yoctosecond even if its absolutely useless to optimize. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print html in python the normal way
On Thu, Oct 4, 2012 at 9:11 AM, Ramchandra Apte wrote: > On Thursday, 4 October 2012 17:00:57 UTC+5:30, Chris Angelico wrote: >> On Thu, Oct 4, 2012 at 9:24 PM, wrote: >> >> > am I missing something. >> >> You should look at the built in django tags, and learn about them before writing your own In this case, look here: https://docs.djangoproject.com/en/dev/topics/templates/#filters striptags Strips all [X]HTML tags. For example: {{ value|striptags }} If value is "Joel is a slug", the output will be "Joel is a slug". Again, these are just a few examples; see the built-in filter reference for the complete list. -- Joel Goldstick -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On Thursday, 4 October 2012 08:41:35 UTC+5:30, Littlefield, Tyler wrote: > pHello all: > > I've seen frameworks like django reload files when it detects that > > they've been changed; how hard would it be to make my engine reload > > files that it detects were changed? I'm also curious how hard it would > > be to build in some error recovery. For example right now when an > > exception occurs, the player is sometimes just left hanging. It's a lot > > harder with Python for me, because I don't get the compile-time errors > > that I would with c++ for example to know that I did something wrong; > > while that's not always useful/and by far it doesn't catch everything, > > it does help. I'm familiar with things like pychecker, but it seems to > > be reporting a lot of issues that aren't issues. For example, I have a > > world module which is the core of the engine; it handles players, as > > well as keeps tracks of all rooms that are loaded in the game and that. > > Because player and world would have circular imports, I just pass the > > world object into player functions like logon/create. Pychecker tells me > > that the world parameter (which is a local var at that point) shadows > > the world variable in world; world is a singleton, so when you import > > world it just has a world = World() at the bottom of the module. > > > > also: I have the following code: > > logging.basicConfig(filename=path.join("logs", "mud.log"), > > level=logging.DEBUG) > > logger = logging.getLogger(__name__) > > logger.addHandler(logging.StreamHandler()) > > I like it displaying to stderr since usually when I'm doing this I'm in > > screen bouncing back and forth between the output and the tt++ session, > > but right now I can't get a couple of things; I'm not sure how to set it > > to log and all other messages to stderr as I did for the file, and I'd > > like to use a rotating log handler so that it'll rotate when the files > > are say above 16 KB or something. Is it possible to do something like > > this; perhaps make it compress the file before it writes to disk, or > > call a command to do so, so that it wouldn't hang the entire mud while > > it compresses? > > Thanks, and sorry again for all the questions. > > > > -- > > Take care, > > Ty > > http://tds-solutions.net > > The aspen project: a barebones light-weight mud engine: > > http://code.google.com/p/aspenmud > > He that will not reason is a bigot; he that cannot reason is a fool; he that > dares not reason is a slave. Solution for the logging problem is to use to use logging.handlers.BaseRotatingHandler [0] ^0 http://docs.python.org/dev/library/logging.handlers.html#baserotatinghandler "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python Meeting Düsseldorf - 23.10.2012
[This announcement is in German since it targets a local user group meeting in Düsseldorf, Germany] ANKÜNDIGUNG Python Meeting Düsseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosphäre. Dienstag, 23.10.2012, 18:00 Uhr Clara Schumann Raum DJH Düsseldorf Diese Nachricht können Sie auch online lesen: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2012-10-23 EINLEITUNG Das Python Meeting Düsseldorf (http://pyddf.de/) ist eine neue lokale Veranstaltung in Düsseldorf, die sich an Python Begeisterte in der Region wendet. Wir starten bei den Treffen mit einer kurzen Einleitung und gehen dann zu einer Reihe Kurzvorträgen (Lightning Talks) über, bei denen die Anwesenden über neue Projekte, interessante Probleme und sonstige Aktivitäten rund um Python berichten können. Anschließend geht es in eine Gaststätte, um die Gespräche zu vertiefen. Einen guten Überblick über die Vorträge bietet unser YouTube-Kanal, auf dem wir die Vorträge nach den Meetings veröffentlichen: http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, Düsseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ORT Für das Python Meeting Düsseldorf haben wir den Clara Schumann Raum in der modernen Jugendherberge Düsseldorf angemietet: Jugendherberge Düsseldorf Düsseldorfer Str. 1 40545 Düsseldorf Telefon: +49 211 557310 http://www.duesseldorf.jugendherberge.de Die Jugendherberge verfügt über eine kostenpflichtige Tiefgarage (EUR 2,50 pro Stunde, maximal EUR 10,00). Es ist aber auch möglich per Bus und Bahn anzureisen. Der Raum befindet sich im 1.OG links. PROGRAMM Das Python Meeting Düsseldorf nutzt eine Mischung aus Open Space und Lightning Talks: Die Treffen starten mit einer kurzen Einleitung. Danach geht es weiter mit einer Lightning Talk Session, in der die Anwesenden Kurzvorträge von fünf Minuten halten können. Hieraus ergeben sich dann meisten viele Ansatzpunkte für Diskussionen, die dann den Rest der verfügbaren Zeit in Anspruch nehmen können. Für 19:45 Uhr haben wir in einem nahegelegenen Restaurant Plätze reserviert, damit auch das leibliche Wohl nicht zu kurz kommt. Lightning Talks können vorher angemeldet werden, oder auch spontan während des Treffens eingebracht werden. Ein Beamer mit XGA Auflösung steht zur Verfügung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an i...@pyddf.de KOSTENBETEILIGUNG Das Python Meeting Düsseldorf wird von Python Nutzern für Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19% Mwst. Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ANMELDUNG Da wir nur für ca. 20 Personen Sitzplätze haben, möchten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an i...@pyddf.de WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Grüßen, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 04 2012) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ 2012-09-27: Released eGenix PyRun 1.1.0 ... http://egenix.com/go35 2012-09-26: Released mxODBC.Connect 2.0.1 ... http://egenix.com/go34 2012-09-25: Released mxODBC 3.2.1 ... http://egenix.com/go33 2012-10-23: Python Meeting Duesseldorf ... 19 days to go eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On Thu, 04 Oct 2012 06:34:28 -0700, Ramchandra Apte wrote: > "Optimize code always even if it causes bugs" - Ramchandra Apte, 2001- Well, you've just added yourself into my list of people whose advice should always be ignored. That is *terrible* advice. But if you insist on following it, you can optimize *any* Python program to this: # === start code === pass # this line is optional # === end code === There you go. The most heavily optimized, fastest Python program in existence. Sure, it has a few bugs, but boy is it fast!!! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest data structure for retrieving objects identified by (x, y) tuple?
On Thu, 04 Oct 2012 08:21:13 -0400, Benjamin Jessup wrote: > On 10/4/2012 12:20 AM, python-list-requ...@python.org wrote: >> How do you know that? >> >> No offence, but if you can't even work out whether lookups in a dict or >> a list are faster, I can't imagine why you think you can intuit what >> the fastest way to retrieve the nearest neighbours would be. > > Whats wrong with the test below? [snip code] I don't know. Is this a trick question? Is the answer, "nothing is wrong"? It doesn't seem to be very useful code, but since I don't know what you think you are testing, I can't tell you whether you are doing it wrong or not. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On Fri, Oct 5, 2012 at 12:00 AM, Steven D'Aprano wrote: > That is *terrible* advice. But if you insist on following it, you can > optimize *any* Python program to this: > > # === start code === > pass # this line is optional > # === end code === > > > There you go. The most heavily optimized, fastest Python program in > existence. Sure, it has a few bugs, but boy is it fast!!! Not many bugs though! I ran it in my Python 5.2.7 for GNU/Windows 256-bit (err, yeah, I borrowed Guido's time machine but had the silly thing in reverse... oops) and it worked perfectly, except that indentation has moved from "significant" to "mandatory". When I added the necessary 5 space indent at the beginning, it correctly created world peace, ensured that Australia won the next Test Match, and then printed "Hello, world!\n" to stdout. Unfortunately, a bug in your "end code" comment meant that the peace it created was by wiping out all life, but that's pretty minor in the scheme of things. Optimization really is that important, folks! ChrisA may need to schedule surgical detongueing of his cheek -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is pylaucher in Python 3.3 being installed in Windows folder?
On Oct 4, 6:30 am, Chris Rebert wrote: > Presumably because Program Files isn't part of the > $PATH.http://superuser.com/questions/124239/what-is-the-default-path-enviro... > Contrast (from the PEP): "However, the Windows directory is always on the > path." I guess that's the reason indeed. > Now, as for why the launcher must be on the $PATH…*shrugs* Now, the question is why not put pylauncher together with python.exe now, when 3.3 has an option to add Python's folder to the PATH? In case there are more than one Python installed this would mean changing pylauncher when changing active Python (via PATH modification). Maybe that's undesired? If so then installing to Program Files and adding its folder to PATH the same way Python's folder is added would be much better than installing into Windows folder. -- http://mail.python.org/mailman/listinfo/python-list
Re: final question: logging to stdout and updating files
On Wed, 03 Oct 2012 21:11:29 -0600, Littlefield, Tyler wrote: > I've seen frameworks like django reload files when it detects that > they've been changed; how hard would it be to make my engine reload > files that it detects were changed? Oh, about as hard as writing a program. What sort of files? What does your engine do? How does it do it? Without knowing the answers to these questions, how can we possibly tell you how hard it will be to reload them? Detecting changed files is easy. If you google for "python monitor directory" and similar terms, you will find a metric tonne of solutions. Having your engine reload files is entirely up to you: it's your engine, it will be as trivial or as difficult as you make it be. > I'm also curious how hard it would be to build in some error recovery. How long is a piece of string? Again, that depends on you. If you design your application with error recovery in mind, it could be trivial. If you don't, it could be impossible. > For example right now when an > exception occurs, the player is sometimes just left hanging. It's a lot > harder with Python for me, because I don't get the compile-time errors > that I would with c++ for example to know that I did something wrong; > while that's not always useful/and by far it doesn't catch everything, > it does help. Sure, compiler-time checks can sometimes be useful. But in general, they tend to only detect the most trivial errors, syntax errors (Python does that too) and type errors. In Python, the usual answer is to concentrate on writing good unit tests. Good unit tests will test far more than the compiler ever could, and will pay for themselves a hundred times over. > I'm familiar with things like pychecker, but it seems to > be reporting a lot of issues that aren't issues. Pychecker, like other linters, don't just report fatal errors. They may also report *suspicious code* which may indicate an error, poor techniques, unused code, bad naming conventions, or other examples of poor style. You should be able to turn off such warnings. > For example, I have a > world module which is the core of the engine; it handles players, as > well as keeps tracks of all rooms that are loaded in the game and that. > Because player and world would have circular imports Right there is a terrible *code smell*. http://www.joelonsoftware.com/articles/Wrong.html Maybe you have a good reason for a circular import, but alarm bells are ringing. Rather than having: # world.py import player # player.py import world which leads to all sorts of complications, it is usually better to have a single module import both world and player and then combine them as needed. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Combinations of lists
2012/10/4 Joshua Landau : > On 3 October 2012 21:15, Steen Lysgaard wrote: >> >> Hi, >> >> thanks for your interest. Sorry for not being completely clear, yes >> the length of m will always be half of the length of h. > > > (Please don't top post) > > I have a solution to this, then. > It's not short or fast, but it's a lot faster than yours. > > But first let me explain the most obvious optimization to your version of > the code: > >> combs = set() >> >> >> for a in permutations(range(len(h)),len(h)): >> comb = [] >> for i in range(len(h)): >> comb.append(c[i][a[i]]) >> comb.sort() >> >> frzn = tuple(comb) >> if frzn not in combs: >> combs.add(frzn) > > > What I have done here is make your "combs" a set. This helps because you > are searching inside it and that is an O(N) operation... for lists. > A set can do the same in O(1). Simplez. > > first = list("AABBCCDDEE") > second = list("abcde") > import itertools > # > # Generator, so ignoring case convention > class force_unique_combinations: > def __init__(self, lst, n): > self.cache = set() > self.internal_iter = itertools.combinations(lst, n) > def __iter__(self): > return self > def __next__(self): > while True: > nxt = next(self.internal_iter) > if not nxt in self.cache: > self.cache.add(nxt) > return nxt > def combine(first, second): > sletter = second[0] > first_combinations = force_unique_combinations(first, 2) > if len(second) == 1: > for combination in first_combinations: > yield [sletter+combination[0], sletter+combination[1]] > else: > for combination in first_combinations: > first_ = first[:] > first_.remove(combination[0]) > first_.remove(combination[1]) > prefix = [sletter+combination[0], sletter+combination[1]] > for inner in combine(first_, second[1:]): > yield prefix + inner > > > This is quite naive, because I don't know how to properly implement > force_unique_combinations, but it runs. I hope this is right. If you need > significantly more speed your best chance is probably Cython or C, although > I don't doubt 10x more speed may well be possible from within Python. > > > Also, 8 Dihedral is a bot, or at least pretending like crazy to be one. Great, I've now got a solution much faster than what I could come up with. Thanks to the both of you. And a good spot on 88... I could not for my life understand what he (it) had written. /Steen -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is pylaucher in Python 3.3 being installed in Windows folder?
On Thu, Oct 4, 2012 at 8:41 AM, Piotr Dobrogost wrote: > Now, the question is why not put pylauncher together with python.exe > now, when 3.3 has an option to add Python's folder to the PATH? In > case there are more than one Python installed this would mean changing > pylauncher when changing active Python (via PATH modification). Maybe > that's undesired? If so then installing to Program Files and adding > its folder to PATH the same way Python's folder is added would be much > better than installing into Windows folder. It shouldn't go in the Python folder. There can be more than one active Python installation, but there should really be only one active pylauncher installation. They should also be kept separate for uninstallation. So the launcher should have its own separate Program Files folder. I don't see why it's so important that the location be on the path in the first place, though. As I understand it this tool is primarily intended to support the .py and .pyw file associations, and those are best looked up in the registry, not on the path. The only reason I can see for having it on the path is for when you want to explicitly invoke it on the command line, and for that we can either add the Program Files location to the path or just let the user deal with setting the path, as many Windows programs do. > I raised this issue at http://bugs.python.org/issue16131 Unfortunately, with Python 3.3 already released, I suspect that it's probably too late to change this. -- http://mail.python.org/mailman/listinfo/python-list
How can I hide my stack frames in a TestCase subclass?
I want to add a custom assert method to a TestCase subclass. I tried to copy my implementation from the unittest module so that it would match the behaviour of the regular TestCase as closely as possible. (I would prefer to just delegate to self.assertEqual() but this causes even more backtrace noise, see below.) The unittest module seems to automatically hide some internal details of its implementation when reporting failed assertions. import unittest class MyTestCase(unittest.TestCase): def assertLengthIsOne(self, sequence, msg=None): if len(sequence) != 1: msg = self._formatMessage(msg, "length is not one") raise self.failureException(msg) class TestFoo(MyTestCase): seq = (1, 2, 3, 4, 5) def test_stock_unittest_assertion(self): self.assertEqual(len(self.seq), 1) def test_custom_assertion(self): self.assertLengthIsOne(self.seq) unittest.main() The output of this is as such: amoe@vuurvlieg $ python unittest-demo.py FF == FAIL: test_custom_assertion (__main__.TestFoo) -- Traceback (most recent call last): File "unittest-demo.py", line 16, in test_custom_assertion self.assertLengthIsOne(self.seq) File "unittest-demo.py", line 7, in assertLengthIsOne raise self.failureException(msg) AssertionError: length is not one == FAIL: test_stock_unittest_assertion (__main__.TestFoo) -- Traceback (most recent call last): File "unittest-demo.py", line 13, in test_stock_unittest_assertion self.assertEqual(len(self.seq), 1) AssertionError: 5 != 1 -- Ran 2 tests in 0.000s FAILED (failures=2) Note that the custom assert method causes a stack trace with two frames, one inside the method itself, whereas the stock unittest method only has one frame, the relevant line in the user's code. How can I apply this frame-hiding behaviour to my own method? -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest data structure for retrieving objects identified by (x, y) tuple?
Am 04.10.2012 03:58 schrieb Steven D'Aprano: alist = [[None]*2400 for i in range(2400)] from random import randrange for i in range(1000): x = randrange(2400) y = randrange(2400) adict[(x, y)] = "something" alist[x][y] = "something" The actual sizes printed will depend on how sparse the matrices are, but for the same above (approximately half full), I wouldn't consider 1000 of 576 "half full"... Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is pylaucher in Python 3.3 being installed in Windows folder?
On 4 October 2012 16:51, Ian Kelly wrote: > On Thu, Oct 4, 2012 at 8:41 AM, Piotr Dobrogost > wrote: >> Now, the question is why not put pylauncher together with python.exe >> now, when 3.3 has an option to add Python's folder to the PATH? In >> case there are more than one Python installed this would mean changing >> pylauncher when changing active Python (via PATH modification). Maybe >> that's undesired? If so then installing to Program Files and adding >> its folder to PATH the same way Python's folder is added would be much >> better than installing into Windows folder. > > It shouldn't go in the Python folder. There can be more than one > active Python installation, but there should really be only one active > pylauncher installation. They should also be kept separate for > uninstallation. So the launcher should have its own separate Program > Files folder. > > I don't see why it's so important that the location be on the path in > the first place, though. As I understand it this tool is primarily > intended to support the .py and .pyw file associations, and those are > best looked up in the registry, not on the path. The only reason I > can see for having it on the path is for when you want to explicitly > invoke it on the command line, and for that we can either add the > Program Files location to the path or just let the user deal with > setting the path, as many Windows programs do. Having them on PATH means that you can do: > py script.py and the effect will be analogous to (in a unix shell): $ ./script.py Of course the idea with the launcher is that you just do > script.py The difference - on my machine - between explicitly using invoking py and allowing the file association to do it is that the latter breaks when redirecting stdin (this is an old bug in Windows): Q:\>script.py < foo Traceback (most recent call last): File "Q:\script.py", line 5, in for line in sys.stdin: IOError: [Errno 9] Bad file descriptor Q:\>py script.py < foo LOTS OF STUFF It would be good to be able to choose where to put the launchers. Unless I missed something that wasn't an option in the installer. It lets you choose the location of all the other files by choosing where to put the Python folder. Also it's not as simple as just moving them to where you want after install since they are associated with the registry keys for running .py and .pyw files. As it happens, since I don't have access to the WINDOWS folder on my work machine, the installer did just put them into the Python33 folder (which is fine with me). Oscar -- http://mail.python.org/mailman/listinfo/python-list
Re: Can somebody give me an advice about what to learn?
> >> The point why Ruby was started (perceived deficit of > >> object-orientation) has been remedied since Python 2.2. > > > > Not completely. At the least, there's arguably still the issue of > > len() and friends (vs. `.length` etc.), and also of `self` being > > explicit. > > I'm not entirely sure which "perceived deficit of object-orientation" > is being talked about, or why anyone but OOP purists would consider > that a problem. Yukihiro Matsumoto did. I myself never perceived any lack of object-orientation with Python, since I've learned programming with Pascal anyway. >;-> I just wanted to point out that given the state of Python today, no one would probably consider starting Ruby any more. Sincerely, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
notmm is dead!
Dear list, Due to lack of energy and resources i'm really sad to announce the removal of notmm from pypi and bitbucket. I deleted also my account from bitbucket as it was not really useful for me. notmm will continue to be accessible from my master site at http://gthc.org/dist/notmm until the server get down, as I cannot find money to pay for the hosting of notmm.org, neither anyone to encourage the project so it can grow further. I have tried to develop a coherent extension for Django using the open source model but I'm afraid to have been bitten by its failure to encourage a free market over one dictated by profit and the use of cheap tricks to compete unfairly with perhaps too much openness. I always will also continue to love and use free softwares but sadly it seems asking for a little fairness is too much asked to competitors dedicated in stealing and subverting my work for their own advantages... I therefore refuse to continue any longer being mocked by competitors asking excessive prices for having a broken Internet dictated by a few companies and decide the content I should be visiting. Shall you have anything you wish saying I'll be open to discuss further on this list. I wish also to thanks the supporters of the project who have invested time and energy into my business and dedication to the notmm project. Best wishes, Etienne -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ e...@gthcfoundation.org "If a free society cannot help the many who are poor, it cannot save the few who are rich." -John F. Kennedy -- http://mail.python.org/mailman/listinfo/python-list
Anybody know what's up with Gmane?
Good evening all, I read some 20 Python mailing lists through Gmane using Thunderbird on Windows but nothing new has arrived for almost 24 hours, hence why I've reluctantly resorted to Google groups to try and find out what is going on. Looking directly at http://news.gmane.org/gmane.comp.python.general shows the last post was the Steven D'Aprano thread titled "Emulating C++ namespaces with ChainMap and metaclass trickery" on 3 Oct at 20:26. I've tried flagging this up but obviously with no success. Anyone any ideas on how to sort this out? Kindest regards. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: Combinations of lists
On Thursday, October 4, 2012 11:12:41 PM UTC+8, Steen Lysgaard wrote: > 2012/10/4 Joshua Landau : > > > On 3 October 2012 21:15, Steen Lysgaard wrote: > > >> > > >> Hi, > > >> > > >> thanks for your interest. Sorry for not being completely clear, yes > > >> the length of m will always be half of the length of h. > > > > > > > > > (Please don't top post) > > > > > > I have a solution to this, then. > > > It's not short or fast, but it's a lot faster than yours. > > > > > > But first let me explain the most obvious optimization to your version of > > > the code: > > > > > >> combs = set() > > >> > > >> > > >> for a in permutations(range(len(h)),len(h)): > > >> comb = [] > > >> for i in range(len(h)): > > >> comb.append(c[i][a[i]]) > > >> comb.sort() > > >> > > >> frzn = tuple(comb) > > >> if frzn not in combs: > > >> combs.add(frzn) > > > > > > > > > What I have done here is make your "combs" a set. This helps because you > > > are searching inside it and that is an O(N) operation... for lists. > > > A set can do the same in O(1). Simplez. > > > > > > first = list("AABBCCDDEE") > > > second = list("abcde") > > > import itertools > > > # > > > # Generator, so ignoring case convention > > > class force_unique_combinations: > > > def __init__(self, lst, n): > > > self.cache = set() > > > self.internal_iter = itertools.combinations(lst, n) > > > def __iter__(self): > > > return self > > > def __next__(self): > > > while True: > > > nxt = next(self.internal_iter) > > > if not nxt in self.cache: > > > self.cache.add(nxt) > > > return nxt > > > def combine(first, second): > > > sletter = second[0] > > > first_combinations = force_unique_combinations(first, 2) > > > if len(second) == 1: > > > for combination in first_combinations: > > > yield [sletter+combination[0], sletter+combination[1]] > > > else: > > > for combination in first_combinations: > > > first_ = first[:] > > > first_.remove(combination[0]) > > > first_.remove(combination[1]) > > > prefix = [sletter+combination[0], sletter+combination[1]] > > > for inner in combine(first_, second[1:]): > > > yield prefix + inner > > > > > > > > > This is quite naive, because I don't know how to properly implement > > > force_unique_combinations, but it runs. I hope this is right. If you need > > > significantly more speed your best chance is probably Cython or C, although > > > I don't doubt 10x more speed may well be possible from within Python. > > > > > > > > > Also, 8 Dihedral is a bot, or at least pretending like crazy to be one. > > > > Great, I've now got a solution much faster than what I could come up with. > > Thanks to the both of you. > > And a good spot on 88... I could not for my life understand what he > > (it) had written. > > > > /Steen If an unique order is defined, then it is trivial to solve this problem without any recursions. -- http://mail.python.org/mailman/listinfo/python-list
sum function
Hi All, I am new to python and am getting the data from hbase. I am trying to do sum on the column as below scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) total = 0.0 r = client.scannerGet(scanner) while r: for k in (r[0].columns): total += float(r[0].columns[k].value) r = client.scannerGet(scanner) print total Do you know of better (faster) way to do sum? Any thoughts please? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On Thu, Oct 4, 2012 at 2:52 PM, wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > total = 0.0 > r = client.scannerGet(scanner) > while r: > for k in (r[0].columns): > total += float(r[0].columns[k].value) > r = client.scannerGet(scanner) > > print total > > Do you know of better (faster) way to do sum? scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) next_r = itertools.partial(client.scannerGet, scanner) total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly wrote: > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) > next_r = itertools.partial(client.scannerGet, scanner) > total = sum(float(col.value) for r in iter(next_r, None) for col in > r.itervalues()) That should be "functools" above, not "itertools". :-P -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
I get below error NameError: name 'functools' is not defined Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
Thanks Ian for the quick reply. I get the below error. NameError: name 'itertools' is not defined Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On 10/04/2012 05:29 PM, Mike wrote: > I get below error > > NameError: name 'functools' is not defined > functools is a module in the standard library. You need to import it. import functools -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On Fri, Oct 5, 2012 at 7:29 AM, Mike wrote: > I get below error > > NameError: name 'functools' is not defined > > Thanks functools is a module: import functools ChrisA -- http://mail.python.org/mailman/listinfo/python-list
RE: Experimental Python-based shell
(A little quoting manipulation to make it easier to read with appropriate context.) > > On Wed, Oct 3, 2012 at 11:25 AM, Amirouche Boubekki > > wrote: > > > 2012/10/3 Jonathan Hayward > > > The chief benefit besides the searching, so far, is that you can use Py3k > > > mixed with shell commands as the > > > scripting language--so script in Python instead of bash. > > > > > > When using Python for scripting, Python lines are indented by an extra > > > tab (or four spaces) while shell-like > > > commands are not indented. So: > > > > cjsh> for index in range(10): > > > > echo %(index)d > > > > > > > 0 > > > 1 > > > 2 [snip] > > > > > Echo could (and maybe should) be a built-in, but it isn't. The output is > > > os.system()'ed to bash, which echoes > > > based on a command that includes the value of a Python variable. The > > > implementation is a bit crude, but it is > > reasonably powerful. > > > > > > I have other things on the agenda, like making it able to run scripts and > > > doing fuzzy matching, but for now > > > those are the main two attractions. > > > > Is it possible to drop completly the bash syntax and use some python > > library (I saw it on github) that wraps > > bash commands with python functions or the other around making it possible > > to call python functions with a bash- > > like syntax. The syntax you are talking about seems strange. > > > > Regards, > > > > Amirouche Jonathan Hayward wrote: > I am open to suggestions and patches. I don't think the syntax strange, > though: it offers a clear and distinct > way to differentiate Python and shell commands, and shell commands can access > Python variables when specified. > And it is a simple rule, without footnotes needed. I need more footnotes. :) Does every shell command not have indentation? How can you tell if the shell command is supposed to be in the loop or after the loop? for index in range(10): # do something echo %(index)d Is the above equivalent to Python pseudo-code solution A or B? Solution A, for index in range(10): #do something Popen('echo', file_path) Solution B, for index in range(10): #do something Popen('echo', file_path) How do I make achieve the other solution? This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
RE: final question: logging to stdout and updating files
Chris Angelico wrote: > Sent: Thursday, October 04, 2012 9:28 AM > To: python-list@python.org > Subject: Re: final question: logging to stdout and updating files > > On Fri, Oct 5, 2012 at 12:00 AM, Steven D'Aprano > wrote: > > That is *terrible* advice. But if you insist on following it, you can > > optimize *any* Python program to this: > > > > # === start code === > > pass # this line is optional > > # === end code === > > > > > > There you go. The most heavily optimized, fastest Python program in > > existence. Sure, it has a few bugs, but boy is it fast!!! > > Not many bugs though! I ran it in my Python 5.2.7 for GNU/Windows > 256-bit (err, yeah, I borrowed Guido's time machine but had the silly > thing in reverse... oops) and it worked perfectly, except that > indentation has moved from "significant" to "mandatory". When I added > the necessary 5 space indent at the beginning, it correctly created > world peace, ensured that Australia won the next Test Match, and then > printed "Hello, world!\n" to stdout. Unfortunately, a bug in your "end > code" comment meant that the peace it created was by wiping out all > life, but that's pretty minor in the scheme of things. Python is a product for Americans! ;) It should ensure America wins the Test Matchwait, do we even have a cricket team? > > Optimization really is that important, folks! > > ChrisA > may need to schedule surgical detongueing of his cheek Think we could get a group rate for c.l.p? Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
Thanks, but I tried all that and don't have much energy for continuing. If you're serious about open source then maybe you can forward the thread to django-developers and get some fundings to pay for a minimalistic fee to get the project maintained by someone else, otherwise I'd prefer sticking with more profitable activities. E On Fri, 5 Oct 2012 08:23:05 +1000 Chris Angelico wrote: > On Fri, Oct 5, 2012 at 8:11 AM, Etienne Robillard > wrote: > > For $399 i give you the current source code and you can do whatever you > > like with it, including > > putting in github or sf. i think to have lost too many time already with > > further > > maintaining the open source version without getting a penny out of it. > > Like I said, I'm not personally interested; but perhaps say that to > the django list and someone'll bite. But if you're really tired of it, > then just post the source code and someone may end up taking your > project to places you never had the energy to. > > > There was - and, incidentally, still kinda is - a project called Gmud, > a 32-bit (but Win32s compatible) Windows MUD client. Its author asked > people to send him money if they liked and used the program - $US20 I > think - but almost nobody ever did. For years, Gmud was the > recommended Windows client for Threshold RPG, and yet still something > like *four* people ever sent the author money. So the author threw the > source out to the world and said "I'm done, have fun". > > Enter the Threshold RPG community. Gmud has been extremely popular (in > fact, some people still use it today), in spite of some limitations > that may have been reasonable a few years ago, but are ridiculous now, > like a fixed 500-line scrollback buffer. So some of the people there > ask me to grab the source, tweak a few things, and recompile. I'm a > geek, I do these sorts of things. > > Well, it turned out to be not that simple, for a few reasons. But > eventually, after a near-complete rewrite, I produced a new MUD client > that uses the same look and feel as Gmud, as an acknowledged > derivative. RosMud++ is now the officially recommended Windows client > for Threshold, and it would never have happened if Gmud's source > hadn't been given away. > > > It's really hard to make money off software, these days. Which is a > pity, because there's lots of good software that'd be worth money. I > do see your pain. :( This is part of why my newest MUD client, Gypsum, > is open-sourced from the very beginning. > > ChrisA -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ e...@gthcfoundation.org -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
On Fri, Oct 5, 2012 at 9:13 AM, Etienne Robillard wrote: > Thanks, but I tried all that and don't have much energy for continuing. If > you're > serious about open source then maybe you can forward the thread to > django-developers > and get some fundings to pay for a minimalistic fee to get the project > maintained > by someone else, otherwise I'd prefer sticking with more profitable > activities. Apologies to all for the non sequitur, Etienne and I were indulging in an off-list conversation. I don't mind it being public (there's nothing secret in it), but it may be a tad confusing to those who just got the tail end of that! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest data structure for retrieving objects identified by (x,y) tuple?
On Thu, 04 Oct 2012 18:11:28 +0200, Thomas Rachel wrote: > Am 04.10.2012 03:58 schrieb Steven D'Aprano: >> alist = [[None]*2400 for i in range(2400)] from random import randrange >> for i in range(1000): >> x = randrange(2400) >> y = randrange(2400) >> adict[(x, y)] = "something" >> alist[x][y] = "something" > >> The actual sizes printed will depend on how sparse the matrices are, >> but for the same above (approximately half full), > > I wouldn't consider 1000 of 576 "half full"... Doh! I obviously can't multiply... I mean, well done, that was a deliberate test to see who was paying attention, and you passed! :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
Err not exactly.. :) Firstly notmm is still ISC licensed and available from here http://gthc.org/notmm/dist/. Secondly i don't want to leave it to the hands of people without I can get a single dime for the work did, however some peoples don't seem to get this point yet.. My apologies if you feel this removal was rude anyways. Feel free to contact me again if you need further clarification or would like to take over maintainership of a branch for a minimal fee. Kind regards, Etienne On 05 Oct 2012 00:22:06 GMT Steven D'Aprano wrote: > On Thu, 04 Oct 2012 14:10:46 -0400, Etienne Robillard wrote: > > > Dear list, > > > > Due to lack of energy and resources i'm really sad to announce the > > removal of notmm from pypi and bitbucket. > > Well that's just rude. Even if you don't intend to maintain the software > any more, why are you removing it from pypi? Since you say you are a fan > of Open Source software, just flag it as unmaintained and leave it for > somebody else to pick up. > > If you are going to abandon the project, release it on PyPI with a dual > MIT and GPL licence, and let it be taken over by somebody else. > > If you were looking for sympathy here, starting off by removing your > project from free hosting, then complaining that you can't pay for the > non-free hosting, was NOT the right way to do so. > > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ e...@gthcfoundation.org -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote: > On 10/04/2012 05:29 PM, Mike wrote: > > > I get below error > > > > > > NameError: name 'functools' is not defined > > > > > > > functools is a module in the standard library. You need to import it. > > > > import functools > > > > > > > > -- > > > > DaveA I imported functools. Now I get the below error please. Traceback (most recent call last): File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) File "test.py", line 16, in total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) AttributeError: 'list' object has no attribute 'itervalues' Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
On Thu, Oct 4, 2012 at 6:22 PM, Steven D'Aprano wrote: > By the way, the latest version of notmm (0.4.4) has an empty licence > file. No licence means that everyone using it is unlicenced and therefore > infringing your copyright. It's an ISC license. The notmm-0.4.4/LICENSE file is a link to the notmm-0.4.4/notmm-0.4.4-rc7/LICENSE file, unless your archiver fails to reconstruct the link when untarring, in which case the former ends up as an empty file (but the latter is still present). -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
You probably have a old tarball or something... $ wget http://gthc.org/dist/notmm/notmm-0.4.4.tar.gz $ md5sum notmm-0.4.4.tar.gz dff1b2ec5373b5157cf79d57169a336e notmm-0.4.4.tar.gz Cheers, Etienne On Thu, 4 Oct 2012 18:46:18 -0600 Ian Kelly wrote: > On Thu, Oct 4, 2012 at 6:22 PM, Steven D'Aprano > wrote: > > By the way, the latest version of notmm (0.4.4) has an empty licence > > file. No licence means that everyone using it is unlicenced and therefore > > infringing your copyright. > > It's an ISC license. The notmm-0.4.4/LICENSE file is a link to the > notmm-0.4.4/notmm-0.4.4-rc7/LICENSE file, unless your archiver fails > to reconstruct the link when untarring, in which case the former ends > up as an empty file (but the latter is still present). > -- > http://mail.python.org/mailman/listinfo/python-list -- Etienne Robillard Green Tea Hackers Club Fine Software Carpentry For The Rest Of Us! http://gthc.org/ e...@gthcfoundation.org -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
On Thu, Oct 4, 2012 at 6:40 PM, Mike wrote: > Traceback (most recent call last): > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, None) for col in > r.itervalues()) > File "test.py", line 16, in > total = sum(float(col.value) for r in iter(next_r, None) for col in > r.itervalues()) > AttributeError: 'list' object has no attribute 'itervalues' "r.itervalues()" should have been "r[0].columns.itervalues()", I think. It's hard to test code against an API that you don't have. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody know what's up with Gmane?
In article <4509cf54-a71d-44cc-90a5-0abd7c6a8...@googlegroups.com>, Mark Lawrence wrote: > I read some 20 Python mailing lists through Gmane using Thunderbird on > Windows but nothing new has arrived for almost 24 hours, hence why I've > reluctantly resorted to Google groups to try and find out what is going on. > Looking directly at http://news.gmane.org/gmane.comp.python.general shows the > last post was the Steven D'Aprano thread titled "Emulating C++ namespaces > with ChainMap and metaclass trickery" on 3 Oct at 20:26. > > I've tried flagging this up but obviously with no success. Anyone any ideas > on how to sort this out? There were problems on one of the gmane servers. The problem was fixed as of about three hours ago and things should be returning to normal. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I hide my stack frames in a TestCase subclass?
David Banks wrote: > I want to add a custom assert method to a TestCase subclass. I tried to > copy my implementation from the unittest module so that it would match > the behaviour of the regular TestCase as closely as possible. (I would > prefer to just delegate to self.assertEqual() but this causes even more > backtrace noise, see below.) The unittest module seems to automatically > hide some internal details of its implementation when reporting failed > assertions. > > import unittest > > class MyTestCase(unittest.TestCase): > def assertLengthIsOne(self, sequence, msg=None): > if len(sequence) != 1: > msg = self._formatMessage(msg, "length is not one") > raise self.failureException(msg) > > class TestFoo(MyTestCase): > seq = (1, 2, 3, 4, 5) > > def test_stock_unittest_assertion(self): > self.assertEqual(len(self.seq), 1) > > def test_custom_assertion(self): > self.assertLengthIsOne(self.seq) > > > unittest.main() > > The output of this is as such: > > amoe@vuurvlieg $ python unittest-demo.py > FF > == > FAIL: test_custom_assertion (__main__.TestFoo) > -- > Traceback (most recent call last): > File "unittest-demo.py", line 16, in test_custom_assertion > self.assertLengthIsOne(self.seq) > File "unittest-demo.py", line 7, in assertLengthIsOne > raise self.failureException(msg) > AssertionError: length is not one > > == > FAIL: test_stock_unittest_assertion (__main__.TestFoo) > -- > Traceback (most recent call last): > File "unittest-demo.py", line 13, in test_stock_unittest_assertion > self.assertEqual(len(self.seq), 1) > AssertionError: 5 != 1 > > -- > Ran 2 tests in 0.000s > > FAILED (failures=2) > > Note that the custom assert method causes a stack trace with two frames, > one inside the method itself, whereas the stock unittest method only has > one frame, the relevant line in the user's code. How can I apply this > frame-hiding behaviour to my own method? Move MyTestCase in a separate module and define a global variable __unittest = True $ cat mytestcase.py import unittest __unittest = True class MyTestCase(unittest.TestCase): def assertLengthIsOne(self, sequence, msg=None): if len(sequence) != 1: msg = self._formatMessage(msg, "length is not one") raise self.failureException(msg) $ cat mytestcase_demo.py import unittest from mytestcase import MyTestCase class TestFoo(MyTestCase): seq = (1, 2, 3, 4, 5) def test_stock_unittest_assertion(self): self.assertEqual(len(self.seq), 1) def test_custom_assertion(self): self.assertLengthIsOne(self.seq) if __name__ == "__main__": unittest.main() $ python mytestcase_demo.py FF == FAIL: test_custom_assertion (__main__.TestFoo) -- Traceback (most recent call last): File "mytestcase_demo.py", line 11, in test_custom_assertion self.assertLengthIsOne(self.seq) AssertionError: length is not one == FAIL: test_stock_unittest_assertion (__main__.TestFoo) -- Traceback (most recent call last): File "mytestcase_demo.py", line 8, in test_stock_unittest_assertion self.assertEqual(len(self.seq), 1) AssertionError: 5 != 1 -- Ran 2 tests in 0.000s FAILED (failures=2) $ -- http://mail.python.org/mailman/listinfo/python-list
Re: Anybody know what's up with Gmane?
On 10/4/2012 3:03 PM, Mark Lawrence wrote: > I read some 20 Python mailing lists through Gmane using Thunderbird > on Windows but nothing new has arrived for almost 24 hours, hence why > I've reluctantly resorted to Google groups to try and find out what > is going on. Looking directly at > http://news.gmane.org/gmane.comp.python.general shows the last post > was the Steven D'Aprano thread titled "Emulating C++ namespaces with > ChainMap and metaclass trickery" on 3 Oct at 20:26. > > I've tried flagging this up but obviously with no success. Anyone > any ideas on how to sort this out? This is the longest outage I remember, but it is back up now. I am reading and replying via gmane. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Experimental Python-based shell
Indexing Python code is ugly. I suggest prefixing non-Python with $. On 10/3/2012 1:24 PM, Jonathan Hayward wrote: I am open to suggestions and patches. I don't think the syntax strange, though: it offers a clear and distinct way to differentiate Python and shell commands, and shell commands can access Python variables when specified. And it is a simple rule, without footnotes needed. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: + in regular expression
On 04/10/2012 04:01, contro opinion wrote: str=" gg" x1=re.match("\s+",str) x1 <_sre.SRE_Match object at 0xb7354db0> x2=re.match("\s{6}",str) x2 <_sre.SRE_Match object at 0xb7337f38> x3=re.match("\s{6}+",str) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/re.py", line 137, in match return _compile(pattern, flags).match(string) File "/usr/lib/python2.6/re.py", line 245, in _compile raise error, v # invalid expression sre_constants.error: multiple repeat why the "\s{6}+" is not a regular pattern? Why are you too lazy to do any research before posting a question? -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list
Re: unit testing class hierarchies
On 10/3/2012 5:33 AM, Oscar Benjamin wrote: On 3 October 2012 02:20, Steven D'Aprano wrote: But surely, regardless of where that functionality is defined, you still need to test that both D1 and D2 exhibit the correct behaviour? Otherwise D2 (say) may break that functionality and your tests won't notice. Given a class hierarchy like this: class AbstractBaseClass: spam = "spam" class D1(AbstractBaseClass): pass class D2(D1): pass I write tests like this: class TestD1CommonBehaviour(unittest.TestCase): cls = D1 def testSpam(self): self.assertTrue(self.cls.spam == "spam") def testHam(self): self.assertFalse(hasattr(self.cls, 'ham')) class TestD2CommonBehaviour(TestD1CommonBehaviour): cls = D2 That's an excellent idea. I wanted a convenient way to run the same tests on two classes in order to test both a pure python and a cython-accelerator module implementation of the same class. Python itself has same issue with testing Python and C coded modules. It has the additional issue that the Python class by default import the C version, so additional work is needed to avoid that and actually test the python code. For instance, heapq.test_heapq.py has ... py_heapq = support.import_fresh_module('heapq', blocked=['_heapq']) c_heapq = support.import_fresh_module('heapq', fresh=['_heapq']) ... class TestHeap(TestCase): module = None ... class TestHeapPython(TestHeap): module = py_heapq @skipUnless(c_heapq, 'requires _heapq') class TestHeapC(TestHeap): module = c_heapq ... def test_main(verbose=None): test_classes = [TestModules, TestHeapPython, TestHeapC, # TestHeap is omitted from the list and not run directly -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: sum function
I agree with you, Ian. Thanks for all the help. Now I get the below error. File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) File "test.py", line 17, in total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues()) Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: + in regular expression
On 10/04/2012 04:59 PM, Mark Lawrence wrote: why the "\s{6}+" is not a regular pattern? Why are you too lazy to do any research before posting a question? Errr... what? I'm only somewhat familiar with the extra stuff that languages provide in their regexs beyond true regular expressions and simple extensions, but I was surprised to see the question because I too would have expected that to work. (And match any sequence of whitespace characters whose length is a multiple of six.) I reskimmed the documentation of the re module and didn't see anything that would prohibit it. I looked at several of the results of a Google search for the multiple repeat error, and didn't really find any explanation beyond "because you can't do it" or "here's a regex that works." (Well, OK, I did see a mention of + being a possessive quantifier which Python doesn't support. But that still doesn't explain why my expectation isn't what happened.) In what way is that an unreasonable question? Evan -- http://mail.python.org/mailman/listinfo/python-list
Re: notmm is dead!
On 10/04/2012 05:13 PM, Etienne Robillard wrote: > Thanks, but I tried all that and don't have much energy for continuing. If > you're > serious about open source then maybe you can forward the thread to > django-developers > and get some fundings to pay for a minimalistic fee to get the project > maintained > by someone else, otherwise I'd prefer sticking with more profitable > activities. Nothing in the existing license prevents someone from taking the latest source and posting it back on Pypi as an unmaintained package. Isn't that correct? What are you referring to when you say "minimalistic fee." Would this be a fee you require for transferring copyright assignment? I know of no fee necessary for a new maintainer to take over should one wish to. Copyright assignment is not strictly necessary. -- http://mail.python.org/mailman/listinfo/python-list
RE: + in regular expression
x3=re.match("\s{6}+",str) instead use x3=re.match("\s{6,}",str) This serves the purpose. And also give some food for thought for why the first one throws an error. Cheers, Saroo -Original Message- From: Python-list [mailto:python-list-bounces+saroo_jain=infosys@python.org] On Behalf Of Mark Lawrence Sent: Friday, October 05, 2012 3:29 AM To: python-list@python.org Subject: Re: + in regular expression On 04/10/2012 04:01, contro opinion wrote: str=" gg" x1=re.match("\s+",str) x1 > <_sre.SRE_Match object at 0xb7354db0> x2=re.match("\s{6}",str) x2 > <_sre.SRE_Match object at 0xb7337f38> x3=re.match("\s{6}+",str) > Traceback (most recent call last): >File "", line 1, in >File "/usr/lib/python2.6/re.py", line 137, in match > return _compile(pattern, flags).match(string) >File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error, v # invalid expression > sre_constants.error: multiple repeat > > why the "\s{6}+" is not a regular pattern? > > > Why are you too lazy to do any research before posting a question? -- Cheers. Mark Lawrence. -- http://mail.python.org/mailman/listinfo/python-list CAUTION - Disclaimer * This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS End of Disclaimer INFOSYS*** -- http://mail.python.org/mailman/listinfo/python-list
Re: Experimental Python-based shell
On 10/3/2012 4:22 PM, Terry Reedy wrote: Indexing Python code is ugly. I suggest prefixing non-Python with $. Indenting, meaning indenting the Python header lines but not non-Python lines. On 10/3/2012 1:24 PM, Jonathan Hayward wrote: I am open to suggestions and patches. I don't think the syntax strange, though: it offers a clear and distinct way to differentiate Python and shell commands, and shell commands can access Python variables when specified. And it is a simple rule, without footnotes needed. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Embedded Python 3 porting issues when passing FILE* to PyRun_SimpleFile() in Windows mixed-compiler environment
Hi. I'm trying to convert a large C application that embeds Python so it works with Python 3, and am running into an new API limitation I can't solve. I have a report from Windows users that there is a crashing problem occurring with calls to PyRun_SimpleFile (and similar functions). This appears to happen when people are using a Python DLL compiled with one compiler (e.g., MicroSoft's) and the application with another compiler (e.g., MinGW/gcc). The basic problem is that C type (FILE*) is not defined by the Windows OS, but instead is specific to the compiler and its associated runtime-environment. So therefore it is not safe to pass a FILE* across DLL boundaries. However many of the Python C API functions only accept a FILE*. Under Python 2 a work-around was used by calling the PyFile_FromString() then PyFile_AsFile(), to effectively get the underlying fopen() to occur inside the Python DLL so that an incompatible FILE* is not passed across the DLL boundary. However many of those PyFile functions, including PyFile_FromFile(), were removed from the Python 3 API. So how can one safely call PyRun_SimpleFile() in Python 3 in Windows where different compilers could be used? Thanks -- Deron Meranda http://deron.meranda.us/ -- http://mail.python.org/mailman/listinfo/python-list
Re: + in regular expression
On Thu, Oct 4, 2012 at 9:44 PM, Saroo Jain wrote: > x3=re.match("\s{6}+",str) > > instead use > x3=re.match("\s{6,}",str) > > This serves the purpose. And also give some food for thought for why the > first one throws an error. That matches six or more spaces, not multiples of six spaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: + in regular expression
On 03Oct2012 21:17, Ian Kelly wrote: | On Wed, Oct 3, 2012 at 9:01 PM, contro opinion wrote: | > why the "\s{6}+" is not a regular pattern? | | Use a group: "(?:\s{6})+" Yeah, it is probably a precedence issue in the grammar. "(\s{6})+" is also accepted. -- Cameron Simpson Disclaimer: ERIM wanted to share my opinions, but I wouldn't let them. - David Wiseman -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I hide my stack frames in a TestCase subclass?
Peter Otten scripsit : > David Banks wrote: > >> Note that the custom assert method causes a stack trace with two frames, >> one inside the method itself, whereas the stock unittest method only has >> one frame, the relevant line in the user's code. How can I apply this >> frame-hiding behaviour to my own method? > > Move MyTestCase in a separate module and define a global variable > > __unittest = True > Hum, is it documented somewhere? I can't find it in the doc. Also, I'm curious to know what kind of magic it's using. -- Manuel Pégourié-Gonnard - http://people.math.jussieu.fr/~mpg/ -- http://mail.python.org/mailman/listinfo/python-list