- 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
169 Posted Topics
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 … | |
Re: Have you tried .readlines() instead of .read() ? | |
Re: You get back 23 Hooters T-shirts (one for the coach). I put in some beer and onion rings ... | |
Re: Is this a Python question? Or did you accidentally post in the wrong thread? | |
Re: Not to be overly pedantic, but in your example the problem is not in [B]time.sleep()[/B] but rather the [B]while True[/B] that never exits the loop. Your routine [B]checkSomething()[/B] is getting called every 0.1 seconds, but not saying the loop is over. Per demetrio, threading is probably what you need. Or, … | |
Re: Have you tried os.putenv(key, value) ? | |
Re: PMJI, but is the problem one of finding the Taylor series for sin(x+1), instead of using the Taylor series for sin(x)? Ask Wolfram Alpha for [b]taylor series sin (x+1)[/b] and it will tell you roughly: sin(x+1) = sin(1) + x*cos(1) - 1/2 * x^2 * sin(1) - 1/6 * x^3 … | |
Re: [QUOTE=;][/QUOTE] Maybe try something a little simpler. Limit yourself to things inside your house. Make a list of 100 or so items. Then figure out which questions lead to which objects. If every question has a 'y' or 'n' response, what you want is a sequence of y and n … | |
Re: [QUOTE=;][/QUOTE] Surely you mean "Dexter laboratory" is on at 10:30. Convert from HH:MM to pure minutes. Find the first entry which is in the future (which is Cow & Chicken) and select the one before that. Unless it's the first entry (as if you typed in 8:45) in which case … | |
Re: Just a guess; I don't know Turtles, but it seems to me you should move the [ICODE]t=turtle()[/ICODE] line from inside Koch() and do it separately. Otherwise you get a new turtle() instance every time you re-enter Koch(). Replace [CODE=Python]Koch("bob",540)[/CODE] with [CODE=Python]t=turtle() # And remove from inside Koch() t.delay=0.01 # And … | |
Re: Have you looked at popen2? It's documented in the Python run-time library manual and I'm sure google will show lots of examples. | |
Re: I have done this on occasion. The easiest way to do this is have your __init__() routine append [B]self[/B] to a list. If it's not "your" class I suppose you could override the __init__ method of the class. Fortunately I never had to worry about deletes... | |
Re: [I]I checked out matplotlib, which is a bit complicated for me.[/I] Hey, the first time is always complicated but in reality matplotlib is fairly easy to use. The problem is picking [B]what[/B] to use. Herewith an example more or less like the chart you want, in under 50 lines of … | |
Re: While ctypes is a good thing to know, it will not by itself solve all your problems. To call Windows you will need something like the pywin32 package. Are you aware of this? (Your post makes no reference to it). | |
Re: [QUOTE] elif 2 <= self.rank <= 10: self.rank = str(self.rank) self.value = self.rank [/QUOTE] In LINE 20 you set [ICODE]self.rank[/ICODE] to a string, then assigned that same string to [ICODE]self.value[/ICODE]. Hence the error. You really are trying to add a string to an integer. Incidentally, I suggest avoiding the use … | |
Re: Go, Wildcats! When posting code you should wrap it around [B]code=Python[/B] and [B]/code[/B] tags, thusly: [code=Python] from scipy import * from numpy import * def Radiograph_data: try: file('c:/users/ross/desktop/radiograph_data.txt') #checks desktop for file except IOerror, e: e = urlopen('http://www.u.arizona.edu/~erdmann/mse350/radiograph_data.txt') #downloads file from internet data = numpy.loadtxt(e, dtype = float32, comments = … | |
Re: I too suggest the use of % to check for zero remainder, avoiding floating point in this problem. A nit on operators: when you want integer-style division, discarding any remainder, the proper operator is [ICODE]//[/ICODE] not [ICODE]/[/ICODE]. As in: [ICODE]l.append(n//i) [/ICODE]. In this particular case you already know the results … | |
Re: This will get you started, but there are many things you need to consider beyond the core function.[code=Python]def password_input(prompt, pw): while True: # Forever data = raw_input(prompt) if data == pw: return [/code]The key routine raw_input() is no longer recommended, but I've forgotten the replacement riff. | |
Re: I noticed you have defined [ICODE]receive()[/ICODE]twice. This means the first definition is discarded and only the second one counts. Do you need [ICODE]receive()[/ICODE]at all? It depends on what you're doing. Normally you'd do a connect() then exchange many (possibly very many) messages via send() / recv(), then close() when all … | |
Re: [QUOTE=vegaseat;821968][...] but since there is no Python assembler it's just an analytical tool.[/QUOTE] Some people might look at that and think [B]opportunity![/B] Google Summer of Code is coming up. Can daniweb.com be a mentoring organization? | |
Re: [ICODE]return count[/ICODE] is indented too far. |
The End.