2,190 Posted Topics

Member Avatar for moazmizo

A dictionary may be a better container than a list of lists. If you give each square a unique number, from 1-81, then the neighbors are simple to find. square -1 and +1 for this row square -9 and + 9 for this column (square -9) -1 and + 1; …

Member Avatar for flufflekins
0
113
Member Avatar for nizbit

It is easier to code than to explain. This will only work if you use a fixed width font. A proportional font would require more work. It is a little bit tricky in that you want to print one sub-list based upon the "b" in the previous sub_list. I have …

Member Avatar for nizbit
0
268
Member Avatar for ffs82defxp

Generally, the structure is more like this. [CODE]import time count = 0 PrevTime = time.time() while count < 1000: count +=1 print ("It took ", time.time() - PrevTime) raw_input() [/CODE]Using "==" in a loop is dicey in more complicated loops, as the counter could be incremented more than once. If …

Member Avatar for woooee
0
107
Member Avatar for pizte

I think you could check for a number in the second position, if I understand correctly that overlays use numbers and updates/adds use a letter. [CODE]if len(line.strip()) and \ not line.startswith("Found") and \ not line[1].isdigit():[/CODE]

Member Avatar for pizte
0
149
Member Avatar for KidBuddha

[CODE] base = Rectangle(p1,p2)[/CODE] Can you draw a rectangle with only 2 points? The simple way to do this is to have the house rectangle on the horizontal (set both x values to the same integer), then you just have to set the x from the door click to the …

Member Avatar for woooee
0
113
Member Avatar for v_rod

A Google coughed up pyq, a download for quotes from Yahoo, and there are sure to be others. This question would probably get more answers on a trading forum, as this one is for coding only.

Member Avatar for v_rod
1
117
Member Avatar for jorgejch

You have both class instances and class objects. The variables cartesian = dict() bondList = list() atomName = str() atomicNum = int() would point to the same variable (block of memory) for all instances of the class, where self.atomName = name self.atomicNum = atNum are unique for each instance of …

Member Avatar for woooee
0
589
Member Avatar for Musafir

That's called string formatting [url]http://www.python.org/doc/2.5.2/lib/typesseq-strings.html[/url] (assuming you are using Python 2.5). A simple example: [CODE]year = 1 pop = 12345 for x in range(2): print "Year %d population = %d" % (year, pop) year += 1 pop += 12345 [/CODE]

Member Avatar for woooee
0
115
Member Avatar for Joe Hart

For starters, you can use one function to do the output. Also, store the output strings in a dictionary. You can then use a for loop to go through the if intFCITC_list[0-->10]<0: and send the appropriate string and starting time to the function to print. I only did the first …

Member Avatar for woooee
0
83
Member Avatar for sentinel123

[quote]Why does it fill every spot instead of only one?[/quote]Because every row is the same block of memory = fieldb [code]for i in range(columns): fieldb.append('.') for i in range(rows): fielda.append(fieldb) # # These will all be the same because they all point to the same memory location for row in …

Member Avatar for sentinel123
0
316
Member Avatar for sentinel123

You really should consider using a class for this. Otherwise it gets real convoluted real fast. If you want some assistance, post back.

Member Avatar for sentinel123
0
132
Member Avatar for mahela007

If you wanted to draw a box on the screen and display some sort of message, you would have to access the memory on the video card. Before toolkits like Tkinter that is the way it was done. In simple terms, you would copy that part of the screen, blank …

Member Avatar for mahela007
0
261
Member Avatar for lookatmills

Use the min function to find the smallest number. Is it just me, or is there one person with 100 different ID's who posts every homework problem here, saying they don't have a clue==don't even try. If you are lost then there is very little we can do to help …

Member Avatar for pythopian
0
71
Member Avatar for persianprez

This is a modified version of your program that prints what you expect. I am not sure if it is what you want or not. [CODE]def tryit(start, end): number = start ## number >= start ## number <= end length = 1 print number, '->', ## end+1 because length starts …

Member Avatar for persianprez
0
125
Member Avatar for krishna_sicsr

88282440 PKD0 Test that the first byte is a digit, split on the space if true, and test that the second element starts with a "P", then print everything that starts with a "D" that follows if I follow your description (which was not very clear). You can also store …

Member Avatar for woooee
0
97
Member Avatar for fallopiano

It should be simple with Python's gstreamer interface. [url]http://pygstdocs.berlios.de/[/url]

Member Avatar for Stefano Mtangoo
0
278
Member Avatar for TheManual

It is generally done with a list. [CODE]def test_input(input_str): accept_list = [] for x in range(0, 10): accept_list.append(str(x)) accept_list.append("d") accept_list.append("r") for character in input_str: if character not in accept_list: return False return True # # test it input_string = "a" print input_string, test_input(input_string) input_string = "3A3" print input_string, test_input(input_string) input_string …

Member Avatar for vegaseat
0
124
Member Avatar for pyprog

First you are not returning a dictionary. I've added a print statement to show that. Also, take a look at "returns" and "arguments" here [url]http://www.penzilla.net/tutorials/python/functions/[/url] for the "something" function. [code]def junk(f): d1 = {} d2 = {} for line in f: columns = line.split(":") letters = columns[1] numbers = columns[2] …

