What language to manipulate text files
I want to do some tricky text file manipulation on many files, but have only a little programming knowledge. What are the ideal languages for the following examples? 1. Starting from a certain folder, look in the subfolders for all filenames matching *FOOD*.txt Any files matching in each folder should be copied to a new subfolder within the current folder called EATING with a new name of *FOOD*COPY.txt 2. Process each file as follows: Here is a simplified example of what I want as input and output. - input . 'several unknown lines of text file Get apples from apples shop Get oranges from oranges shop Get plums from plums shop Get pears from pears shop Eat from apples, oranges, plums, pears'whitespace at start of line is unimportant . 'more unknown lines of text file Chapter 1 Several lines of text about apples in here Chapter 2 Several lines of text about oranges in here Chapter 3 Several lines of text about plums in here Chapter 4 Several lines of text about pears in here - output . 'several unknown lines of text file Get apples from apples shop Get oranges from oranges shop Get plums from plums shop Get pears from pears shop Get bagels from bagels shop 'the Get lines... Get donuts from donuts shop 'can be in any order Eat from apples, bagels, oranges, plums, donuts, pears'whitespace at start of line is unimportant . 'more unknown lines of text file Chapter 1 Several lines of text about apples in here Chapter 2 Several lines of text about bagels in here Chapter 3 Several lines of text about oranges in here Chapter 4 Several lines of text about plums in here Chapter 5 Several lines of text about donuts in here Chapter 6 Several lines of text about pears in here Summary: I have added two new items to Get; I have put them into the comma-delimited list after searching for a particular fruit to put each one after; The Chapters are renumbered to match their position in the comma-delimited list. The several lines of text about each new item can be pulled from a new_foods.txt file (or a bagels.txt and a donuts.txt file). My first objective is to process the files as described. My second objective is to learn the best language for this sort of text manipulation. The language should run on Windows 98, XP and Linux. Would Python be best, or would a macro-scripting thing like AutoHotKey work? I thought about Perl, but think I would learn bad habits and have hard to read code. Thanks, Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: What language to manipulate text files
Roose wrote: Why do people keep asking what language to use for certain things in the Python newsgroup? Obviously the answer is going to biased. Not that it's a bad thing because I love Python, but it doesn't make sense if you honestly want an objective opinion. R What usenet group is it best to ask in then? Is there one where people have good knowledge of many scripting languages? Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: What language to manipulate text files
I tried Bash on Cygwin, but did not know enough about setting up the environment to get it working. Instead I got an excellent answer from alt.msdos.batch which used the FOR IN DO command. My next job is to learn Python. Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: Filtering out non-readable characters
On 15 Jul 2005 17:33:39 -0700, MKoool [EMAIL PROTECTED] wrote: I have a file with binary and ascii characters in it. I massage the data and convert it to a more readable format, however it still comes up with some binary characters mixed in. I'd like to write something to just replace all non-printable characters with '' (I want to delete non-printable characters). I am having trouble figuring out an easy python way to do this... is the easiest way to just write some regular expression that does something like replace [^\p] with ''? Or is it better to go through every character and do ord(character), check the ascii values? What's the easiest way to do something like this? thanks Easiest way is open the file with EdXor (freeware editor), select all, Format Wipe Non-Ascii. Ok it's not python, but it's the easiest. -- http://mail.python.org/mailman/listinfo/python-list
Cross-Platform Bonjour Module
Can anybody point me to a Python module for using the mDNSResponder stuff (http://developer.apple.com/networking/bonjour)? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
league problem in python
I'm new to programming and have chosen Python as my first language. I've gone through Allen Downey's Think Python book and I think I'm ready to dive into a project. The first problem I've chosen to tackle is a problem I have seen at my tennis club. Each spring/fall, the pro puts out a sheet of paper for people to sign up for tennis leagues. Depending on how many people sign up for a league, he'll assign a certain number of courts each week to that league. After this, he makes up a schedule of who plays who on each week and who has a bye. Unfortunately, he does this by hand and a lot of times, some people will play certain people more than once and certain other people never. Other problems that arise: some people have more bye weeks than others, some people have all their bye weeks clumped together so that they don't play for weeks on end. I would like to create a simple program where the pro could enter in how many people were in the league, the number of courts available, and the number of weeks the schedule would run and then generate a schedule where everybody played everybody else once and got the same number of bye weeks, preferably spaced out evenly. How should I go about starting this problem...I'm feel like this is a really simple problem, but I'm having writer's/coder's block. Can you guys help? -- http://mail.python.org/mailman/listinfo/python-list
possible pairings in a set
I'm new to python and I'm trying to come up with a function that takes a given number of players in a game and returns all possible unique pairings. Here's the code I've come up with so far, but I'm not getting the output I'd like to: def all_pairings(players): cleanlist = [] for i in range(players): cleanlist.append(i) return cleanlist start = 0 follow = start +1 finallist = [] while follow = len(cleanlist)-1: for player in cleanlist: mini = cleanlist[start],cleanlist[follow] finallist.append(mini) follow +=1 start+=1 return finallist If I were to execute the function with all_pairings(4), I want to get the output [[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]. Instead, I get [0,1,2,3] with the code I currently have. Can you guys help me out? Also, if my code is considered ugly or redundant by this community, can you make suggestions to clean it up? -- http://mail.python.org/mailman/listinfo/python-list
sharing/swapping items between lists
I'm trying to design an iterator that produces two lists. The first list will be a list of unique pairings and the second will be a list of items that weren't used in the first list. After each round, the items that weren't used in the round before will get put back in and the second list will be populated with unique items. To clarify, here's an example of what my output would be if I had 8 items: First Iteration LIST 1LEFTOVERS LIST [(1,2),(3,4),(5,6)] [7,8] Second Iteration [(1,3), (2,7),(4,8)] [5,6] Third Iteration [(1,5), (2,6), (7,8)][3,4] etc Additionally, I want the items in the leftovers list to be used the same amount. Can you guys suggest an approach to this problem...I'm trying to teach myself python so an outline of how to approach this would probably be more helpful to me than an explicit solution. I'll cry mercy if I can't figure it out after your hints. -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing/swapping items between lists
On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote: In article 4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com, Ross ross.j...@gmail.com wrote: I'm trying to design an iterator that produces two lists. The first list will be a list of unique pairings and the second will be a list of items that weren't used in the first list. After each round, the items that weren't used in the round before will get put back in and the second list will be populated with unique items. How do you specify what goes into the first list? Based on your description, I would have expected that the output from the first iteration would be ( [(1,2),(3,4),(5,6)], [7,8] ) Regardless of the actual algorithm, if you are returning items one at a time and maintaining state in a computation, you probably want to use a generator. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? I'm sorry...my example was probably a bad one. A better example of output I would like would be something like [[1,2],[3,4],[5,6]] and then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is produce some sort of round robin algorithm for tennis that is constrained by the number of courts available each week. So if there are only 3 courts available for a singles league and 10 people have signed up, 4 players will have a bye each week. I want my algorithm to produce unique matchups each week and also give each player the same angle? -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing/swapping items between lists
On Apr 13, 9:08 am, a...@pythoncraft.com (Aahz) wrote: In article c569228f-f391-4317-83a2-08621c601...@r8g2000yql.googlegroups.com, Ross ross.j...@gmail.com wrote: I'm sorry...my example was probably a bad one. A better example of output I would like would be something like [[1,2],[3,4],[5,6]] and then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is produce some sort of round robin algorithm for tennis that is constrained by the number of courts available each week. So if there are only 3 courts available for a singles league and 10 people have signed up, 4 players will have a bye each week. I want my algorithm to produce unique matchups each week and also give each player the same angle? How about Googling for round robin algorithm python? ;-) -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? I have the basic algorithm and it works fine...I'm just having trouble adding another parameter to it that allows for court constraints and bye weeks. -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing/swapping items between lists
On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: In article f64c9de2-3285-4f74-adb8-2111c78b7...@37g2000yqp.googlegroups.com, Ross ross.j...@gmail.com wrote: On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: In article c569228f-f391-4317-83a2-08621c601...@r8g2000yql.googlegroups.= com, Ross =A0ross.j...@gmail.com wrote: I'm sorry...my example was probably a bad one. A better example of output I would like would be something like [[1,2],[3,4],[5,6]] and then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is produce some sort of round robin algorithm for tennis that is constrained by the number of courts available each week. So if there are only 3 courts available for a singles league and 10 people have signed up, 4 players will have a bye each week. I want my algorithm to produce unique matchups each week and also give each player the same angle? How about Googling for round robin algorithm python? ;-) I have the basic algorithm and it works fine...I'm just having trouble adding another parameter to it that allows for court constraints and bye weeks. You'll need to give us more information, then. Why don't you start with the core algorithm you're using? -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? Here's the core algorithm I'm using: def round_robin(teams,rounds): if len(teams)%2: teams.append(None) mid = len(teams) //2 for i in range(rounds): yield zip(teams[:mid], teams[mid:]) teams = teams[0:1] + teams[mid:mid+1] + teams[1:mid-1]+teams[mid +1:]+teams[mid-1:mid] if __name__== '__main__': rounds = 15 teams = range(16) for round in round_robin(teams,rounds): print round -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing/swapping items between lists
On Apr 14, 10:34 am, Ross ross.j...@gmail.com wrote: On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: In article f64c9de2-3285-4f74-adb8-2111c78b7...@37g2000yqp.googlegroups.com, Ross ross.j...@gmail.com wrote: On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: In article c569228f-f391-4317-83a2-08621c601...@r8g2000yql.googlegroups.= com, Ross =A0ross.j...@gmail.com wrote: I'm sorry...my example was probably a bad one. A better example of output I would like would be something like [[1,2],[3,4],[5,6]] and then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is produce some sort of round robin algorithm for tennis that is constrained by the number of courts available each week. So if there are only 3 courts available for a singles league and 10 people have signed up, 4 players will have a bye each week. I want my algorithm to produce unique matchups each week and also give each player the same angle? How about Googling for round robin algorithm python? ;-) I have the basic algorithm and it works fine...I'm just having trouble adding another parameter to it that allows for court constraints and bye weeks. You'll need to give us more information, then. Why don't you start with the core algorithm you're using? -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? Here's the core algorithm I'm using: def round_robin(teams,rounds): if len(teams)%2: teams.append(None) mid = len(teams) //2 for i in range(rounds): yield zip(teams[:mid], teams[mid:]) teams = teams[0:1] + teams[mid:mid+1] + teams[1:mid-1]+teams[mid +1:]+teams[mid-1:mid] if __name__== '__main__': rounds = 15 teams = range(16) for round in round_robin(teams,rounds): print round fyi rounds=15 and teams =range(16) was just test code I was playing around with...they could theoretically be anything. -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing/swapping items between lists
On Apr 14, 7:18 pm, Aaron Brady castiro...@gmail.com wrote: On Apr 14, 7:01 pm, Aaron Brady castiro...@gmail.com wrote: On Apr 14, 12:37 pm, Ross ross.j...@gmail.com wrote: On Apr 14, 10:34 am, Ross ross.j...@gmail.com wrote: On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote: In article f64c9de2-3285-4f74-adb8-2111c78b7...@37g2000yqp.googlegroups.com, Ross ross.j...@gmail.com wrote: On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote: In article c569228f-f391-4317-83a2-08621c601...@r8g2000yql.googlegroups.= com, Ross =A0ross.j...@gmail.com wrote: I'm sorry...my example was probably a bad one. A better example of output I would like would be something like [[1,2],[3,4],[5,6]] and then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is produce some sort of round robin algorithm for tennis that is constrained by the number of courts available each week. So if there are only 3 courts available for a singles league and 10 people have signed up, 4 players will have a bye each week. I want my algorithm to produce unique matchups each week and also give each player the same angle? How about Googling for round robin algorithm python? ;-) I have the basic algorithm and it works fine...I'm just having trouble adding another parameter to it that allows for court constraints and bye weeks. You'll need to give us more information, then. Why don't you start with the core algorithm you're using? -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Why is this newsgroup different from all other newsgroups? Here's the core algorithm I'm using: def round_robin(teams,rounds): if len(teams)%2: teams.append(None) mid = len(teams) //2 for i in range(rounds): yield zip(teams[:mid], teams[mid:]) teams = teams[0:1] + teams[mid:mid+1] + teams[1:mid-1]+teams[mid +1:]+teams[mid-1:mid] if __name__== '__main__': rounds = 15 teams = range(16) for round in round_robin(teams,rounds): print round fyi rounds=15 and teams =range(16) was just test code I was playing around with...they could theoretically be anything. Here is an idea. Create a list of all possible pairs, using itertools.combinations. You'll notice everyone gets equal play time and equal time against each other on a pair-by-pair basis. Then, call random.shuffle until one player isn't playing on two courts in one day. This might take a long time. Not that I can guarantee that a depth- first-search would be any faster, or that a breadth-first-search would run faster *and* run in available memory. cough I have a sub-optimal solution that I'm playing with now. Since my output is a list of tuples and looks something like this (if there were 16 teams and 15 rounds), I could designate a each nth tuple in each round as a bye, but since the 1st item in my list remains fixed, it's suboptimal. For example, you could say every 4th (and/or 3rd , 5th, etc depending on how many available cts) tuple in each round gets a bye and pop() it from the list...: [(0, 8), (1, 9), (2, 10), (3, 11), (4, 12), (5, 13), (6, 14), (7, 15)] [(0, 9), (8, 10), (1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 7)] [(0, 10), (9, 11), (8, 12), (1, 13), (2, 14), (3, 15), (4, 7), (5, 6)] [(0, 11), (10, 12), (9, 13), (8, 14), (1, 15), (2, 7), (3, 6), (4, 5)] [(0, 12), (11, 13), (10, 14), (9, 15), (8, 7), (1, 6), (2, 5), (3, 4)] [(0, 13), (12, 14), (11, 15), (10, 7), (9, 6), (8, 5), (1, 4), (2, 3)] [(0, 14), (13, 15), (12, 7), (11, 6), (10, 5), (9, 4), (8, 3), (1, 2)] [(0, 15), (14, 7), (13, 6), (12, 5), (11, 4), (10, 3), (9, 2), (8, 1)] [(0, 7), (15, 6), (14, 5), (13, 4), (12, 3), (11, 2), (10, 1), (9, 8)] [(0, 6), (7, 5), (15, 4), (14, 3), (13, 2), (12, 1), (11, 8), (10, 9)] [(0, 5), (6, 4), (7, 3), (15, 2), (14, 1), (13, 8), (12, 9), (11, 10)] [(0, 4), (5, 3), (6, 2), (7, 1), (15, 8), (14, 9), (13, 10), (12, 11)] [(0, 3), (4, 2), (5, 1), (6, 8), (7, 9), (15, 10), (14, 11), (13, 12)] [(0, 2), (3, 1), (4, 8), (5, 9), (6, 10), (7, 11), (15, 12), (14, 13)] [(0, 1), (2, 8), (3, 9), (4, 10), (5, 11), (6, 12), (7, 13), (15, 14)] -- http://mail.python.org/mailman/listinfo/python-list
indirectly addressing vars in Python
Forgive my newbieness - I want to refer to some variables and indirectly alter them. Not sure if this is as easy in Python as it is in C. Say I have three vars: oats, corn, barley I add them to a list: myList[{oats}, {peas}, {barley}] Then I want to past that list around and alter one of those values. That is I want to increment the value of corn: myList[1] = myList[1] + 1 Is there some means to do that?. Here's my little session trying to figure this out: oats = 1 peas = 6 myList=[] myList [] myList.append(oats) myList [1] myList.append(peas) myList [1, 6] myList[1]= myList[1]+1 myList [1, 7] peas 6 So I don't seem to change the value of peas as I wished. I'm passing the values of the vars into the list, not the vars themselves, as I would like. Your guidance appreciated... Ross. -- http://mail.python.org/mailman/listinfo/python-list
Managing timing in Python calls
I'm porting some ugly javascript managed stuff to have an equivalent behaviour in a standalone app. It uses events that arrive from a server, and various small images. In this standalone version, the data is local in a file and the images in a local directory. My AJAX code managed a timely presentation of the info, and in the Javascript that relied on the ugly: myImage.onload = function(){dosomething_when_it's_finished} structure. Also, I used the similarly unpretty: var t = window.setTimeout( function () { do_when_timed_out} structures which allows stuff to happen after a perscribed period. In my python implementation my first guess is to use a thread to load my image into a variable myImage = wx.Image(aPic.gif, wx.BITMAP_TYPE_GIF ).ConvertToBitmap() so that it won't block processing. (Though perhaps it'll just happen so fast without a server involved that I won't care.) Is there a nice equivalent of a 'setTimeout' function in python? ie to call a function after some time elapses without blocking my other processing? I suppose just a thread with a time.sleep(x_mS) in it would be my first guess? Can anyone give me some feedback on whether that's a logical path forward, or if there are some nicer constructs into which I might look? Thanks for any suggests... Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: Managing timing in Python calls
bieff...@gmail.com wrote: Python has in its standard library a timer class which actually is implemented as a thread (I think) ... however, when using a GUI package, I think it is better to use gui- specific functions for event-driven programming, to make sure that your code do not mess with GUI event loop and to work around the lack of thread-safety in some GUI libraries. This applies to timer/timeouts but also to execute code when specific I/O events occur ( e.g. the receiving of data from a socket ). Although I'm not an expert of pywx, a quick search pointed me to this page: http://wxpython.org/onlinedocs.php from which it seams that WxTimerEvent couldbe what you need. I agree with you that for loading images from local files a thread should not be needed. P.S : notice that the documentation refers to the C++ library on which the python wrapper is built. This is often the case for python wrapper of GUI libraries. However, the most important ones come with a rich set of demo programs (and pywx demo suite is quite complete) from which one can lear what he needs. Ciao - FB The wxTimerEvent does sound attractive - I'll look into that. Thanks too for the opinion on loading images - gives me some guts to just give it a try without threading it and see how it goes. I appreciate the quick input :) Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: Managing timing in Python calls
Interesting stuff - I hadn't come across the 'with' syntax before, so I've learned something already. I was briefly excited to learn about the callLater command which is just a convenience class for the wxTimer class. It seems to be pretty much a parallel of the var t = window.setTimeout( function () { do_when_timed_out} sort of thing in AJAX. However, as is well grumbled on the 'net, you can't use wxTimer from a non-main thread. So that dropped off my plate. But getting my head around my AJAX problem versus my python implementation, I realized my use of those javascript structures were really just used because javascript doesn't allow any threading at all. With Python, just having my other processing path in a thread is enough, and I can use the brutish time.sleep() function, without worrying about blocking the processing of my mainline (UI) thread. So I'm able to proceed. I do want to know more about the 'with' command tho' so I'll look into that. Thx again. Ross. cmdrrickhun...@yaho.com wrote: I believe WxTimerEvent is handled using the event queue, which isn't going to do what you want. An event which goes through the queue does not get processed until you return to the queue. What you want to do is actually a rather difficult task to do generically. Should the task be interrupted immediately? Or is a tiny latency acceptable? Should the function being terminated get to handle its own termination? Or should the termination be forced on it. What sort of overhead is acceptable for this set_timeout behavior? I would not be surprised if there isn't a built in solution, because its so hard, but rather built in tools which can be used to do it. If your timeouts are on the order of seconds, you might be able to just check time.time() at the begining, and compare it to the current time later in the function. This could be on the main thread or on a worker thread. If you need better handling, you may want to look at how condition variables and such work. Finally, thread has a function to send a Keyboard Interrupt to the main thread. I believe you could do your work on the main thread, and catch the interrupt. Background tasks are not easy to implement in any language (other than perhaps AJAX ;-) ). Remember, Python does not support truly simultaneous threads. It actually does timeslices of about 100 operations. Any solution you choose should work given this information. And as for a nicer construct, I personally just learned of how to handle the with command. I could see something like class Timeout: def __init__(self, t): self.t = t def __enter__(self): self.start = time.time() def __exit__(self, x, y, z): return None def __nonzero__(self): return time.time() - self.start = self.t def doSomethingLong(timeout = True): # true guarentees bailout never occurs while timeout: doAnIteration() with Timeout(3) as t: doSomethingLong(t) and have your Timeout class have a flag which it sets when doSomethingLong needs to bail out, using whatever method is best for your particular application. This is, of course pseudocode - I've not run it through python msyself. Hopefully any errors are obvious enough that you can work around them. -- http://mail.python.org/mailman/listinfo/python-list
Custom C Exception Subclasses
For a project that I am doing, it would be useful to have an exception class that stores some additional data along with the message. However, I want to be able to store a couple pointers to C++ classes, so I can't just use an exception created with PyExc_NewException. If I were to subclass the built-in Exception type, I would need to have access to the PyExc_ExceptionObject, but the headers only give PyExc_Exception, the type object. This seems like a rather straightforward task, but I can't seem to find any documentation for it. Does anyone know how to do this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Custom C Exception Subclasses
On Dec 24, 9:24 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: In fact you can, you could store those pointers as attributes of the exception object, using a PyCObject. Excellent. I was not aware of the PyCObject type. Accessing those attributes isn't as easy as doing exc-field, but I think it's easy enough. Inheriting from some exception type requires you to define the type structure and fill it right, and IMHO is a lot harder. Perhaps there is a misunderstanding here. To subclass a type, you need the type, not an instance of such type. Ah yes, I probably should have been more clear. In the docs about subclassing, they use a PyListObject as the first field of the Shoddy struct so that the fields are filled in correctly. Now, how would I go about adding methods to a custom exception object? -- http://mail.python.org/mailman/listinfo/python-list
get method
I am teaching myself Python by going through Allen Downing's Think Python. I have come across what should be a simple exercise, but I am not getting the correct answer. Here's the exercise: Given: def histogram(s): d = dict() for c in s: if c not in d: d[c] = 1 else: d[c] += 1 return d Dictionaries have a method called get that takes a key and a default value. If the key appears in the dictionary, get returns the corresponding value; otherwise it returns the default value. For example: h = histogram('a') print h {'a': 1} h.get('a', 0) 1 h.get('b', 0) 0 Use get to write histogram more concisely. You should be able to eliminate the if statement. Here's my code: def histogram(s): d = dict() for c in s: d[c]= d.get(c,0) return d This code returns a dictionary of all the letters to any string s I give it but each corresponding value is incorrectly the default of 0. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: get method
On Dec 29, 8:07 pm, Scott David Daniels scott.dani...@acm.org wrote: Ross wrote: ... Use get to write histogram more concisely. You should be able to eliminate the if statement. def histogram(s): d = dict() for c in s: d[c]= d.get(c,0) return d This code returns a dictionary of all the letters to any string s I give it but each corresponding value is incorrectly the default of 0. What am I doing wrong? How is this code supposed to count? --Scott David Daniels scott.dani...@acm.org I realize the code isn't counting, but how am I to do this without using an if statement as the problem instructs? -- http://mail.python.org/mailman/listinfo/python-list
formatted 'time' data in calculations
There seems to be no shortage of information around on how to use the time module, for example to use time.ctime() and push it into strftime and get something nice out the other side, but I haven't found anything helpful in going the other way. That is, given some formatted text describing times - is there something that makes it easy to calculate time differences, or do I have to index my way through the string pulling out characters, converting to integers etc... Data is formatted: t1 = 09:12:10 t2 = 11:22:14 I want to calculate tdiff = t2-t1 Any suggestions? (Thanks for anything you can offer) -Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: formatted 'time' data in calculations
Thanks Chris and Diez for the quick pointers... Very helpful Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: formatted 'time' data in calculations
Scott David Daniels wrote: Ross wrote: There seems to be no shortage of information around on how to use the time module, for example to use time.ctime() and push it into strftime and get something nice out the other side, but I haven't found anything helpful in going the other way. As to a paucity of conversion formatting, there is no magic way to take everyone's way of putting date and time information in text and convert it to unambiguous format, in part because there are too many different and contradictory formats. When I write dates, I know what I intended; when I read dates, I guess what the author intended. Have you read the entire time module document? If so, which functions in that module take strings as arguments? That is, given some formatted text describing times - is there something that makes it easy to calculate time differences, or do I have to index my way through the string pulling out characters, converting to integers etc... Data is formatted: t1 = 09:12:10 t2 = 11:22:14 I want to calculate tdiff = t2-t1 Do you do any work yourself? Show us your attempts. This looks like a trivial exercise. It seems that for less than four times the effort of asking your question you might have found the answer. Perhaps I am being too cranky this morning. --Scott David Daniels scott.dani...@acm.org Jeeze, you're quite an ass aren't you? -- http://mail.python.org/mailman/listinfo/python-list
Re: formatted 'time' data in calculations
Thanks Chris and Diez for the quick pointers... Very helpful Ross. -- http://mail.python.org/mailman/listinfo/python-list
My Python / wxPython app crashing - suggestions?
I have a rather elaborate app on python 2.5.2 on mac osx 10.4.11. The GUI elements are built on wxPython 2.8.10.1. Development has gone pretty well, but I've got an intermittent rather silent crash that happens without spewing any error messages to my console at all. I'm developing in Eclipse with PyDev, and I build with py2app to make an executable app. Whether in Eclipse/PyDev or running standalone, the crash occurs randomly without any messages almost every run, though it takes me 10 -15min of usage before I get the fateful crash. The only data I can get is from the CrashReporter Log directory where a MyApp.crash.log tells me that Thread 4 crashed with: Thread: 4 Exception: EXC_BAD_ACCESS (0x0001) Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x0004 and: Thread 4 crashed with X86 Thread State (32-bit): eax: 0x ebx: 0x9083d561 ecx: 0x0074 edx: 0x92e341ac edi: 0x14442b60 esi: 0x ebp: 0xb0370b58 esp: 0xb0370b58 ss: 0x001f efl: 0x00010286 eip: 0x92e30522 cs: 0x0017 ds: 0x001f es: 0x001f fs: 0x gs: 0x0037 Given the lack of other info, this doesn't tell me much. Any suggestions? One other (perhaps related issue?) very rarely, much less common than the crash is a spurious malloc error from deep in python somewhere. Not sure that my code is responsible. I don't recognize this format of complaint. Python(9544,0xa000d000) malloc: *** error for object 0x1a05c8f0: double free Python(9544,0xa000d000) malloc: *** set a breakpoint in szone_error to debug Can anyone suggest somewhere to start? If I start putting random breakpoints and prints in trying to catch the crash, I could be here for years as I can't yet nail down the conditions that precipitate it. Regards, Ross. -- http://mail.python.org/mailman/listinfo/python-list
unpacking vars from list of tuples
I'm inexperienced with some of the fancy list slicing syntaxes where python shines. If I have a list of tuples: k=[(a, bob, c), (p, joe, d), (x, mary, z)] and I want to pull the middle element out of each tuple to make a new list: myList = [bob, joe, mary] is there some compact way to do that? I can imagine the obvious one of myList = [] for a in k: myList.append(a[1]) But I'm guessing Python has something that will do that in one line... Any suggestion is appreciated... Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: unpacking vars from list of tuples
On Sep 15, 6:00 pm, Andre Engels andreeng...@gmail.com wrote: On Tue, Sep 15, 2009 at 11:51 PM, Ross ros...@gmail.com wrote: I'm inexperienced with some of the fancy list slicing syntaxes where python shines. If I have a list of tuples: k=[(a, bob, c), (p, joe, d), (x, mary, z)] and I want to pull the middle element out of each tuple to make a new list: myList = [bob, joe, mary] is there some compact way to do that? I can imagine the obvious one of myList = [] Thanks both Chris and André. That's quite obvious once it's pointed out for me. Thanks especially for the terminology that will make learning the related concepts a bit easier. Ross for a in k: myList.append(a[1]) But I'm guessing Python has something that will do that in one line... Any suggestion is appreciated... You can use a list comprehension: myList = [a[1] for a in k] -- André Engels, andreeng...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: unpacking vars from list of tuples
Thanks Tim, That's actually the stuff I was trying to remember. my_list = [name for _, name, _ in k] I recalled using some underscores for nice dense unnamed variable unpacking before, but couldn't recall the process. Thanks for that. Ross. On 15-Sep-09, at 6:33 PM, Tim Chase wrote: If I have a list of tuples: k=[(a, bob, c), (p, joe, d), (x, mary, z)] and I want to pull the middle element out of each tuple to make a new list: myList = [bob, joe, mary] is there some compact way to do that? I can imagine the obvious one of myList = [] for a in k: myList.append(a[1]) But I'm guessing Python has something that will do that in one line... To add some readability to the other suggested solutions, I'd use tuple unpacking my_list = [name for status, name, code in k] Not knowing what [0] and [2] are, I randomly designated them as status and code, but you likely have your own meanings. If you don't, you can always just use the _ convention: my_list = [name for _, name, _ in k] # or my_list = [name for (_, name, _) in k] As an aside, my_list is preferred over myList in common Python practice. I don't know if there's a preferred convention for with vs without the parens in such a tuple-unpacking list comprehension. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: unpacking vars from list of tuples
Cool - Now that would be some seriously dense, efficient code! Will have to play with numpy sometime. R. On 17-Sep-09, at 12:25 PM, Chris Colbert wrote: if you have numpy installed: ln[12]: import numpy as np In [13]: k = np.array([('a', 'bob', 'c'), ('p', 'joe', 'd'), ('x', 'mary', 'z')]) In [14]: k Out[14]: array([['a', 'bob', 'c'], ['p', 'joe', 'd'], ['x', 'mary', 'z']], dtype='|S4') In [15]: k[:,1] Out[15]: array(['bob', 'joe', 'mary'], dtype='|S4') -- http://mail.python.org/mailman/listinfo/python-list
Not this one the other one, from a dictionary
Learning my way around list comprehension a bit. I wonder if someone has a better way to solve this issue. I have a two element dictionary, and I know one of the keys but not the other, and I want to look up the other one. So I have this dictionary: aDict = {'a': 'bob', 'b': 'stu'} I know that the dictionary contains two keys/value pairs, but I don't know the values nor that the keys will be 'a' and 'b'. I finally get one of the keys passed to me as variable BigOne. e.g.: BigOne = a The other key, call it littleOne remains unknown. It might be b but could be c, x, etc... I later need to access both values... I have something that works, with list comprehension - but wonder if there's a more brief/elegant way to get there: BigValu = aDict[BigOne] temp = [ thing for thing in aDict if thing != BigOne ] LittleValu = aDict[ temp[0] ] Any thoughts? - Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: Not this one the other one, from a dictionary
Thanks Tim (and Ishwor) for the suggestions, those are structures that somewhat new to me - looks good! I'll play with those.At this rate I may soon almost know what I'm doing. Rgds Ross. On 18-Sep-09, at 1:19 PM, Tim Chase wrote: Learning my way around list comprehension a bit. I wonder if someone has a better way to solve this issue. I have a two element dictionary, and I know one of the keys but not the other, and I want to look up the other one. Several ways occur to me. Of the various solutions I played with, this was my favorite (requires Python2.4+ for generator expressions): d = {'a': 'alice', 'b':'bob'} known = 'a' other_key, other_value = ( (k,v) for k,v in d.iteritems() if k != known ).next() If you just want one or the other, you can simplify that a bit: other_key = (k for k in d.iterkeys() if k != known).next() other_key = (k for k in d if k != known).next() or other_value = (v for k,v in d.iteritems() if k != known).next() If you're using pre-2.4, you might tweak the above to something like other_key, other_value = [ (k,v) for k,v in d.iteritems() if k != known ][0] other_key = [k for k in d if k != known)[0] other_value = [k for k in d.iteritems if k != known][0] Hope this helps, -tkc -- http://mail.python.org/mailman/listinfo/python-list
Plain simple unix timestamp with an HTTP GET
I'd like to just quickly and with a minimum of parsing (ie no screen- scraping) get a unix epoch timestamp (or another format if necessary). I thought with a quick second search on Google I'd find a URL where I could do a simple urllib2 based HTTP GET and have a timestamp returned to me. I don't want to use NTP. I need this because I want to run it on an embedded system where I don't have a local timesource, but do have a network service. I'm very low on memory tho. I can set up my own service on django I suppose, and just render back the timestamp from datetime.time() but SURELY someone else is already doing that? My googling has fallen flat. Any suggestions. Thanks in advance! -Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plain simple unix timestamp with an HTTP GET
No - it's not really a python specific need, it's just what I'm using just now, and can't think of where else to ask. It's also my fav test- bed, as it's so easy. Your curl example is using grep and date which I don't have available. I have no fancy libraries, just core parsing capability. I found that NIST has some capability on various servers. RFC 868 and 867. I can get this curl http://208.66.175.36:13/ 55351 10-06-04 00:24:46 50 0 0 8.3 UTC(NIST) * But I'd have a lot of parsing to pull it together. Apparently RFC868 provides a 32bit unformated binary response, but I can't make much out of it. I think my TCP client library is expecting chars and is screwed by bit-boundary expectations. The number is supposed to be seconds since 1900, which is just as good as seconds since 1970. Still hunting. Tho' maybe getting a bit off topic for a python msg board :) On Jun 3, 8:36 pm, livibetter livibet...@gmail.com wrote: I don't know what tools do you have on embedded system, but I really don't think this has to be using Python. Here is what I would do on a normal desktop using your unique way to set up time: date -s $(curl -s -Ihttp://example.com| grep Date | cut -d \ -f 2-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Plain simple unix timestamp with an HTTP GET
On Jun 3, 11:20 pm, livibetter livibet...@gmail.com wrote: This? hwclock --utc --set --date=$(datestr=$(curlhttp://208.66.175.36:13/ 2/dev/null | cut -d \ -f 2-3) ; echo ${datestr//-//}) Only hwclock, curl, cut, and Bash. PS. I didn't know I can set the time via hwclock, learned from Paul's post, but still didn't try to see if it does work. Thanks for the info. Yes, I like the port 13 stuff from NIST et al which is RFC 867 formatted, but on the hdwe the parsing is more work. Found a bit of port 37 RFC 868 stuff that sounds interesting. I am able to get a long int from it now I think (e.g. 64.236.96.53:37 in Virginia), though it seems to be a bit mangled, and doesn't work out to the number I'd expect for a 1900 epoch. Still, I think it's usable, and is just a single number. I hear NIST is gradually getting away from RFC868 stuff tho' which is too bad. Some of us don't need pS accuracy. +/- 5min is fine. Thx for the input! -- http://mail.python.org/mailman/listinfo/python-list
unicode compare errors
I've a character encoding issue that has stumped me (not that hard to do). I am parsing a small text file with some possibility of various currencies being involved, and want to handle them without messing up. Initially I was simply doing: currs = [u'$', u'£', u'€', u'¥'] aFile = open(thisFile, 'r') for mline in aFile: # mline might be £5.50 if item[0] in currs: item = item[1:] But the problem was: SyntaxError: Non-ASCII character '\xa3' in file The remedy was of course to declare the file encoding for my Python module, at the start of the file I used: # -*- coding: UTF-8 -*- That allowed me to progress. But now when I come to line item that is a non $ currency, I get this error: views.py:3364: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal. …which I think means Python's unable to convert the char's in the file I'm reading from into unicode to compare to the items in the list currs. I think this is saying that u'£' == '£' is false. (I hope those chars show up okay in my post here) Since I can't control the encoding of the input file that users submit, how to I get past this? How do I make such comparisons be True? Thanks in advance for any suggestions Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode compare errors
On Dec 10, 2:51 pm, Ross ros...@gmail.com wrote: Initially I was simply doing: currs = [u'$', u'£', u'€', u'¥'] aFile = open(thisFile, 'r') for mline in aFile: # mline might be £5.50 if item[0] in currs: item = item[1:] Don't you love it when someone solves their own problem? Posting a reply here so that other poor chumps like me can get around this... I found I could import codecs that allow me to read the file with my desired encoding. Huzzah! Instead of opening the file with a standard aFile = open(thisFile, 'r') I instead ensure I've imported the codecs: import codecs ... and then I used a specific encoding on the file read: aFile = codecs.open(thisFile, encoding='utf-8') Then all my compares seem to work fine. If I'm off-base and kludgey here and should be doing something differently please give me a poke. Regards, Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode compare errors
On Dec 10, 4:09 pm, Nobody nob...@nowhere.com wrote: On Fri, 10 Dec 2010 11:51:44 -0800, Ross wrote: Since I can't control the encoding of the input file that users submit, how to I get past this? How do I make such comparisons be True? On Fri, 10 Dec 2010 12:07:19 -0800, Ross wrote: I found I could import codecs that allow me to read the file with my desired encoding. Huzzah! If I'm off-base and kludgey here and should be doing something Er, do you know the file's encoding or don't you? Using: aFile = codecs.open(thisFile, encoding='utf-8') is telling Python that the file /is/ in utf-8. If it isn't in utf-8, you'll get decoding errors. If you are given a file with no known encoding, then you can't reliably determine what /characters/ it contains, and thus can't reliably compare the contents of the file against strings of characters, only against strings of bytes. About the best you can do is to use an autodetection library such as: http://chardet.feedparser.org/ That's right I don't know what encoding the user will have used. The use of autodetection sounds good - I'll look into that. Thx. R. -- http://mail.python.org/mailman/listinfo/python-list
Removing items from a list simultaneously
Is there a quick way to simultaneously pop multiple items from a list? For instance if i had the list a = [1,2,3,4,5,6,7] and I wanted to return every odd index into a new list, my output would be new_list = [2,4,6] or similarly if I wanted to return each index that was one away from the midpoint in a, I would get [3,5]. -- http://mail.python.org/mailman/listinfo/python-list
complementary lists?
If I have a list x = [1,2,3,4,5,6,7,8,9] and another list that is a subset of x: y = [1,4,7] , is there a quick way that I could return the complementary subset to y z=[2,3,5,6,8,9] ? The reason I ask is because I have a generator function that generates a list of tuples and I would like to divide this list into complementary lists. -- http://mail.python.org/mailman/listinfo/python-list
list comprehension question
If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to return a new list of each individual element in these tuples, I can do it with a nested for loop but when I try to do it using the list comprehension b = [j for j in i for i in a], my output is b = [5,5,5,6,6,6] instead of the correct b = [1,2,3,4,5,6]. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
yet another list comprehension question
I'm trying to set up a simple filter using a list comprehension. If I have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)] and I wanted to filter out all tuples containing None, I would like to get the new list b = [(1,2), (3,4),(6,7)]. I tried b = [i for i in a if t for t in i is not None] but I get the error that t is not defined. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: yet another list comprehension question
On May 2, 7:21 pm, Chris Rebert c...@rebertia.com wrote: On Sat, May 2, 2009 at 7:13 PM, Ross ross.j...@gmail.com wrote: I'm trying to set up a simple filter using a list comprehension. If I have a list of tuples, a = [(1,2), (3,4), (5,None), (6,7), (8, None)] and I wanted to filter out all tuples containing None, I would like to get the new list b = [(1,2), (3,4),(6,7)]. b = [tup for tup in a if None not in tup] Cheers, Chris --http://blog.rebertia.com Thanks I feel retarded sometimes. -- http://mail.python.org/mailman/listinfo/python-list
Code works fine except...
For the past couple weeks, I've been working on an algorithm to schedule tennis leagues given court constraints and league considerations (i.e. whether it's a singles or a doubles league). Here were my requirements when I was designing this algorithm: -Each player plays against a unique opponent each week. -Similarly, in a doubles league, each player plays with a unique partner each week. -Each player gets a fair number of bye weeks (i.e. the player with the most bye weeks will have no more than one bye week than the player with the least number of bye weeks) I'm very close to arriving at my desired solution, but I have one glaring flaw. When I have an even number of players sign up for my league and there are court constraints, my current algorithm gives the first player in my league a bye week every single week. I'll post my code below and see how you guys think I should add to/ amend my code. def round_robin(players, rounds): if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): if doubles == True: doubles_week = len(week)/2.0 byes = doubles_week - courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:]) print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] print playing, bye_list -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 3, 10:16 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 3, 11:29 pm, Chris Rebert c...@rebertia.com wrote: Probably not the cause of the problem, but where did the magic numbers 1.072 and 1.08 come from? It is perhaps not the most direct cause of the problem, in the sense that the magic numbers could take various values and the problem would still be there. But the magic numbers appear to be used for spreading out bye selection, and that's broken. The extended slice as written will always pick the first element, since the step is guaranteed to be positive. Since the first player (or None, when there are an odd number of players) stays put in the first position during the round_robin shuffle, that player will always be selected for a bye. Further, as written, the calculated number of byes has no bearing on the actual number of byes selected. I think what I would do is adjust the shuffling algorithm in such a way that everyone moves through the various positions in the list (would it be as simple as adding a shift at the end of round_robin???). Then I could simply select the byes from one end of the list (with a regular slice instead of an extended slice). John The magic numbers that everyone is wondering about are indeed used for spreading out the bye selection and I got them by simply calculating a line of best fit when plotting several courts: byes ratios. The byes = #whatever in my code calculate the number of tuples that need to be placed in the bye_list. At first glance, the suggestion of adding a simple shift at the end of round_robin doesn't seem to work since round_robin already shifts everything except for the first position already. Please correct me if I'm wrong because you might have been suggesting something different. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 4, 7:01 am, Ross ross.j...@gmail.com wrote: On May 3, 10:16 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 3, 11:29 pm, Chris Rebert c...@rebertia.com wrote: Probably not the cause of the problem, but where did the magic numbers 1.072 and 1.08 come from? It is perhaps not the most direct cause of the problem, in the sense that the magic numbers could take various values and the problem would still be there. But the magic numbers appear to be used for spreading out bye selection, and that's broken. The extended slice as written will always pick the first element, since the step is guaranteed to be positive. Since the first player (or None, when there are an odd number of players) stays put in the first position during the round_robin shuffle, that player will always be selected for a bye. Further, as written, the calculated number of byes has no bearing on the actual number of byes selected. I think what I would do is adjust the shuffling algorithm in such a way that everyone moves through the various positions in the list (would it be as simple as adding a shift at the end of round_robin???). Then I could simply select the byes from one end of the list (with a regular slice instead of an extended slice). John The magic numbers that everyone is wondering about are indeed used for spreading out the bye selection and I got them by simply calculating a line of best fit when plotting several courts: byes ratios. The byes = #whatever in my code calculate the number of tuples that need to be placed in the bye_list. At first glance, the suggestion of adding a simple shift at the end of round_robin doesn't seem to work since round_robin already shifts everything except for the first position already. Please correct me if I'm wrong because you might have been suggesting something different. And also, as you all have pointed out, my inclusion of def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): should have been def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds): I forgot to erase that extra parameter when I was playing around with my code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 3, 8:29 pm, John Machin sjmac...@lexicon.net wrote: On May 4, 12:36 pm, Ross ross.j...@gmail.com wrote: For the past couple weeks, I've been working on an algorithm to schedule tennis leagues given court constraints and league considerations (i.e. whether it's a singles or a doubles league). Here were my requirements when I was designing this algorithm: -Each player plays against a unique opponent each week. -Similarly, in a doubles league, each player plays with a unique partner each week. -Each player gets a fair number of bye weeks (i.e. the player with the most bye weeks will have no more than one bye week than the player with the least number of bye weeks) I'm very close to arriving at my desired solution, but I have one glaring flaw. When I have an even number of players sign up for my league and there are court constraints, my current algorithm gives the first player in my league a bye week every single week. I'll post my code below and see how you guys think I should add to/ amend my code. def round_robin(players, rounds): if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] def test_round_robin(players, rounds, courts, doubles = False): players = range(players) DON'T change the type/contents/meaning of a variable name like that. E.g. use nthings for a number of things and things for a collection of things. for week in round_robin(players,rounds,courts): The round_robin() function has only TWO arguments. This code won't even run. When you document neither your data structures nor what your functions are intended to do, the last hope for somebody trying to make sense of your code is to give meaningful names to your variables. week and doubles_week are NOT meaningful. if doubles == True: Bletch. s/ == True// doubles_week = len(week)/2.0 I doubt very much that using floating point is a good idea here. byes = doubles_week - courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] The derivation of the constants 1.072 and 1.08 is what? playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:]) print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] print playing, bye_list For everybody's enlightenment, I have gone through and commented my code so you can better understand what I'm doing. Here it is: def round_robin(players, rounds): # if number of players odd, insert None at first position if len(players)%2: players.insert(0, None) mid = len(players)//2 for i in range(rounds): yield zip(players[:mid], players[mid:]) players = players[0:1] + players[mid:mid+1] + players[1:mid-1] + players[mid+1:] + players[mid-1:mid] rotates players like this: 1 2 - 3 - 4 /| 5 - 6 -7 - 8 def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds): if doubles == True: #for doubles pairings doubles_week = len(week)/2.0 byes = doubles_week - courts #number of tuples to be put into bye_list if byes == 0: bye_list = [] else: following formula equally spaces out tuples selected for bye_list and selects appropriate number according to length of the league bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u not in bye_list] midd = len(playing)//2 doub_sched = zip(playing[:midd], playing[midd:])#matches the remaining tuples into doubles matches print doub_sched, bye_list else: byes = len(week)- courts if byes == 0: bye_list = [] else: bye_list = week[::int(round(1.072*(courts/byes)+1.08))] playing = [u for u in week if u
Re: Code works fine except...
On May 4, 12:15 pm, a...@pythoncraft.com (Aahz) wrote: In article 8d4ec1df-dddb-469a-99a1-695152db7...@n4g2000vba.googlegroups.com, Ross ross.j...@gmail.com wrote: def test_round_robin(players, rounds, courts, doubles = False): players = range(players) for week in round_robin(players,rounds,courts): if doubles == True: doubles_week = len(week)/2.0 byes = doubles_week - courts Side note: thou shalt indent four spaces, no more, no fewer For more info, see PEP 8. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ It is easier to optimize correct code than to correct optimized code. --Bill Harlan Yes... I know this. Unfortunately, copy/pasting my code from the IDE into the google group messes with indentations. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 4, 7:59 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 4, 10:01 am, Ross ross.j...@gmail.com wrote: The magic numbers that everyone is wondering about are indeed used for spreading out the bye selection and I got them by simply calculating a line of best fit when plotting several courts: byes ratios. But that doesn't really help you. When you do seq[::step], step is evaluated once and used for the whole extended slice. So in almost all cases that you are likely to encounter, step is 2, so you'll get seq[0], seq[2], seq[4], etc. Even if step is some other positive number, seq[0] will always be chosen. The byes = #whatever in my code calculate the number of tuples that need to be placed in the bye_list. Fine, but that's not the number of byes that you put into bye_list. At first glance, the suggestion of adding a simple shift at the end of round_robin doesn't seem to work since round_robin already shifts everything except for the first position already. Please correct me if I'm wrong because you might have been suggesting something different. If you read my post carefully, you would see that you HAVE to do something about the first player always being stuck in the first spot. Either move him around, or select your byes differently. That said, I've played around with the shuffling a bit, and it does seem to be pretty tricky to get it to work for the general case where there is no prior knowledge of how many players and courts you will have. I can't shake the feeling that someone good at math will be able to figure out something elegant; but if left to my own devices, I am starting to lean toward just generating all the possible matches and somehow picking from them as needed to fill the courts, trying to keep the number of matches played by each player as close to equal as possible, and trying to keep the waiting times approximately equal as well. John But that doesn't really help you. When you do seq[::step], step is evaluated once and used for the whole extended slice. So in almost all cases that you are likely to encounter, step is 2, so you'll get seq[0], seq[2], seq[4], etc. Even if step is some other positive number, seq[0] will always be chosen. It's not true that in almost all cases the step is 2. How that is evaluated directly depends on the number of available courts. Anyways, you're right that seq[0] is always evaluated. That's why my algorithm works fine when there are odd numbers of players in a league. But if you will notice, my original question was how I could ADD TO or AMMEND my current code to account for even number of players. I have used an algorithm that comes up with all possible pairings and then randomly puts people together each week and places players in a bye list according to how many times they've previously been in the bye list but since I was dealing with random permutations, the algorithm took minutes to evaluate when there were more than 10 players in the league. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 4, 7:33 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 4, 8:56 pm, Ross ross.j...@gmail.com wrote: Anyways, you're right that seq[0] is always evaluated. That's why my algorithm works fine when there are odd numbers of players in a league. It doesn't work fine for all odd numbers of players. For example, 15 players on 3 courts should result in 5 byes. But what actually happens with your code is that you get 4 byes or 8 byes, depending on whether you've got floating-point division enabled. So the way you are selecting byes does not even guarantee that you'll allocate the correct number of active matches for the number of courts, and this is due to the fact that the extended slice is too coarse a tool for the task. Now, it may be that for you, the number of players and courts is always within a confined range such that extended slicing and your magic constants will work. That's fine for you, but we weren't given that information. I haven't even begun to look at what happens for doubles. John You're right... I only tested cases when number of people playing outnumbered the number of byes that week. Anyways, I'm new to programming and this has been a good learning experience. Next time around, I'll be sure to thoroughly comment my code before I ask for help on it. I really appreciate all the help that you've offered so far. Right now, I'm debating whether I should try to reinvent the round_robin generator part of the code or whether there still might be a way to shuffle the results of the generated output so that I can slice it effectively. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 5, 12:32 am, John Yeung gallium.arsen...@gmail.com wrote: On May 5, 1:12 am, John Yeung gallium.arsen...@gmail.com wrote: [...] the problem may require bigger guns (either much better math or much more sophisticated programming). Yes, I'm responding to myself. Well, I went ahead with the approach I mentioned earlier, generating all possible matches and then selecting among them as needed to fill up the courts, trying to keep the number of matches played by each player as fair as possible. (I should mention that this, or something similar, was suggested earlier by someone else in a different thread, in response to the same question by the same OP.) I did use bigger guns (mainly a class for player objects, with custom __cmp__ method), but still didn't do anything with doubles. I haven't tested it much, but I'll post it if anyone's interested. (That way people can pick on me instead of the OP. ;) John I'm interested to see what you did. From your description, it sounds like I've tried what you've done, but when I implemented my version, it took minutes to evaluate for bigger numbers. If that isn't the case with yours, I'd be interested in seeing your implementation. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 5, 1:33 pm, MRAB goo...@mrabarnett.plus.com wrote: Ross wrote: On May 5, 12:32 am, John Yeung gallium.arsen...@gmail.com wrote: On May 5, 1:12 am, John Yeung gallium.arsen...@gmail.com wrote: [...] the problem may require bigger guns (either much better math or much more sophisticated programming). Yes, I'm responding to myself. Well, I went ahead with the approach I mentioned earlier, generating all possible matches and then selecting among them as needed to fill up the courts, trying to keep the number of matches played by each player as fair as possible. (I should mention that this, or something similar, was suggested earlier by someone else in a different thread, in response to the same question by the same OP.) I did use bigger guns (mainly a class for player objects, with custom __cmp__ method), but still didn't do anything with doubles. I haven't tested it much, but I'll post it if anyone's interested. (That way people can pick on me instead of the OP. ;) John I'm interested to see what you did. From your description, it sounds like I've tried what you've done, but when I implemented my version, it took minutes to evaluate for bigger numbers. If that isn't the case with yours, I'd be interested in seeing your implementation. Here's my approach (incomplete): def get_pair(player_list, played): for first in range(len(player_list)): player_1 = player_list[first] for second in range(first + 1, len(player_list)): player_2 = player_list[second] pair = player_1, player_2 sorted_pair = tuple(sorted(pair)) if sorted_pair not in played: played.add(sorted_pair) del player_list[second] del player_list[first] return pair return None def round_robin(player_list, courts, played): playing = [] for c in range(courts): pair = get_pair(player_list, played) if pair is None: break playing.append(pair) byes = player_list[:] player_list[:] = byes + [player for pair in playing for player in pair] yield playing, byes def test_round_robin(players, rounds, courts, doubles=False): player_list = range(players) played = set() for r in range(rounds): for playing, byes in round_robin(player_list, courts, played): print playing, byes- Hide quoted text - - Show quoted text - Looks like somewhat of an improvement, although the bye distribution is still slightly lopsided. For example, in a singles league with 12 players, 12 rounds, and 4 courts, The first player had at least 2 less byes than every other player and 3 less byes than the players with the most number of byes. Thanks for your input though...I'll look into how I can improve upon it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 5, 10:33 am, MRAB goo...@mrabarnett.plus.com wrote: Ross wrote: On May 5, 12:32 am, John Yeung gallium.arsen...@gmail.com wrote: On May 5, 1:12 am, John Yeung gallium.arsen...@gmail.com wrote: [...] the problem may require bigger guns (either much better math or much more sophisticated programming). Yes, I'm responding to myself. Well, I went ahead with the approach I mentioned earlier, generating all possible matches and then selecting among them as needed to fill up the courts, trying to keep the number of matches played by each player as fair as possible. (I should mention that this, or something similar, was suggested earlier by someone else in a different thread, in response to the same question by the same OP.) I did use bigger guns (mainly a class for player objects, with custom __cmp__ method), but still didn't do anything with doubles. I haven't tested it much, but I'll post it if anyone's interested. (That way people can pick on me instead of the OP. ;) John I'm interested to see what you did. From your description, it sounds like I've tried what you've done, but when I implemented my version, it took minutes to evaluate for bigger numbers. If that isn't the case with yours, I'd be interested in seeing your implementation. Here's my approach (incomplete): def get_pair(player_list, played): for first in range(len(player_list)): player_1 = player_list[first] for second in range(first + 1, len(player_list)): player_2 = player_list[second] pair = player_1, player_2 sorted_pair = tuple(sorted(pair)) if sorted_pair not in played: played.add(sorted_pair) del player_list[second] del player_list[first] return pair return None def round_robin(player_list, courts, played): playing = [] for c in range(courts): pair = get_pair(player_list, played) if pair is None: break playing.append(pair) byes = player_list[:] player_list[:] = byes + [player for pair in playing for player in pair] yield playing, byes def test_round_robin(players, rounds, courts, doubles=False): player_list = range(players) played = set() for r in range(rounds): for playing, byes in round_robin(player_list, courts, played): print playing, byes FYI... I was testing your code further and discovered a strange outcome... when there are 16 people for 7 courts, every 7th round your code produces 4 byes instead of the correct 2 byes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 6, 3:14 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 6, 3:29 am, MRAB goo...@mrabarnett.plus.com wrote: I have the feeling that if the number of rounds is restricted then the difference between the minimum and maximum number of byes could be 2 because of the requirement that players shouldn't play each other more than once, meaning that the players have to be shuffled around a bit, so a player might play a week earlier or later than would otherwise be the case. This is the feeling that I am getting also. All my efforts to keep everything as balanced as possible at all times (to be ready for the season to end suddenly at any time) result in messy jams that could otherwise be alleviated if I allowed temporary imbalances, knowing that there are more weeks later to make them up. John If I were to set up a dictionary that counted players used in the bye list and only allowed players to be added to the bye list if they were within 2 of the least used player, would this be a good approach for managing bye selection or would using a dictionary in this manner be unnecessary/redundant? -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 6, 3:14 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 6, 3:29 am, MRAB goo...@mrabarnett.plus.com wrote: I have the feeling that if the number of rounds is restricted then the difference between the minimum and maximum number of byes could be 2 because of the requirement that players shouldn't play each other more than once, meaning that the players have to be shuffled around a bit, so a player might play a week earlier or later than would otherwise be the case. This is the feeling that I am getting also. All my efforts to keep everything as balanced as possible at all times (to be ready for the season to end suddenly at any time) result in messy jams that could otherwise be alleviated if I allowed temporary imbalances, knowing that there are more weeks later to make them up. John If I were to set up a dictionary that counted players used in the bye list and only allowed players to be added to the bye list if they were within 2 of the least used player, would this be a good approach for managing bye selection or would using a dictionary in this manner be unnecessary/redundant? -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 6, 3:14 pm, John Yeung gallium.arsen...@gmail.com wrote: On May 6, 3:29 am, MRAB goo...@mrabarnett.plus.com wrote: I have the feeling that if the number of rounds is restricted then the difference between the minimum and maximum number of byes could be 2 because of the requirement that players shouldn't play each other more than once, meaning that the players have to be shuffled around a bit, so a player might play a week earlier or later than would otherwise be the case. This is the feeling that I am getting also. All my efforts to keep everything as balanced as possible at all times (to be ready for the season to end suddenly at any time) result in messy jams that could otherwise be alleviated if I allowed temporary imbalances, knowing that there are more weeks later to make them up. John If I were to set up a dictionary that counted players used in the bye list and only allowed players to be added to the bye list if they were within 2 of the least used player, would this be a good approach for managing bye selection or would using a dictionary in this manner be unnecessary/redundant? -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
On May 7, 1:11 am, John Yeung gallium.arsen...@gmail.com wrote: On May 7, 12:30 am, Ross ross.j...@gmail.com wrote: If I were to set up a dictionary that counted players used in the bye list and only allowed players to be added to the bye list if they were within 2 of the least used player, would this be a good approach for managing bye selection or would using a dictionary in this manner be unnecessary/redundant? I certainly have not proved it, but I think you don't need to resort to anything fancy if you are OK with the maximum byes being within two of the minimum byes. (Maybe this needs to be larger with larger numbers of players.) Try using your original shuffle but instead of selecting matches to throw away each week, just use the matches you need (to fill up the courts) and pick up where you left off the next week. For example, with 10 players, each round ideally consists of five matches. If you only have four courts, don't throw away the fifth match; save it as the first match next week. To be honest, I didn't look too carefully at your original shuffle. It may be good enough. It's a little different than the standard rotation as presented on Wikipedia: http://en.wikipedia.org/wiki/Round-robin_tournament#Scheduling_algorithm The one on Wikipedia happened to pass my casual tests with no more than a 2-bye difference between the most-played and least-played players, and didn't run into the problem of scheduling the same player for two matches the same week. But I have to stress I only tried a few starting values, which all worked; I didn't try to break it, or run an extensive battery of tests. John John, I really appreciate your help with this problem. Thanks to your suggestions, I've managed to solve the problem. Here's what I did: I used my original round_robin generator to generate each week. I then took every week and chained them all together end to end. Then, depending on how many courts are available, I can select that many tuples at a time from the list. If you go in order, the discrepancy between the player with the least amount of byes and the greatest amount of byes is only 1. If you can make it exactly all the way through a cycle, there will be no discrepancy. Anyways, I've done all this by hand and it works so now I'm going to go ahead and code it up. Again, thanks for your help. -Ross -- http://mail.python.org/mailman/listinfo/python-list
slice iterator?
I have a really long list that I would like segmented into smaller lists. Let's say I had a list a = [1,2,3,4,5,6,7,8,9,10,11,12] and I wanted to split it into groups of 2 or groups of 3 or 4, etc. Is there a way to do this without explicitly defining new lists? If the above problem were to be split into groups of 3, I've tried something like: start = 0 stop = 3 for i in range(len(a)): segment = a[start:stop] print segment start += stop stop += stop Unfortunately start and stop don't increment using this code. Ideally, my outcome would be [1,2,3] [4,5,6] [7,8,9] [10,11,12] -- http://mail.python.org/mailman/listinfo/python-list
[issue2271] msi installs to the incorrect location (C drive)
New submission from Ross [EMAIL PROTECTED]: When installing Python using any of the following stand-alone installers: python-2.5.2.amd64.msi python-2.5.1.amd64.msi python-2.5.2.msi all the files and folders are installed in C:\ instead of C:\Python25\ as specified in the installer. Creating C:\Python25\ before installation, changing the folder name, and rebooting the machine did not solve the problem. The installation is being performed on Windows Vista Enterprise 64 bit with an Intel Q6600 processor machine. -- components: Installation, Windows messages: 63455 nosy: rossmclendon severity: normal status: open title: msi installs to the incorrect location (C drive) type: behavior versions: Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2271 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2271] msi installs to the incorrect location (C drive)
Ross [EMAIL PROTECTED] added the comment: log now attached Added file: http://bugs.python.org/file9655/python.zip __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2271 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2271] msi installs to the incorrect location (C drive)
Ross [EMAIL PROTECTED] added the comment: Checking Progress. This is a big of a show-stopper as it prevents me from using a number of python dependent packages. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2271 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue2271] msi installs to the incorrect location (C drive)
Ross [EMAIL PROTECTED] added the comment: using Orca, I modified the .msi file and python now appears to be working. I made the following change: Property - SecureCustomProperty Changed value from REMOVEOLDSNAPSHOT;REMOVEOLDVERSION to REMOVEOLDSNAPSHOT;REMOVEOLDVERSION;TARGETDIR;DLLDIR Running the modified .msi file resulted in Python being installed in C:\Python25 (the correct location). Currently, the installation appears to work properly. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue2271 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6818] remove/delete method for zipfile/tarfile objects
New submission from Ross rossmclen...@tamu.edu: It would be most helpful if a method could be included in the TarFile class of the tarfile module and the ZipFile class of the zipfile module that would remove a particular file (either given by a name or a TarInfo/ZipInfo object) from the archive. Usage to remove a single file from an archive would be as follows: import zipfile zipFileObject = zipfile.ZipFile(archiveName,'a') zipFileObject.remove(fileToRemove) zipFileObject.close() Such a method should probably only apply to archives that are in append mode as write mode would erase the original archive and read mode should render the archive immutable. One possible extra to be included is to allow a list of file names or ZipInfo/TarInfo objects to be passed into the remove method, such that all items in the list would be removed from the archive. -- components: Library (Lib) messages: 92154 nosy: rossmclendon severity: normal status: open title: remove/delete method for zipfile/tarfile objects type: feature request versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6818 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6818] remove/delete method for zipfile/tarfile objects
Changes by Ross rossmclen...@tamu.edu: -- components: +IO ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6818 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6818] remove/delete method for zipfile/tarfile objects
Ross rossmclen...@tamu.edu added the comment: Slight change to: Such a method should probably only apply to archives that are in append mode as write mode would erase the original archive and read mode should render the archive immutable. The method should probably still apply to an archive in write mode. It is conceivable that one may need to delete a file from the archive after it has been written but before the archive object has been closed. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6818 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6818] remove/delete method for zipfile/tarfile objects
Ross rossmclen...@tamu.edu added the comment: In light of Lars's comment on the matter, perhaps this functionality could be added to zip files only. Surely it can be done, considering that numerous utilities and even Windows Explorer provide such functionality. I must confess that I am unfamiliar with the inner workings of file archives and compression, but seeing as it is implemented in a number of places already, it seems logical that it could be implemented in ZipFile as well. I'll spend some time the next few days educating myself about zip files and how this might be accomplished. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6818 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23144] html.parser.HTMLParser: setting 'convert_charrefs = True' leads to dropped text
New submission from Ross: If convert_charrefs is set to true the final data section is not return by feed(). It is held until the next tag is encountered. --- from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def __init__(self): HTMLParser.__init__(self, convert_charrefs=True) self.fed = [] def handle_starttag(self, tag, attrs): print(Encountered a start tag:, tag) def handle_endtag(self, tag): print(Encountered an end tag :, tag) def handle_data(self, data): print(Encountered some data :, data) parser = MyHTMLParser() parser.feed(foo alink/a bar) print() parser.feed(spam alink/a eggs) --- gives Encountered some data : foo Encountered a start tag: a Encountered some data : link Encountered an end tag : a Encountered some data : barspam Encountered a start tag: a Encountered some data : link Encountered an end tag : a With 'convert_charrefs = False' it works as expected. -- components: Library (Lib) messages: 233291 nosy: xkjq priority: normal severity: normal status: open title: html.parser.HTMLParser: setting 'convert_charrefs = True' leads to dropped text type: behavior versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23144 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23144] html.parser.HTMLParser: setting 'convert_charrefs = True' leads to dropped text
Ross added the comment: That would make sense. Might also be worth mentioning the difference in behaviour with convert_charrefs = True/False as that was what led me to think this was a bug. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23144 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
virtualenv doesn't see my compiled tensorflow
With the prebuilt version of tensorflow, I did: virtualenv --system-site-packages ~/tensorflow and somehow got it working with keras. Now I've compiled tensorflow in another shell/directory, where to start with I did: virtualenv --system-site-packages . and I got it running with keras on my net, with a nice speedup. Then I went back to my previous shell, did a deactivate, then virtualenv --system-site-packages ~/tf_compile/tensorflow to point to the dir that was '.' above, but my prompt path did not pick up '(tensorflow)' as before: % virtualenv --system-site-packages ~/tf_compile/tensorflow New python executable in /Users/priot/tf_compile/tensorflow/bin/python Installing setuptools, pip, wheel...done. priot keras% and I get: % python prog.py ... File "/Users/ppp/anaconda/lib/python2.7/site- packages/keras/backend/tensorflow_backend.py", line 1, in import tensorflow as tf ImportError: No module named tensorflow Seems inconsistent. % virtualenv --version 15.1.0 % python --version Python 2.7.10 :: Anaconda custom (x86_64) OS: OSx Darwin -- https://mail.python.org/mailman/listinfo/python-list
Re: virtualenv doesn't see my compiled tensorflow
Solution: remember to run the 'activate' script: % source ~/tf_compile/tensorflow/bin/activate On Friday, September 1, 2017 at 2:39:33 PM UTC-7, ro...@cgl.ucsf.edu wrote: > With the prebuilt version of tensorflow, I did: > >virtualenv --system-site-packages ~/tensorflow > > and somehow got it working with keras. Now I've compiled tensorflow in > another shell/directory, where to start with I did: > >virtualenv --system-site-packages . > > and I got it running with keras on my net, with a nice speedup. Then I went > back to my previous shell, did a deactivate, then > > virtualenv --system-site-packages ~/tf_compile/tensorflow > > to point to the dir that was '.' above, but my prompt path did not pick up > '(tensorflow)' as before: > > % virtualenv --system-site-packages ~/tf_compile/tensorflow > New python executable in /Users/priot/tf_compile/tensorflow/bin/python > Installing setuptools, pip, wheel...done. > priot keras% > > and I get: > > % python prog.py > ... > File "/Users/ppp/anaconda/lib/python2.7/site- > packages/keras/backend/tensorflow_backend.py", line 1, in > import tensorflow as tf > ImportError: No module named tensorflow > > Seems inconsistent. > > % virtualenv --version > 15.1.0 > > % python --version > Python 2.7.10 :: Anaconda custom (x86_64) > > OS: OSx Darwin -- https://mail.python.org/mailman/listinfo/python-list
parakeet 0.1.0 - web-based reporting for PyKota
Parakeet is a TurboGears (http://www.turbogears.org) application intended to provide a rich web interface for reporting on print quotas managed by PyKota (http://www.pykota.org) and CUPS (http://www.cups.org). The 0.1.0 release is aimed solely at developers already familiar with PyKota, LDAP and TurboGears. It allows end-users to log in and view their current balance, as well as a list of recently printed jobs. Parakeet is licensed under the GPL, and is available for download from http://cheeseshop.python.org/pypi/parakeet Cheers Andrew signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
short python talk available from osbootcamp.org
Hi All, Open Source Bootcamp (osbootcamp) teaches skills with open source. We recently had a python talk which we've recorded and made freely available from the osbootcamp.org videos section. Enjoy! Andrew http://osbootcamp.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
what happens when the file begin read is too big for all lines to be read with readlines()
HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what happens if the number of lines is huge?I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. I am using it like this: slines = infile.readlines() # reads all lines into a list of strings called slines Thanks for anyone who knows the answer to this one. -- http://mail.python.org/mailman/listinfo/python-list
Re: what happens when the file begin read is too big for all lines tobe?read with readlines()
Yes, I have read this part readlines( [sizehint]) Read until EOF using readline() and return a list containing the lines thus read. If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. Objects implementing a file-like interface may choose to ignore sizehint if it cannot be implemented, or cannot be implemented efficiently. Maybe I'm missing the obvious, but it does not seem to say what happens when the input for readlines is too big. Or does it? How does one tell exactly what the limitation is to the size of the returned list of strings? - Original Message - From: Ben Finney [EMAIL PROTECTED] Newsgroups: comp.lang.python To: python-list@python.org Sent: Saturday, November 19, 2005 6:48 AM Subject: Re: what happens when the file begin read is too big for all lines tobe?read with readlines() Ross Reyes [EMAIL PROTECTED] wrote: Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. The Python documentation is online, and it's good to get familiar with it: URL:http://docs.python.org/ It's even possible to tell Google to search only that site with site:docs.python.org as a search term. When I use readlines, what happens if the number of lines is huge? I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. The documentation on methods of the 'file' type describes the 'readlines' method, and addresses this concern. URL:http://docs.python.org/lib/bltin-file-objects.html#l2h-244 -- \ If you're not part of the solution, you're part of the | `\ precipitate. -- Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: question on regular expressions
Darren Dale [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm stuck. I'm trying to make this: file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf,file://C %5Cfolderx%5Cfoldery%5Cmydoc2.pdf (no linebreaks) look like this: ./mydoc1.pdf,./mydoc2.pdf my regular expression abilities are dismal. I won't list all the unsuccessful things I've tried, in a nutshell, the greedy operators are messing me up, truncating the output to ./mydoc2.pdf. Could someone offer a suggestion? Thanks, Darren from os.path import basename import urllib url = 'file://C:%5Cfolder1%5Cfolder2%5Cmydoc1.pdf' print './%s'%basename(urllib.url2pathname(url)) HTH, Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: built-in 'property'
Steven Bethard [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [snip] For this reason, I usually suggest declaring properties like[1]: py class E(object): ... def x(): ... def get(self): ... return float(self._x) ... def set(self, x): ... self._x = x**2 ... return dict(fget=get, fset=set) ... x = property(**x()) ... def __init__(self, x): ... self._x = x ... [snip] [1] Thanks to whoever originally suggested this! Sorry, I've forgotten who... Hello. As Alex mentioned, I'm the author of the tidy property idiom recipe. I stumbled across the idea back in June of 2003, when there were ongoing discussions about property syntax and, in particular, thunks. I've discovered that Greg Ewing had a similar idea 6 months earlier [1], though I wasn't aware of that at the time. I'll note that it is possible to change the built-in property (in a backward compatible manner) to be used as a decorator for this idiom, to redefine parts of properties in sub-classes, and to provide default get/set/del methods. That being said, while I appreciate that there are people who like this recipe (and others who don't), I think it's important to point out that this is *not* the recommended property idiom. Moreover, Guido doesn't like it and he would prefer that it not become the standard [2][3]. Sean [1] http://mail.python.org/pipermail/python-dev/2003-January/032611.html [2] http://mail.python.org/pipermail/python-dev/2003-January/032630.html [3] http://mail.python.org/pipermail/python-dev/2004-January/042206.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting rid of self.
BJörn Lindqvist [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Thank you for your replies. But they don't deal with my original question. :) I have read the thousands of posts all saying self is good and they are right. But this time I want to be different m-kay? I figure that there might be some way to solve my problem by doing this: [snip ...] But beyond that, I have no idea and I would be grateful if someone would like to help me with it. http://starship.python.net/crew/mwh/hacks/selfless.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Wed, 12 Oct 2005 23:27:26 +0100, Roedy Green [EMAIL PROTECTED] wrote: On Sun, 09 Oct 2005 23:04:49 -, [EMAIL PROTECTED] (Gordon Burditt) wrote or quoted : I think one necessary function of email and USENET is that it should allow you to SAFELY communicate with strangers or, worse, people you know but do not trust at all, Yes, but with spam ANY communication with an unwanted stranger is a nuisance. !-- etc -- Roedy, I would just _love_ to see the response from the industry when you tell them they should dump their whole mail infrastructure, and switch over to a whole new system (new protocols, new security holes, new problems start to finish). I gather that's the gist of the suggestion, a new protocol with built in public key (a fine, well known, accepted term, IMHO it doesn't need changing) cryptography and signature support? IMAP is in many ways better than POP3, but you would be surprised at the weight of an accepted standard I think. -- Ross Bamford - [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Thu, 13 Oct 2005 09:04:17 +0100, //[EMAIL PROTECTED] wrote: Roedy Green [EMAIL PROTECTED] writes: Next Mr. Phish had to present his passport etc when he got his Thawte ID. Now Interpol has a much better handle on putting him in jail. He can't repudiate his phishing attempt. Any underage drinker in a college town can tell you a hundred ways to get sufficient fake ID to get around that. See also: http://www.ahbl.org/funny/response1.php I'll let others here fill in the blanks. :) :) :) -- Ross Bamford - [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
How do I pass args using Python Windows
Hi - I wonder if someone might be able to lend a quick answer to this. I have a python script that I normally run from the command line on Solaris. i.e. %pythonscript filein fileout I decided to try IDLE on Windows to do some debugging with the debugger (which I unfortunately dont' have on Solaris 5.7) So my question is: How do I pass the command line args when using the Windows IDLE/Python environment? Thanks for any tips. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question: Explain this behavior
On Thu, 14 Jul 2005 15:46:40 -0700, David Smith wrote: Why does code snippet one work correctly, but not two. The only difference is the placement of the else. I know that indentation affects execution, but how does it change behavior in the following examples? Thank you. 1. for n in range(2, 10): for x in range(2, n): if n % x == 0: print n, 'equals', x, '*', n/x break else: # loop fell through without finding a factor print n, 'is a prime number' snip A quote from Python: Essential Reference (2/e) (p56) says it best: The 'else' clause of a loop executes only if the loop runs to completion. This either occurs immediately (if the loop wouldn't execute at all) or after the last iteration. On the other hand, if the loop is terminated early using the 'break' statement, the 'else' clause is skipped. Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: How to connect to UNIX machine from windows box
I want to connect to unix machine using ssh to run some commands . I have not tried this, but it might be useful. http://www.lag.net/paramiko/ HTH, Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: list insertion
On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush wrote: i am trying to insert into a singly linked list hold = self.next self.next = DaClass(value) self.next.next = hold but i suspect (from print statement insertions) that the result is not as i expect. as the concept and code should be very common, as i am too old for pride, i thought i would ask. mahalo, randy The example above looks like it would work, as long as other stuff you _don't_ show is fine. Specifically, how do you handle the case when the list is empty? Better to show a more complete example with output and how that is not what you expect. Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4.2 using msvcrt71.dll on Win and compatibility issues
Martin v. Löwis wrote: In general, the only Microsoft-supported strategy is that you must use only a single msvcrt in the entire application. So either recompile PostGres, or recompile Python. If you want a compiled version of Python that already uses MSVCRT then you try using pyMingGW: http://jove.prohosting.com/iwave/ipython/pyMinGW.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Replacing curses
Ian Ward wrote: I'll have to deal with that anyway, since I'm doing all my own wrapping, justification and clipping of text. In general it's impossible to know how many display positions some random Unicode character might use. For example, Chinese characters normally take two display positions, but the terminal your using might not support them and display a single width replacement character. Hopefully, you're limitted in the character set you actually need to support and the terminals that your applicaiton will be using. -- http://mail.python.org/mailman/listinfo/python-list
Re: Legality of using Fonts
Steven D'Aprano wrote: It is highly unlikely that any judge will be fooled by a mere change in format (but Your Honour, I converted the TTF file into a bitmap). If that were true, almost the entire X11 bitmap font collection would be illegal. Fonts aren't subject copyright, just the hints in most outline fonts, which are considered computer programs. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Legality of using Fonts
Steven D'Aprano wrote: In any case, even in the USA, hinted fonts are copyrightable, and merely removing the hints (say, by converting to a bitmap) is no more legal than whiting out the author's name from a book and claiming it as your own. That's an absurd comparison. By making a bitmap font from an hinted outline font you're only copying the typeface, you're not copying the hints, the computer program, that's the only part of the font that's subject copyright. If a book consisted of two parts, the first a play by Shakespeare, and the second a commentary of that play, and someone copied only the first part, they'd be doing nothing illegal. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to build python without 'posixmodule' ?
mrstephengross wrote: I'm working on building python 2.4.2 with the mingw compiler (on cygwin). Try following the instructions on the pyMinGW site: http://jove.prohosting.com/iwave/ipython/pyMinGW.html Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Pure python implementation of string-like class
Steve Holden wrote: Wider than UTF-16 doesn't make sense. It makes perfect sense. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Pure python implementation of string-like class
Steve Holden wrote: Wider than UTF-16 doesn't make sense. Ross Ridge wrote It makes perfect sense. Alan Kennedy wrote: UTF-16 is a Unicode Transcription Format, meaning that it is a mechanism for representing all unicode code points, even the ones with ordinals greater than 0x, using series of 16-bit values. It's an encoding format that only supports encoding 1,112,064 different characters making it a little more than 20-bits wide. While this enough to encode all code points currently assigned by Unicode, it's not sufficient to encode the private use area of ISO 10646-1 that Akihiro Kayama wants to use. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Pure python implementation of string-like class
Xavier Morel wrote: Not if you're still within Unicode / Universal Character Set code space. Akihiro Kayama in his original post made it clear that he wanted to use a character set larger than entire Unicode code space. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Re: Pure python implementation of string-like class
Ross Ridge wrote: Akihiro Kayama in his original post made it clear that he wanted to use a character set larger than entire Unicode code space. Xavier Morel wrote: He implies that ... He explictly said that character set he wanted to use wouldn't fit in UTF-16. ... but in later messages he 1. Implies that he wants to use the Unicode private spaces, which are in the Unicode code space He explictly said that he wanted to use the U+6000...U+7FFF range which is outside of the Unicode code space, despite him mistakenly calling them Unicode characters. 2. Says explicitly that his needs concern Kanji encoding... I have no clue whether he really needs such a large character set, but if he does then it makes sense for him to want to use an encoding that's wider than UTF-16. As for the problem he actually posed, I'd suggest using tuples rather than lists, since tuples are immutable like strings. That would make it easier for the class to be used as key in a dictionary. Hmm... thiking about it, it might actually make sense to use strings as the internal representation as a lot operations can be implemented by using the standard string operation but multipling the offsets and lengths by 4. Ross Ridge -- http://mail.python.org/mailman/listinfo/python-list
Python's use in RAD
Hi, I am currenly a second year university student and was wondering if you could help me ut. As part of a project i have decided to write about python, i am not having very much luck with regards to finding infrmation on pythons use in Rapid Application Development, and was wondering of you could highlight some of the features that make it suitable for RAD. Like the use of dinamic binding. Your healp would be appreciated. Hope to hear from you soon. Ross -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Memory Manager
[EMAIL PROTECTED] wrote: 20 MBs = 5 M 32-bit words = 1.25 millis to move half of them on a 2GHz machine. Don't know how much a milli costs where you live. A 2GHz machine doesn't have 20Mb of 2GHz memory. You made the mistake of measuring the speed of processor's cache, rather than the RAM. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: How about adding rational fraction to Python?
D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: I don't think that it is a travesty either. I would also not be so offended if the language treated it that way from the start although I would still have had to get used to it having spent so much time in C and assembler which has natural results. The real problem here is that it is an arbitrary, fundamental change to the way the language works. I would be almost as upset if the change was happening the other way. I feel pretty much the same way. This change in behaviour is likely to be the sole reason keeping me from switching to Python 3 for a long time. If the slash (/) operator had always been defined as floating point division then I would've gotten used to it. Now however, there's no compelling reason for me to try to adjust to this new behaviour. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: How about adding rational fraction to Python?
Paul Rubin http://[EMAIL PROTECTED] wrote: http://en.wikipedia.org/wiki/Natural_number D'Arcy J.M. Cain [EMAIL PROTECTED] writes: Recheck the context. I was talking about the natural result, not natural numbers. Paul Rubin http://[EMAIL PROTECTED] wrote: The natural result of doing arithmetic with natural numbers is more natural numbers. D'Arcy said nothing about natural numbers, and bringing them up adds nothing to this discussion. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: How about adding rational fraction to Python?
Ross Ridge [EMAIL PROTECTED] writes: D'Arcy said nothing about natural numbers, and bringing them up adds nothing to this discussion. Paul Rubin http://[EMAIL PROTECTED] wrote: The numbers D'Arcy is proposing to operate on that way are natural numbers whether he says so or not. No, the discussion has been about the behaviour of the division operator in Python when used with Python's integral and floating-point data types. These data types include many numbers that are not natural numbers. Really, the natural division operation on integers, if there is one, is divmod (which returns a quotient and remainder). Then either your definition of natural is wrong, or the fact that something is the natural way of doing something doesn't mean it should be done that way in Python. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: time.time() strangeness
Nitro [EMAIL PROTECTED] wrote: I can tell you more now. If I pass D3DCREATE_FPU_PRESERVE while creating the DirectX device the bug does not appear. This flag means Direct3D defaults to single-precision round-to-nearest (see [1]) mode. Unfortunately it is not an option to pass this flag, I need the performance boost it gives. Using D3DCREATE_FPU_PRESERVE is extreamly unlikely to affect the performance of your code. Almost all 3D computation these days is done either on the video card or using SSE math on the CPU, neither which is affected by the use of this flag and the state of the FPU's precision setting. If you're mixing Python and Direct3D I would strongly recommend using D3DCREATE_FPU_PRESERVE. It will save you a lot of headaches because time.time() is probably not the only thing that will break. Can somebody tell me how this interacts with python's time.time()? I suppose it's some kind of double vs. float thing or some fpu asm code issue... If you let Direct3D change the FPU settings, then the calculation made to compute the floating-point value returned by time.time() gets rounded to a 32-bit single-precision floating-point value. This means that number returned by time.time() only has 24 bits of precision, which for current time values, only gives you an accuracy of a hundred seconds or so. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: time.time() strangeness
Nitro [EMAIL PROTECTED] wrote: They should really make the fpu preserve flag the default. It just causes very sneaky bugs. They did in Direct3D 10, which doesn't change the flags. It's too late to change the behaviour Direct3D 9 which was created a time where changing FPU precision could have an effect on low end configurations. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list
Re: How about adding rational fraction to Python?
Mark Dickinson [EMAIL PROTECTED] wrote: True division and floor division are different operations. It doesn't seem ridiculous to use different operators for them. I don't have a problem with there being different operators for integer and floating-point division. I have a problem with the behviour of the slash (/) operator changing. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] [EMAIL PROTECTED] -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // -- http://mail.python.org/mailman/listinfo/python-list