2,190 Posted Topics

Member Avatar for adil.mahmud.choudhury

What exactly are you trying to do? It is not obvious from the program. There are other problems in addition to indentation: while 1>0: The above is an infinite loop that you never exit. You open the file '/var/log/kern.log' at least 3 times without previously closing it. You mix pack() …

Member Avatar for woooee
0
180
Member Avatar for PeteB247

Start with a tutorial on MySQL for Python, as your code does not contain enough to comment on. For starters, you don't ever call the function connect_to_database, and the function itself does not connect to any database. Start with opening a database correctly and inserting records, which is in every …

Member Avatar for woooee
0
2K
Member Avatar for kRaeTwin

> I keep getting the error: "TypeError: expected a character buffer object" We can't help without the complete error message; which tells where the error is in the program among other things. a[i].lower() Take a look at this page http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/strings3.html beginning at the paragraph that starts with "Strings are immutable, …

Member Avatar for woooee
0
1K
Member Avatar for Alkajak

It appears that the classes are part of the cause of your confusion, so since you do not use them, I have just deleted them and the code runs until it encounters the next error. Note that you will have a problem if you try to split anything after line …

Member Avatar for woooee
0
1K
Member Avatar for anishxx323

And generally, the input is separate from the rest of the program. def get_input(): option = 99 while option not in [0, 1, 2, 3, 4]: print("0 - clear out scores") print("1 - input more scores") print("2 - display all scores") print("3 - get average scores") print("4 - end program") …

Member Avatar for TrustyTony
0
273
Member Avatar for shawn.conway.77

Possibly I to L = 3 letters, L to P = 4 letters 5 to 9 = 4, 9 to 14 = 5 so I 9 P 20 =6+14 5 L 14 U =P+5 letters

Member Avatar for logo32design
0
371
Member Avatar for lancelot626

> It gives me that error am I doing something wrong We don't know what the error is so there is no way to answer other than to ask what happens if nothing is found in the data base. Try printing the look up before adding to the combobox.

Member Avatar for lancelot626
0
299
Member Avatar for pynehalem

