Posts
 
Reputation
Joined
Last Seen
Ranked #761
Strength to Increase Rep
+5
Strength to Decrease Rep
-1
100% Quality Score
Upvotes Received
9
Posts with Upvotes
9
Upvoting Members
6
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
4 Commented Posts
0 Endorsements
Ranked #864
~50.2K People Reached
Favorite Forums
Favorite Tags
Member Avatar for Robbert

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 …

Member Avatar for sekmani
2
29K
Member Avatar for mahela007

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.

Member Avatar for Lucaci Andrew
0
11K
Member Avatar for Roiti

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 ) …

Member Avatar for The_Kernel
0
244
Member Avatar for kjock002

sum is actually a built-in function so you can easily change it a single line: sum(range(1, n+1, 2))

Member Avatar for The_Kernel
0
3K
Member Avatar for Tech B

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]

Member Avatar for Tech B
0
456
Member Avatar for eva yang

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 …

Member Avatar for eva yang
0
140
Member Avatar for doctorjo5

[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] …

Member Avatar for woooee
0
174
Member Avatar for herrschteiner
Member Avatar for tziny
Member Avatar for sammakko

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'), …

Member Avatar for sammakko
0
86
Member Avatar for Hawkeye Python

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.

Member Avatar for The_Kernel
0
172
Member Avatar for msaenz

I know there are modules out there for sorted dictionaries, but out of curiosity why do you want to do this?

Member Avatar for vegaseat
0
164
Member Avatar for baskar007

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 …

Member Avatar for The_Kernel
0
723
Member Avatar for bol0gna

[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 …

Member Avatar for vegaseat
0
196
Member Avatar for tlj333

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: …

Member Avatar for tlj333
0
191
Member Avatar for simpatar

[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 …

Member Avatar for The_Kernel
0
164
Member Avatar for jmark13

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 …

Member Avatar for lukerobi
0
192
Member Avatar for willygstyle

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) …

Member Avatar for willygstyle
0
151
Member Avatar for mahela007

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].

Member Avatar for The_Kernel
0
256
Member Avatar for SoulMazer

You can also solve this problem by opening the file as unbuffered: "open('filename', 'w', 0)"

Member Avatar for SoulMazer
0
1K
Member Avatar for joe82

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 …

Member Avatar for joe82
0
127
Member Avatar for johndoe444

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.

Member Avatar for The_Kernel
0
165
Member Avatar for hughesadam_87

[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 …

Member Avatar for jlm699
0
1K
Member Avatar for akindo

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 = …

Member Avatar for akindo
0
136
Member Avatar for brashli

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', '', …

Member Avatar for The_Kernel
0
140
Member Avatar for dinilkarun

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]

Member Avatar for dinilkarun
0
148
Member Avatar for hughesadam_87

There's always a more clever way :-) [CODE] start = 10 end = 20 open(outfile, 'w').writelines(open(infile).readlines()[start:end]) [/CODE]

Member Avatar for The_Kernel
0
137