- Strength to Increase Rep
- +9
- Strength to Decrease Rep
- -2
- Upvotes Received
- 44
- Posts with Upvotes
- 36
- Upvoting Members
- 22
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
Re: Problem is, there's no way to know "when the internet is disconnected" ahead of time. You might be able to get to 99.99% of all websites but can't get to the one you're trying at the moment. Is "the internet disconnected" in that case? What if it's the other way … | |
Re: You would want something like this: for t in range(120,-1,-1): minutes = t / 60 seconds = t % 60 print "%d:%2d" % (minutes,seconds) # Python v2 only time.sleep(1.0) ... but that just prints out the time left. If you're supposed to put the time in a separate window, well, … | |
Re: I don't see much here on generators. They are a nice feature of Python that everyone should know. Generators are neat ways of doing certain things that involve iterative work. For example, instead of calling a fibonacci function to return fibonacci numbers in a list (say), we create a [I]generator … | |
Re: Good suggestion rr, but I think that just capitalizes the first word of each line. Instead of `readlines()` you want `readwords()`, except that doesn't exist. I think judicious use of `split()` is in order, and remember each line will end with `\n` so you'll want to be sure to delete … | |
Re: You could start with this and maybe clean it up a bit. [code=Python] import struct import sys blocksize = 0x2000 errstart = 0 # File offset of start of error span errend = 0 # File offset just past end of error span diffct = 0 # Difference region count … | |
Re: I use 'T' instead of '10', but you can change this as needed[code=Python]import random rank = random.choice( ('A','2','3','4','5','6','7','8','9','T','J','Q','K') ) suit = random.choice( ('c','d','h','s') ) card = rank + suit print card # or print(card) for Python >= 2.6[/code] | |
Re: I would use numpy and represent the matrix as an ARRAY datatype. Additionally, I'd look around numpy to see if somebody has already solved your problem. If not, please submit your solution when you got it working. | |
Re: You need to add colons in your 'if' statements. 'if difficulty == easy:' etc. | |
Re: Have you got a server listening on port 25? This is not the Windows default configuration. (>netstat -aon). It's easy enuf to write your own mail server that just looks for connects, accepts them, and logs appropriate data. | |
Re: Your example probably doesn't handle the case `L<W`, though that's a simple fix. I don't think I know what a tray is. If you hand me a 6-inch square of cardboard and a pair of scissors, I would cut out a 1-inch by 1-inch square at each of the 4 … | |
Re: Why is line 11 (`for col...`) there? Shouldn't you just iterate over all the rows? Notice you don't use `col` anywhere in the program. I think `caca` ends up being a list of all the cell values in row `i`. In which case, after line 13, you would want something … | |
Re: Also, range(0,255) will only create a 255-entry list. If you want all 256 entries, indexed 0 to 255, use range(256). | |
Re: Can you tell us where the error occurs? Maybe even toss in the whole callback chain? | |
Re: From what I can see, there's no `<td>` in `tag[0]`. Sure you don't want `tag[1]`? | |
Re: An `or` operation is evaluated left-to-right. In this case, if `self.getopt('-v')` returns 1 then the user entered `-v` on the command line, in which case we set self.verbose to `True` and ***go on to the next statement***. If there was no `-v` on the command line, we evaluate the second … | |
Re: > The integral rapidly becomes negligible if x is large so i understand you would simply use the limits of -5 to 5 to calculate this integral. However, i'm still unsure of how to do this. Unless I'm mistaken, I think you can fix this by inserting between line 11 … | |
Re: After a while you get used to using tuples where feasible. For instance, I've just written a program to generate an image with alternating yellow and pink (!) stripes. First lines of code were: yellow = (244, 244, 0, 255) pink = (255, 142, 200, 255) (for R,G,B,Alpha). Why choose … | |
Re: You didn't tell us what was in the DirViento column. I sincerely hope you are not trying to convert a temperature value in degrees to a temperature value in radians... | |
Re: Of course, NumPy (www.numpy.org) has exactly the routine you need. | |
| Re: I've done this sort of stuff before. To answer your second question, here's a code sub-snippet: import copy import Image import numpy as np img = Image.open('E:\\JCH\\Snap.jpg') newx = img.size[0] newy = img.size[1] # Image is (newx,newy) pixels imga = np.asarray(img) # This is the secret; convert img to array … |
Re: > not_lapped= True """used to test if there was no lapping""" I don't see how this can work. You should be writing: not_lapped= True # used to test if there was no lapping > """this was the best i could come out with but didnt solve the problem""" You should … | |
Re: > I have no idea what to do. The underlying calculations are pretty simple but I myself am confused about what the other stuff means. You almost have to RTTM (Read The Teacher's Mind). For example: > ... For your demo, calculate the GPA to 2 decimal places for these … | |
Re: > Now here is a brain teaser, list all the states that joined the Union after 1865 Add the following to the end: print('-'*35) print("US states admitted after 1865:") for state in instance_list: if int(state.date[-4:]) > 1865: print("{:15} {}".format(state.state, state.date[-4:])) Works for me ... | |
Re: I don't know how others are faring here, but every time I try to post something I get an error message complaining my code is improperly formatted. Even if it's all comments! After which I'm often no longer able to type into the editing box. Something is clearly hosed. Is … | |
Re: Well, pickle.dump() should have no problem saving a variable, as in `pickle.dump(variable,f)`. Now if pickle doesn't like that it will raise an exception, but I suspect if you just try it will work fine...based on pickle.dumps() working on a test case I just tried. You will probably find your real … | |
Re: > However, > print float('0x123abc') > does not work Isn't this a bug in Python? | |
Re: I'm a little curious about the control work starting at line 40 above. When you get a pygame.QUIT event, setting done=True doesn't automagically exit the loop...you just fall thru to the next set of code. It doesn't look like you should. Howzabout using **break** instead? Speaking of which, shouldn't the … |