Use "SELECT" and "WHERE" to only return record(s) that match from the SQLite database [See "Named Placeholders"](http://zetcode.com/db/sqlitepythontutorial/)

Member Avatar for woooee
0
325
Member Avatar for ddree

Start by getting the input from the user, i.e. Name, number of hours, etc. and then work out the math on paper and convert to Python. Post back with problems.

Member Avatar for woooee
0
1K
Member Avatar for hotblink

FWIW, you can also use divmod instead of two statements (divide and mod), but I doubt that this code would be accepted from a beginning student, and only prints the plural form of the words. x = input('Enter the before-tax price (in cents): ') y = input('Enter your painment (in …

Member Avatar for Xantipius
0
442
Member Avatar for kabir383

> So this is a case of "two wrongs make you write"? Ba dum bum... I will have to use that somewhere myself.

Member Avatar for woooee
0
178
Member Avatar for bryceburry

To end the game if there is a tie, set the last "while True" to some varialble instead that goes to False when there are no more empty spaces, like empty_space=True while empty space: input = raw_input("Select a spot: ") input = int(input) ## rest of code empty_space=test_for_empty(board) To get …

Member Avatar for TrustyTony
0
445
Member Avatar for rbsmith333

Your list contains "option 1", etc, not "1". options = [ 'option 1', 'option 2', 'option 3' ] while True: playerOpt = int(input('input ')) list_test = "option %d" % (playerOpt) if list_test in options: break ## exit while() print("\n Not a valid entry\n")

Member Avatar for rbsmith333
0
195
Member Avatar for lewashby

> the checking starts with 0 (list indeces start with 0) Lists don't have indexes, lists use offsets. So "some_list[5]" means offset 5 from the beginning, or skip over the first 5 elements=beginning of the sixth. It comes from the beginning days of computers when programmers had to do everything …

Member Avatar for ~s.o.s~
0
146
Member Avatar for deepthought

Try splitting the original on the newline and working with the resulting list. split_str=orig_string.split("\n")

Member Avatar for deepthought
0
404
Member Avatar for cjquines

You should also get errors for n = raw.input("Terms? ") and for b = m * m + m first_term = ( ( n * n + n ) / 2 ) - 1 and the same as the above comment if m != 0: will always be true the …

Member Avatar for want_learn
0
108
Member Avatar for vegaseat

Just to see what it would take, modifying Ene's code to draw a right angle triangle of unknown dimensions is just a little more tedious import turtle as tu import random tu.title('draw a right angle triangle') # set at 50% of original size tu.setup(width=0.5, height=0.5) tu.up() tu.goto(60, 100) tu.down() # …

Member Avatar for woooee
0
2K
Member Avatar for maiden128

There are many examples on the web so no reason to duplicate answers here. Start with this link: http://www.daniweb.com/software-development/python/code/216557/turtle-graphics-python

Member Avatar for woooee
0
228
Member Avatar for pxalpine

> But this doesn't do exactly what I want... anyone help? How are we supposed to know what this means? In general, you want to compare words to words. Your code will also find sub-words, ie. "the" is in "then" and "and" is in "random", so use == instead for …

Member Avatar for woooee
0
196
Member Avatar for dan.nitschke

It depends on what is in "letters". If your OS is set to ASCII then the latin1 characters will not be found.

Member Avatar for vegaseat
0
5K
Member Avatar for hughesadam_87

You would use len() print sline[5], type(sline[5]), bool(len(sline[5])) or eval(), although eval will do anything, so if someone puts "rm *" in the file that is being read, eval will delete the files. for lit in ["False", "True"]: x = eval(lit) print x, type(x)

Member Avatar for woooee
0
928
Member Avatar for padton

> I can't seem to find a solution for writing the data into a .csv format where all keys and values are separated by a delimiter, e.g. 11,2.5,2.7,32.6 ? Perhaps it would be a better idea to write it out into a formatted .txt file instead? Using a txt file …

Member Avatar for woooee
0
165
Member Avatar for python1956

Note that the list you posted is not a list of tuples. You can use the older method to do this, although it is slower. def return_lower(x, y): return cmp(x[0][1:], y[0][1:]) test_list=[('a070918_215953.SFTC', '1369.000'), ('a070917_220602.SFTC', '1369.000'), ('a070915_221210.SFTC', '1369.000'), ('r080323_044006.SFTC', '1369.000')] print sorted(test_list, cmp=return_lower)

Member Avatar for Lardmeister
0
4K
Member Avatar for ProNewb

Simple debugging will point out the error. Try running the code with these additional print statements. def occurrence(e, input_list): for item in input_list: print "checking" item, e ## test for checking every item s = 0 if item == e: print " found, s =", s ## this will clarify …

Member Avatar for ProNewb
0
177
Member Avatar for lukerobi

> I ran into some trouble today while trying to launch idle from it from tkinter import * For starters, you should not run apps that use Tkinter from Idle since Idle is written in Tkinter. The results are unpredictable, so try again without using Idle and post back if …

Member Avatar for lukerobi
0
415
Member Avatar for GrimJack

Giving my niece and nephews the old "we had it tough back in my day" routine, I told them that it was so tough that if we wanted to change the TV channel we had to get up off the couch, walk across the room, and turn the knob. They …

Member Avatar for vinnitro
1
3K
Member Avatar for python |

Generally you pass as arguments like this simplified code:[CODE]## program run.py def print_args(name, passwd): print name print passwd ## calling program import run input_name = raw_input("Enter name ") input_passwd = raw_input("Enter password ") run.print_args(input_name, input_passwd) [/CODE]

Member Avatar for Pervex
0
5K
Member Avatar for rev_ollie

Use os.path.isdir() and os.path.islink() to identify which is which and then compare. As far as splitting goes, I would use something along these lines import os test_path="C:/Pyth/Shortcuts/1000.lnk" first, second = os.path.split(test_path) print first, second print second.split(".")

Member Avatar for woooee
0
229
Member Avatar for Twist43

You would bind <Button-3> to the item [Click Here](http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm). For whitespace, you would have to test event.x and event.y to see if you are over white space or not. This uses a left click to determine the location (event.x, event.y) to draw the snowman, but the principle is the same. …

Member Avatar for Twist43
1
4K
Member Avatar for dwhite12

Test for length after you strip the line, and note that "new" is already used by Python. for line in keep: if len(line.strip()): new_fp.write(line)

Member Avatar for dwhite12
0
215
Member Avatar for alex.ashton.58

Generally you pass the value to the function as you want the code "encapslated", i.e. the class does everything. class Foot: def __init__(self,mov,posx,posy,targx,targy): # self.mov is soldier's movement speed, currently not implemented self.mov = mov # self.x and self.y are soldier's position self.x = posx self.y = posy # self.targx …

Member Avatar for alex.ashton.58
0
199
Member Avatar for debbie.chen.946

What does happen? You don't know, so add a print statement to see what is happening def main(): List=[] infile = open ("words_dos.txt","r") words = infile.read() wordList=List.append(words) print "wordList =", wordList Note the difference between read() and readlines() [Click Here](http://docs.python.org/tutorial/inputoutput.html) Also, take a look at the "functions" heading [Click Here](http://hetland.org/writing/instant-python.html) …

Member Avatar for woooee
0
237
Member Avatar for MacUsers

ln has a -f (force option). See man ln. Also, try this instead as it may not be a symlink [CODE]if not os.path.exists(path):[/CODE]

Member Avatar for trsarg
0
3K
Member Avatar for smile1

You have two instances of Tk running which is never a good idea. Use a Toplevel instead. The following is a very simple example. But it will not solve the problems. The problem is that you have somewhere around 100+ lines of code that have not been tested so you …

Member Avatar for woooee
0
2K
Member Avatar for jancho1911

I would use a dictionary with the category as key, and a list of all words in the subset as the value [QUOTE=jancho1911;717752]Let V be the vocabulary of all words in the documents in D For each category ci ----->ci=dictionary key Let Di be the subset of documents in D …

Member Avatar for callmerudy
0
215
Member Avatar for G_S

If you have a <b> then you should also have a </b>, etc. Doing this yourself usually involves a split() and iterating over each item, and a good habit to form is to try to iterate over the text as few times as possible, which means looking for each tag …

Member Avatar for G_S
0
8K
Member Avatar for HankReardon

UpperCaseSentence = (myList[myString]) UpperCaseSentence is a tuple that only contains the final item in the list "myList", as you have written it, which is an empty string if the text that is entered ends with a period. mySentenceList = mySentence.split('.') Add some print statements and see for yourself. Also, as …

Member Avatar for HankReardon
0
3K
Member Avatar for memomk

There is no way to tell without a complete error message which the contains the errant line. Also, do you instantiate the class and then call the setupUI function with a parameter? As the code stands now, nothing will happen even if the code does not contain errors.

Member Avatar for memomk
0
2K
Member Avatar for aot

The datetime module will do micro-seconds [code]import datetime print datetime.datetime.now() time_now = datetime.datetime.now() print time_now[/code]

Member Avatar for BBTK
0
9K
Member Avatar for drichird

You should test for whatever in the program, and if true then call the function or class in the imported module. As stated previously, this is a design problem not a programming problem. A simple example from you would help.

Member Avatar for drichird
0
8K
Member Avatar for kalookakoo

You read the file into a list but write the file as one string. Instead write one tuple per record. And delete loadTextString() as that is just confusing things. [code] save_text(listOfOldScores, "high scores.txt") # def save_text(scores_list, file_name): file_handler = open(file_name, "w") for tup in scores_list: file_handler.write("%s, %d\n" % (tup[0], tup[1])) …

Member Avatar for jemnbuckeye
0
4K
Member Avatar for fishsticks1907

You have the range endings reversed and you want to start at +1 on the inner loop. ~~~ for x in range(0, len(a)-1): for j in range(x+1, len(a)): ~~~ Also you swap every time there is a difference instead of once per loop. ~~~ import random a=[random.randint(1, 100) for ctr …

Member Avatar for TrustyTony
0
250
Member Avatar for margreet

[Dive Into Python](http://www.diveintopython.net/toc/index.html) covers all aspects, but if you are beginning there are other tutorials at the [Python Wiki](http://wiki.python.org/moin/BeginnersGuide/Programmers).

Member Avatar for woooee
0
151
Member Avatar for xav.vijay

Since it is a count, fetchone will not return anything. You could also fetchall, on a straight select, and check the length of the returned list if that is more straight forward.

Member Avatar for TrustyTony
0
627
Member Avatar for BThomps

You call randomNumGenerator() twice, once in each of the two functions and so are working with two different values (althought it is possible to return the same value twice). If you are going to tutor then you should try to follow the [Python Style Guide](http://www.python.org/dev/peps/pep-0008/) and stop using the half-camelCase …

Member Avatar for BThomps
0
239
Member Avatar for windiggy

~~~ if color in "rgb" and color != "": ~~~ if color is in "rgb" it can not be equal to "" or any other character, so this is redundant.

Member Avatar for woooee
0
360
Member Avatar for MunkyCheez

You also have to convert from strings in the file, to integers. A read and convert example ~~~ test_data="""1 4 5 3 1 0 2 4 18 5 2 0 0 9""" # ##f = open(inputfile, "r") f = test_data.split("\n") # output_list = [] for rec in f: numbers_as_strings = …

Member Avatar for woooee
0
4K
Member Avatar for aquaben

Your program works fine for me, after correcting some indentation errors, on Python2.7. Show us what the program prints. ~~~ def enter_names(): fn=raw_input("please select your first name ") ln=raw_input("Please select your Last Name ") return fn, ln def enter_numbers(): fnbr=input("please select your favorite number ") sfnbr=input("please select your second favorite …

Member Avatar for woooee
0
106
Member Avatar for oldSoftDev

You don't check the last element, so possibly want to use ~~~ for x in range(0,len(mylist)-1): ## don't compare "x" to itself and go to the end of the list for y in range (x+1,len(mylist)): ~~~ This will give you a count for each item, so you will get three …

Member Avatar for TrustyTony
0
218
Member Avatar for vlady

You have to append a newline, "\n" ~~~ for record in ['<table border="1" cellpadding="15" cellspacing="5" width="100%">', '<tr>', '<th colspan="2">Vysvedcenie</th>', '</tr>', '<tr>', '<td width="50%">Meno, Priezvisko:</td>\<td>Skolsky rok:</td>', '</tr>'] ## number of lines truncated above vytvor.write("%s\n" % (record)) ~~~

Member Avatar for woooee
0
192

The End.