Member Avatar for vegaseat
0
327
Member Avatar for gangster88

[QUOTE]The get an error when i try to execute this?[/QUOTE] Not enough info for anyone to help (could be an indentation error, or could be in the calcs). First add some print statements for the individual calcs to isolate the error, and post the specific error message. [CODE]def distance_between_points(p1, p2): …

Member Avatar for gangster88
0
177
Member Avatar for herebutfortea

That is usually a directory problem, i.e. it can't find something because it is not in the current directory. For this line, give it the absolute path name tune = mp.newMedia("/complete/path/Therock.wav") If that doesn't work, check that something is printed so you know the program was started. Finally, if you …

Member Avatar for woooee
0
140
Member Avatar for Kruptein

Do you have to use something like queue_draw() to update the widget? The pygtk.org site has been down for 2 days now, so can't look it up, but try it and see. [QUOTE]Do You mean I have to give whole my code and/or a screenshot of my wxglade window? [/QUOTE]Just …

Member Avatar for Kruptein
-1
167
Member Avatar for parsifal67

FWIW this will find all occurrences of a word in a string. Also note that if you are looking for "the" it will give a hit for "then". If you only want the word, you have to search with spaces added, " the " -assuming string.lower() and that punctuation is …

Member Avatar for mitsuevo
0
257
Member Avatar for ChaseRLewis

Wouldn't this lead to an infinite loop. [CODE]def Prime(x,y): n=2 if x == 1: Prime(x+1,y) elif x == 2: print (2) Prime(x+1,y) elif x <= 0: print ("Number must be a positive integer" else: while n < n+1: ## <=====[/CODE]

Member Avatar for vegaseat
0
220
Member Avatar for P00dle

[QUOTE]Also, is there anyway in Python that you can test whether or not a line of data is binary?[/QUOTE]All data is binary. That's the way the computer does it. I am assuming that you mean bytes that are not text. If you look at an ASCII table like this one …

Member Avatar for P00dle
0
163
Member Avatar for PixelHead777

[CODE]finderGuess = finderGuess - ((((finderGuess*((1+finderGuess)^numberMonths))/(((1+finderGuess)^numberMonths)-1))- (monthlyPayment/loanAmount))/(((((1+finderGuess)^numberMonths)-1) (finderguess*(numberMonths*((1+finderGuess)^(numberMonths-1)))+ (1+finderGuess)^((finderGuess*(1+finderGuess)^numberMonths)* (numberMonths*((1+finderGuess)^(numberMonths-1)))))/ ((((1+finderGuess)^numberMonths)-1)^2)))) [/CODE]I hope you are the only one who has to deal with this code. It may help to remember that the compiler can only do one thing at a time, unless you have a multi-core machine and an OS that …

Member Avatar for woooee
0
229
Member Avatar for i are smart

[QUOTE]I thought this path was suppose to be set by default. it's not so i'm trying to set it.[/QUOTE]You can modify it on startup by adding PYTHONPATH to your ~/.bash.rc file, or create one if you don't have it. export PYTHONPATH=$PYTHONPATH:/path/to/add:/second/path

Member Avatar for vegaseat
0
688
Member Avatar for logon84

[QUOTE]i am a beginner. i have no idea how i can make Tic Tac Toe game. please help me.[/QUOTE] Take on something that is easier first. If you have no idea at all on how to start, then there is little that anyone can do.

Member Avatar for manathisbest
-2
172
Member Avatar for SMIFMD

Some corrections to get you started, provided the indentation is correct.[CODE]def encrypted_message(): ## "message" has not been defined in this function char = message encrypted_message = "" ## encrypted_message = "" from the previous statement for char in encrypted_message: x = ord(char) if char.isalpha(): ## "key" has not been declared …

Member Avatar for masterofpuppets
0
197
Member Avatar for python123
Member Avatar for vnproduktionz

Start with something like this (Not Tested).[CODE]energyFile = open("EnergySources.csv","r") state_dict = {} for line in energyFile: line = line.strip() fields = line.split(",") state = fields[0].strip() if state == "State": ## you didn't give us any idea where state name comes from state_name = fields[???] state_dict[state_name] = fields[1:] elif not len(state): …

Member Avatar for woooee
0
106
Member Avatar for Ri0o

You want to use "readlines()",as readline reads one line at a time, where readlines() reads all data. Also, a print statement is added for clarity.[CODE]records = open(grades.txt,'r').readlines() table = [] newtable = [] for line in records: line = line[:-1] r = string.split(line,':') ## table.append(r) ## for x in table: …

Member Avatar for Ri0o
-1
124
Member Avatar for sneekula

This question is better asked/searched on Ubuntu's forums. The answer is something in the neighborhood of copying the 3.0 install and changing to 3.1, to or use apt-get's install from source-I haven't done it but this might help [url]https://lists.ubuntu.com/archives/ubuntu-users/2005-July/042275.html[/url] [url]http://www.debian.org/doc/manuals/apt-howto/ch-sourcehandling.en.html[/url] If you do install from source, (not the same as …

