2,190 Posted Topics
Re: The error appears to be on the previous line. First, make sure that this is actually a Python3 package and not a Python2 package. There are many packages that have not been ported to Python3x. | |
![]() | Re: "Why is this taking so long" is a question that is too general for you to answer. So learn to use [url=http://wiki.python.org/moin/PythonSpeed/PerformanceTips#Profiling_Code]profiling[/url]. The first few sentences read "The first step to speeding up your program is learning where the bottlenecks lie. It hardly makes sense to optimize code that is … |
Re: You use "replace" so it replaces all text that is equal (duplicates), when you should slice off the word. [code]def split_word(word, numOfChar): r = [] # h = len(word)/numOfChar ## not used while True: if len(word) == 0: return r else: r.append(word[0:numOfChar]) word = word[numOfChar:] ## changed return r print … | |
| |
Re: Sets are the way to go [code]# assumes each square is numbered 1 thorugh 9, not 0 through 8 ## rows, columns, & diagonals winner_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9], \ [1, 4, 7], [2, 5, 8], [3, 6, 9], \ [1, 5, 9], [3, … | |
Re: Some suggestions; use a for() loop to pick a random number on each pass, and another list/tuple for the values corresponding to the random number. Also, it is personal preference, but you can use a function to get the input and only return when the input is recognized. A subset … | |
Re: See the grid manager [url=http://infohost.nmt.edu/tcc/help/pubs/tkinter/layout-mgt.html#grid]here[/url] or [url=http://effbot.org/tkinterbook/grid.htm]here[/url]. | |
Re: Use a list [url]http://www.greenteapress.com/thinkpython/html/book011.html[/url] [code]input_list = [] while True: ID = input('> ') if ID == 'exit': ## "is" is different from equal break else: input_list.append(ID) print input_list[/code]or a dictionary [url]http://www.greenteapress.com/thinkpython/html/book012.html[/url] [code]number = 1 ## integers remove leading zeros automatically input_dict = {} while True: key = 'A%03d' % (number) … | |
Re: First, these while() loops and/or "break" are not necessary [code] if command == "look up": print "You look up to the ceiling but nothing of any use is up there." # break elif command == "look down": # while 1: print "You look down you are sat on a bed." … | |
Re: You should probably ask this question on the Daniweb MS Windows forum that corresponds to your version as this is an "install software on Windows" question and not a Python question. | |
Re: I would suggest that you start with a tutorial on passing and returning parameters in functions like [url=http://hetland.org/writing/instant-python.html]this one[/url], and also read up on changing variables, see "Arithmetic Operators" [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutdata.htm]here[/url], as this question is covered in every tutorial and too simple to be asking someone else about. Your code, modified … | |
Re: NoneType means that delitem deletes in place so list.__delitem__(index) works for your code, and list = list.__delitem__(index) binds "list" to the return value=None. Also, choose a name other than "list" as that is already used by Python to convert to a list. | |
Re: [quote]since 1 is less than two[/quote]Then it is not one. Add a print statement to show what is being compared. [code]def Fitness(a,b,c): f = [a,b,c] print "comparing", f[0:2], "against 2, 3, and 4" if f[0:2] >= 4 and sum(f) >= 13: print 'Gold' elif f[0:2] >= 3 and sum(f) >= … | |
Re: [quote]the gif-frame stops but the tiny Tk-win wont stop[/quote]The stop button is only bound to the wxpython widgets. You would have to have a separate stop button in Tkinter, or as stated above, the usual process is to code everything using the same tool kit. | |
Re: pow is a function in the "math" program [code]import math print r"pow(2,3) returns 2^3-->", math.pow(2,3) [/code] | |
Re: [quote]but I have no idea how I would label it[/quote]The labels would be outside of "grid" if you want to use it in a game, and so change the contents. They would be incorporated in a print_grid() function as the only time you require labels is when the grid is … | |
Re: [code] for number in range(a,b,c):[/code]This prints a number starting with "a", ending at "b", and the step/increment is "c". What happens if b<a? [code] if len(x)== 2: a=x[0] b=x[1]+c ## <----- "c" does not exist at this point c=1 [/code]Also you can just use [code] else: x_str_array = x_str.split(',') # … | |
Re: [QUOTE=Lameness;1726567]I think Pythonbeginner! means something like this: string of letters: 'abcdefgh' list of integers: [(2, 6)], how can you extract the letters from 2-6 (cefg)?[/QUOTE] (cefg) what happened to "d". [quote]Can anyone give a clue?[/quote]You can access the letters in a string by it's offset (note that the fifth offset … | |
Re: [code] def move(self, board, temp_stack): if board.game_end(): [/code]What does the function game_end test? Definitely not new_board or new_stack since they are not instance variables and are not passed to the function, so the game_end function is testing some container that does not change. Add a print statement to the function … | |
Re: Vegaseat's [url=http://www.daniweb.com/software-development/python/threads/221705]example[/url] from this forum [code]# explore the ttk.Progressbar of the Tkinter module ttk # ttk is included with Python 3.1.1 import tkinter as tk from tkinter import ttk def click(event): # can be a float increment = 4 pbar.step(increment) root = tk.Tk() root.title('ttk.Progressbar') pbar = ttk.Progressbar(root, length=300) pbar.pack(padx=5, pady=5) … | |
Re: [quote]I need a library for a certain script and I don't know which one to choose[/quote]What are the options that you are choosing from? This is the Python programming forum for posting programs written in Python. I don't know what you mean by "library", but there is nothing that exists … | |
Re: "board" is global and a list, which is why you can pass it to a function but not catch the return and still have an updated board. Either pass and return the variable (the accepted method) or delete the variable in the function definition. This code can possibly reach a … | |
Re: I would assign a unique number to each character that makes up a maze. Then you can find S(tart) and proceed in whatever direction there is an space, keeping track of the path taken so you try different solutions. Also, you might want a variable that is set to True … | |
Re: Yes it is. Do you get the error on the next line in the program? We don't know since you didn't include the entire error message, but it appears that the compiler has gone to the next line looking for the missing apostrophe. [code]## This works without any errors data=[('Geo','Elephant',['hay','peanuts']), … | |
Re: You would probably have to use a large grid with squares, like a large tic-tac-toe board, with a unique number for each square . Also, if you store what the square is, a wall or open space, then you should be able to come up with a formula/decision table to … | |
Re: Your link gives a 404 error [quote]Well, Im sorry you had to see this... ...but this page doest exist. Does that even make SENSE? Try it again. If that doest work, falcon punch your computer - especially if its a Macboo--*shot*.[/quote] | |
Re: [quote] #now retrieve next item in list without looping again #something like record.next()[/quote]Use readlines, which reads the file into a list.[code]f_data = open('file.txt').readlines() while ctr in range(5): ## first 5 only print "this_rec", f_data[ctr] if ctr > 0: print "previous_rec", f_data[ctr-1] print "next_rec", f_data[ctr+1] print "-"*50 [/code]There are many examples … | |
Re: Assuming both files are the same length (if they are not you will have to account for that), use the same offset for each list, i.e. record 1 from file a-->record 1 from file b [code]for ctr in len(energy_in): ## print them for testing print energy_in[ctr], slab_in[ctr] energy=energy_in[ctr].split() ##for j … | |
Re: Passing parameters to a function [url]http://www.tutorialspoint.com/python/python_functions.htm[/url] | |
Re: You can use lists also to clean up the code [code] if (size == 1): ## if (style == 1): price_list = [0, 5.95, 7.00, 6.50, 9.00, 11.00] price = price_list[style] """ Replaces if (size == 1): if (style == 1: price = 5.95 elif(style == 2): price = 7.00 … | |
Re: That is correct, you are comparing for highest price. [code]## copied with code tags for other readers num=0 price=0 lowest=0 HST=0.13 items=0 print "Enter 0 to print receipt.\n-----------------------" while price>0: price=raw_input("Enter your price here: $") price=float(price) num=num+price#num is the subtotal print "tag2" while price<0: print "Invalid number" price=raw_input("Enter your price … | |
Re: Sorry, Tony already answered. The indent is probably incorrect. | |
Re: [quote]I need to have it so that it knows when a note button is clicked[/quote]The standard way is to set some variable. In Tony's code, a button click calls play_note() and sends it the note and key. You could use the key to tell which button is clicked and possibly … | |
Re: You either use the grid manager or a separate Frame for each set of 3 buttons. [code]from Tkinter import * class GUI(): def __init__(self, r): self.r = r self.i = StringVar() self.f = Frame(self.r) self.f.pack(fill = BOTH) self.g = LabelFrame(self.f, text = 'Groupbox 1', height = 90, width = 150, … | |
Re: Use subprocess not execfile [code]#!/usr/bin/python #-*- coding:Utf-8-*- # -*- coding: cp1252 -*- import os import subprocess print 'hello' #os.system("sudo chmod 777 /home/ismail/Bureau/Test/20111214") subprocess.call("/path/to/program/Backup1.py", shell=True) [/code]There are many, many docs on the web about subprocess if you want to know more, as it is used in many different ways. | |
Re: Just test for it and eliminate the trailing period [code]test_text="prob=0.345." test_text = test_text.strip() if test_text.endswith("."): print test_text[:-1] print test_text[:-1].split("=")[/code] | |
Re: You should also incrementally test your code and not just post a load of crap and demand that we fix it for you, or otherwise we are jerks. I get that your web page is zipped in some odd form. Note that urlopen().read() returns a string or bytes, not a … | |
Re: You can code your own check using Python's isdigit() function, but as we have no way of knowing what you have studied in class, you will probably just come back and say that you haven't used it in class, so it would be a further waste of time. [code]def int_check(str_in): … | |
Re: All of the else: pass statements do nothing and can be eliminated [code]if len(m)>1: Properties['Proper divisors']= str(m) else: ## does nothing pass # # while n>0: ## you don't change "n" so this is an infinite loop UI=str(raw_input('What are you looking for?')) if UI=='Everything' or UI=='All': print Properties elif UI=='Properties' … | |
Re: if text == char: should yield an error since "char" has not been declared. If you want to test for letters it is easier to test for dot or dash as the if and use letters in the else (asuming there are no periods or dashes when letters are input). … | |
Re: The OP has it correct [quote]I need to print data using if-elif statement elif row['password']=='muta55':[/quote]. | |
Re: You have to test for more than a period unless you know the sentences won't contain abbreviations. Take a look at this variation: [code]import re def sentCapitalizer(): s = 'the money is in the bag Mr. Jones. however you dont want it.' rtn = re.split('([.!?] *)', s) print('') print(''.join([each.capitalize() for … | |
Re: We don't have the Button class so can't test your code. Also, if the Button class does not provide a callback (way to call a function when clicked) you will have to write your own. So far you have done very little, even the easy things like randomly choose one … | |
Re: This post is the same as [url]http://www.daniweb.com/software-development/python/threads/398951[/url] Take a look at it first, and then post any further questions. | |
Re: You don't need functions for something this simple: [code]num_english = {0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine"} for num in [0, 5]: print num, num_english[num] [/code]So now, all you have to do it iterate over the numbers. … | |
Re: The following works for me. Check the rest of your code that is not posted for differences. [code]from Tkinter import * class MyDialog: def __init__(self,parent): self.Frame1= Frame(parent) self.Frame1.pack() self.enabled = IntVar() self.checkbutton = Checkbutton(self.Frame1,text = "Enable Email Option", variable=self.enabled,command=self.OnCheckBoxClick) self.checkbutton.pack() def OnCheckBoxClick(self): iTemp = self.enabled.get() print "iTemp %s"%iTemp root=Tk() M=MyDialog(root) … | |
Re: You open the file every pass through the loop, and only read one record. Read the file once before the loop and store it (like the list of lists below), then access the stored values. [code]file_object = open('herp.txt', 'r') data_as_list = file_object.readlines() file_object.close() product_list_of_lists = [] ## process 2 records … | |
Re: [quote]I am trying to read a text file into a 2D list.[/quote]Assuming you want each record to be one row of the 2D list, you are making your code too complicated. [code] infile = open(infile,"r") old_2D =[] for line in infile: line = line.strip() new_row = [] ## start with … | |
Re: To append the two recs together, you want to say something like, [code]data=open(fname, "r").readlines() for ctr in len(data): if data[ctr].strip().startswith("DATE:"): print data[ctr].strip(), data[ctr+1].strip() [/code]EOL though is actually decimal 10 or 13 or a combination of the two. Decimal 127 is Delete. To eliminate it, try something like this:[code]eliminate=chr(127) rec=rec.replace(eliminate, " … | |
Re: You don't ever exit the "while True" loop. and colour.split() != colourslst: This will never be true because one has four colors and one has 5 colors (excuse me, 'colours'). You definitely want to add some print statements to see what is happening in the program. |
The End.