- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 9
- Posts with Upvotes
- 9
- Upvoting Members
- 6
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: Short answer, you don't do this. Usually when you want to get values from a thread you pass it a queue, and have a your main thread get values from the same queue. A couple other things: you're calling join(), which will block until the thread is finished making the … | |
Re: Just to add on, the carriage return character '\r' actually moves the cursor to the start of the current line. So in this case you could just print the number (without a newline), wait a couple seconds, print a carriage return then print the next number. | |
Re: Just on first look your main while loop in the scan function isn't right. Try changing it to: [code=python] for i in range(times): host = list1[0] + "." + list1[1] + "." + list1[2] + "." + list1[3] while threading.activeCount() >= threads: time.sleep(.1) Scanner(str(host), self.port).start() nlist1[3] = ((++nlist1[3]) %256 ) … | |
Re: sum is actually a built-in function so you can easily change it a single line: sum(range(1, n+1, 2)) | |
Re: I don't think you can just dump a python array into the dll's function. Try initializing graydata like this: [code] graydata_type = ctypes.c_ubyte * (w * h) graydata = graydata_type()[/code] | |
Re: A class variable is shared across instances of the class, while an instance variable is unique to that instance of the class. Consider the following example: [CODE]class Foo: name = "FOO" def __init__(self, value): self.value = value mine = Foo("bar") mine_2 = Foo("taz") print mine.value, mine.name print mine_2.value, mine.name Foo.name … | |
Re: [QUOTE=woooee;1140074]Use the "in" keyword. [code]**--- will return a positive for words like "strunk" found = False for word in ["trunk", "branches"] : if word in words[1]: found = True if not found: print "processing this" [/CODE][/QUOTE] Wouldn't it make sense to do this the opposite way? i.e. [code] if words[1] … | |
| Re: The script seems to be doing exactly what you describe it is. What's the problem? |
| |
Re: Here's what I'd do. By converting the sorted list into a dictionary you'll end up with the highest value for each key in the list [code=python] list1 = [('1201', '3'), ('1101', '4'), ('1101', '2'), ('1101', '3'), ('4472', '3'), ('4472', '1'), ('4472', '2'), ('4472', '0'), ('5419', '2')] list2 = [('1101', '3'), … | |
Re: it's failing because you're trying to subtract an int (Bet) from a string (money). You need to convert the string you read in from the money file into an int. You can use the built-in function int(string) to do that. | |
Re: I know there are modules out there for sorted dictionaries, but out of curiosity why do you want to do this? | |
Re: I'd have a separate thread that looks for changes to the file. When it sees a change the thread should send a signal. You can then have your treeview listen for that signal and call a handler to update what's displayed. See [url]http://zetcode.com/tutorials/pygtktutorial/signals/[/url] for more info on creating your own … | |
Re: [QUOTE=woooee;1025555]Always use absolute path+file names.[CODE]filePath = "Dataset/parameter feature vectors" for fname in os.listdir(filePath): complete_name = os.path.join(filePath, fname) data_str = open(complete_name).read() index = data_str.find("female") if index != -1: females.append(index) print fname else: print "append the ones that aren't female to a males"[/CODE][/QUOTE] I don't think this is doing what bol0gna wants … | |
Re: There's a couple problems in your play_choice function it looks like: [code=python]def play_choice(): play_ch = raw_input #You're setting "play_ch" to the actual raw_input function. To get the return value from the function it should be "play_ch = raw_input()" while play_ch != 1 and play_ch != 2 and play_ch != 3: … | |
Re: [QUOTE=masterofpuppets;1022966]hi what version of python are you using, because i noticed your print statement is different. Maybe that's the reason. I tried it on python 2.6 and it seems to work :)[/QUOTE] The reason this is happening is that "input" in python 3 works the same as "raw_input" in python … | |
Re: Here's how I would approach this: (1) for each entry in L2 find all the matching sub-lists from L1. You can use a list comprehension or a for loop for this. (2) Add all the sub-lists that matched into a single list (3) Reduce the list containing all the sub-lists … | |
Re: Not sure why your version is running slowly. Here's a quick and dirty version I just came up with using threads and a queue. It runs very quickly for me (less than a second I'd guess). [CODE=python]import socket import threading import Queue import time class Worker(threading.Thread): def __init__(self, port_queue): threading.Thread.__init__(self) … | |
Re: You can use the builtin function setattr to do this. See [URL="http://docs.python.org/library/functions.html#setattr"]http://docs.python.org/library/functions.html#setattr[/URL]. | |
Re: You can also solve this problem by opening the file as unbuffered: "open('filename', 'w', 0)" | |
Re: If you're getting an IndexError it means the location you're referencing in the list doesn't exist. You assume each line has at least three columns, however I'd bet there's an empty line in there that's screwing you up. It's easy to fix in any case. Just check that the length … | |
Re: I think your problem is that in the call to re.sub you're replacing the match with a raw string. Try removing the 'r' prefacing the replacement string. | |
Re: [QUOTE=shoemoodoshaloo;899945]Ok, here is what I am doing: First my code scans a large data file. In column 10, the genetic data is listed by "name", and there are about 110 different names total. Whenever it gets to a new name, it stores it in a list, so I have something … | |
Re: Basically you just want to put the keys from the dictionary into a list and sort that list. Then if you iterate through the sorted list of keys. Like this: [code=python]my_dict = { 'z': 1, 'a': 2, 'g': 3 } sorted_keys = sorted(my_dict.keys()) for key in sorted_keys: print '%s = … | |
Re: To split up the line from your first post here's what I'd do (this will also strip out the quotes from the beginning and end of each entry): [code=python]data = """'Corn For Grain', 'Irrigated', '1970', 'Colorado', 'Chaffee', '8', '10', '15', '11199199', '1', '', '100 acres', '75 bushel', '7500 bushel', '', … | |
Re: Seems like a good case for a regular expression [code=python]import re test_input = "AND Category 07|Spec 01|ABC 01 AND Category 07|Spec 02|XYZ 02 AND Category 07|Spec 03|PQR 03 " test_output = re.sub('\|[A-Z]{3} [0-9]{2}', '', test_input)[/code] | |
Re: There's always a more clever way :-) [CODE] start = 10 end = 20 open(outfile, 'w').writelines(open(infile).readlines()[start:end]) [/CODE] |