Member Avatar for pdxwebdev
0
1K
Member Avatar for kenmeck03
Member Avatar for vegaseat
0
114
Member Avatar for henks83

[QUOTE]This week's lab is to design a hangman game. Your program should be able to open a text file which contains a list of words (one word on each line of the text file) and read the words into a list to contain all of the possible words.[/QUOTE]If you don't …

Member Avatar for masterofpuppets
0
957
Member Avatar for rackster992

Google came up with this site which has a link to download source code. I hope you didn't pay $99.95 for the book! [url]http://www.jbpub.com/catalog/9780763746025/[/url]

Member Avatar for dcghelp
0
1K
Member Avatar for rush_ik52

First, you have to decide which GUI toolkit you want to use. Here's an example Google found using Tkinter [url]http://code.activestate.com/recipes/124894/[/url]

Member Avatar for snippsat
0
824
Member Avatar for dinilkarun

You can pipe top to a file on Linux and then read the file. Apparently you can use WMI for MS WIndows but I have not used it [url]http://timgolden.me.uk/python/wmi_cookbook.html#running_processes[/url]

Member Avatar for dinilkarun
0
145
Member Avatar for bol0gna

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]

Member Avatar for vegaseat
0
198
Member Avatar for lrh9

When validating, you want to include, not exclude. So you want a list of data that is acceptable, and the input has to be in the list. That way, when another unit or type of data is introduced it is automatically an error. If your program excludes, then the new …

Member Avatar for paddy3118
0
362
Member Avatar for A_Dubbs

Since you are testing 6 letters total, you want to use "len(w)-5" so you won't run out of letters. To set up an example using "aabbcc" as the simplest example, you only want the for loop to test the first letter. It will test a->a, b->b, and c->c. If you …

Member Avatar for woooee
0
138
Member Avatar for saikeraku

You want to use a class structure for this, so each player can be an instance of the same class, and divide the code into several small functions. [QUOTE]Also, I don't know why but I can't input more than 3 armies for the attacking army, and more than 2 for …

Member Avatar for woooee
0
93
Member Avatar for tlj333

[QUOTE]I still don't understand why not 1 and not 2 and not 3 is the proper way to do this[/QUOTE]Alternatives would be: [CODE]while (play_choice < 1) or (play_choice > 3): while play_choice not in [1, 2, 3]: # Also, you can use .lower instead of 2 compares while play_again.lower() == …

Member Avatar for tlj333
0
194
Member Avatar for nicsmr

You can set the encoding for the file fp = codecs.open('test', encoding='utf-8', mode='w') Or you can change the default encoding for the system sys.setdefaultencoding('utf-8') You may have to use encode/decode, see here [url]http://farmdev.com/talks/unicode/[/url]

Member Avatar for vegaseat
0
129
Member Avatar for jmark13

Using for() loops is easier. This is somewhat of a brute force method but works fine for smaller lists. [CODE]L1=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] L2=[1,2,3,4,11] L3=[] for number in L2: for a_list in L1: if (number in a_list) and (a_list not in L3): L3.append(a_list) print L3 ## ## You can also delete from the …

Member Avatar for lukerobi
0
193
Member Avatar for pygirl

[QUOTE]Does anyone know how to change border colour of a widget [/QUOTE]Border colors, AFAIK, are the same as the widget color, so you would have to use an outside, empty widget of one color, and an inside widget of another color, although that is not quite what you want. The …

Member Avatar for pygirl
0
1K
Member Avatar for nerdagent

This will get you started, but a dictionary would work much better for this. [CODE]elif stChoice == 2: for stock_list in portfolio: print "symbol = %s for %s" % (stock_list[1], stock_list[0]) rmv = raw_input("Type in the ticker name for the stock you wish to remove. ") for stock_list in portfolio: …

Member Avatar for vegaseat
0
127
Member Avatar for dmcadidas15

[QUOTE]return an error message if the values entered aren't either the strings 'on' or 'off'[/QUOTE]Can you use a list instead of all of those variables? Otherwise, try the code below which tests each button individually instead of the confusing and, and, or, etc. in your code. Speaking of testing each …

Member Avatar for woooee
0
101
Member Avatar for chico2009

[QUOTE]Is there some way I can display the 'escape characters'[/QUOTE] Escape characters are generally < decimal 32 and > decimal 127 (in English), but you may have to adjust for your character set. This works for me.[CODE]# -*- coding: utf-8 -*- test_file = [ "about, approximately περίπου cinema σινεμά (το)", …

Member Avatar for chico2009
0
144
Member Avatar for mohfawzy

This is a forum for the Python programming language. Your question should be asked at the swarmplayer site, or on a board for the distro that you are using.

Member Avatar for woooee
0
36
Member Avatar for Megabyte89

[QUOTE]self.database.execute('INSERT INTO contacts (fname) VALUES (null,?),' [fname]) AttributeError: 'contact' object has no attribute 'database'[/QUOTE]It means that you have not declared "self.database" anywhere in your program, and the interpreter does not know if it is a variable, file pointer, another class, etc.

Member Avatar for Stefano Mtangoo
0
484

The End.