3,386 Posted Topics
Re: 6th item of the list is item number 5, so you must reduce factorA to accomodate this 0-based indexing. __init__ should have same indentation as other def's, probably cut-and-paste error. [CODE] def __init__(self, indata): self.data = indata self.total = len(self.data) def getTtestFactorA(self, factorA): ListFactorA = [] for factorA in self.data: … | |
Re: I do not know what you want to accomplish, but this code does at least something: [CODE]from graphics import * def main(): x = 0 y = 0 while not(3<=x<=9): x = int(raw_input("Enter The Width Of Your Patch: ")) while not(3<=y<=9): y = int(raw_input("Enter The Height Of Your Patch: ")) … | |
Re: Maybe 'it is better to ask forgiveness than permission' ie try.,except | |
Re: why you do not make list in for loop or list comprehension out of bricks? | |
Re: Make sure you understand [B]import this[/B] The philosophy of Python reminder for your contemplation [B]Duck typing[/B] Invest time for testing and designing use cases instead of catching mistakes of users before hand, instead: [B]“it's easier to ask forgiveness than permission” [/B]try..except..else is your thing not hasattr (except from basestring type … | |
Re: I do not understand how the track<11 could become False. | |
Re: You are not getting to out the lines that are after the tagged lines. Add to line the next one stripping the new line: [CODE]input1 = open("in.txt") output1 = open("outp.txt","w") with input1 as f: out = ''.join('%s %s' % (line.rstrip(),next(f)) for line in f if line.startswith(('a)','b)','c)','d)'))) # startswith works with … | |
Re: def guessing(self): tite = self.character_ent.get() tite = tite.lower() if tite in self.getName(): newer = "" for i in range(len(self.getName())): if tite == self.getName(): newer += tite else: newer += self.so_far[i] newer.replace(i,tite) self.so_far = newer self.movie_name_txt.delete(0.0,END) self.movie_name_txt.insert(0.0, self.so_far) Push (code) button for correct tags. This is completely ununderstandable anyway, need real … | |
| |
Re: I am not any special re optimizer, but wouldn't one use something similar to this? [CODE]import re myteststr='x = 78.36734693877551, z = 11.428571428571429 -> amplitude: 8.62847057093655E-6 | phase -1.5707968246742405\n' rs=re.compile('(-*\d+.\d+E*-*\d*)') print map(float, rs.findall(myteststr)) [/CODE] | |
Re: Maybe you could find any inspiration from my boggle code: [URL="http://www.daniweb.com/code/snippet299470.html"]Yet another boggle word game [/URL] For enterless input see: [url]http://snippets.dzone.com/posts/show/915[/url] | |
Re: What is purpose of 20 and 21 and why function at 44-47 after main code? And if by miracle the while would be entered which miracle would give value for [B]used[/B] ;) | |
Re: Something like this situation? [CODE]try: from pretty import ppr as pprint # my pretty printer, see snippet archive except: from pprint import pprint # standard fallback def outten(a): for i in range(1, 1+10): yield float(a) / i def outone(x): yield x / 2.0 values = (1, 2, 3, 4, 21, … | |
Re: You are not calling that function, how do you know it does not work? Looks like you have linked low level data structure. Can you tell if all code is yours and if not what you have added and how have you tested it? | |
Re: Here is my start also, but it sorts the lines by alphabetic order input files are supposed to start with same letters (here 'file0') and end with '.txt'. [CODE]import os import itertools ids = [] lines = [] for fn in (f for f in os.listdir(os.curdir) if f.startswith('file0') and f.endswith('.txt')): … | |
Re: Reconsider about dynamic typing, read this for fun: [url]http://en.wikipedia.org/wiki/Duck_typing[/url] Otherwise maybe you should start coding in Ada, where you can really 'enjoy' strong typing.:icon_twisted: Also this thread should then be 'typed' as solved thread, so can you mark it so :) | |
Re: Simpler to write instead of lines 6 and 7[CODE]totalScores += number * score [/CODE] What you are trying to do? | |
Re: Example of input (instance of the class) and expected output would help. I get error: [CODE]Traceback (most recent call last): File "J:/Python26/kort.py", line 13, in <module> kort = Kortlek() File "J:/Python26/kort.py", line 10, in __init__ tmp= Kort(color, form, number, grade) NameError: global name 'Kort' is not defined >>> [/CODE] | |
Re: Would be maybe cleaner not to use function names min and max, even it is this local scope as keyword parameters. Matter of style only, has points of easy to remember keyword name. Here little modified version: [CODE]def get_user_value(start=None, end=None, message=None, converter=float): if (start is not None) and (end is … | |
Re: [CODE]products = ["YELLOW,SMALL,STRETCH,ADULT,T21fdsfdsfs", "YELLOW,SMALL,STRETCH,ADULT,Tdsfs", "YELLOW,SMALL,STRETCH,ADULT,TD"] products = [this.rsplit(',',1)[0] for this in products ] print products [/CODE] | |
Re: This is how I would do, maybe you can use it to debug your solution: [CODE]def list_str(lst, per_line): # given a list of items, # return per_line items per line. start = '[' while len(lst) > per_line: start += str(lst[:per_line])[1:-1]+',' yield start start ='' lst =lst[per_line:] yield start + str(lst[:per_line])[1:-1]+']' … | |
Re: On the other hand useful fact is also to remember that [QUOTE] >>> print(Fraction.from_float(pi).limit_denominator(10000)) 355/113 >>> 355/113.0 3.1415929203539825 >>> 355/113.0-pi 2.667641894049666e-07 >>> [/QUOTE] | |
Re: And the connection with Python language? [url]http://filext.com/file-extension/T[/url] [url]http://www.freedownloadscenter.com/Business/Document_Management_Tools/Paradox_viewer.html[/url] | |
Re: You are giving suit as Jordan and you are not using the return value from validSuit (which you should name valid_suit). | |
Re: And put at the end of program: [CODE] mainloop() [/CODE] | |
Re: I can not see that you changed the function, you are putting value to first fitting slot from beginning, not say find combinations closest to container size. To inputs look ugly, you can use [iCODE]while itemweight:[/iCODE] and read the values to list from input inside the while. Put some print … | |
Re: In python there is not main program, but the code in highest indention level is executed when code is loaded. To stop modules main code to run you can put [ICODE]if __name__ == 'main':[/ICODE] in beginning of that code. For object oriented program main program would generally be used to … | |
Re: test.txt is not good variable name you should probably have 'test.txt', loriginal will contain fist line of file, line is not defined, split is splitting (you should use rstrip), newline is by the way '\n'... Your code is junk. Start over, if you need to cheat, check my answer in … | |
Re: [iCODE]del self.FrontBmp[/iCODE] does not function, you mean? | |
Re: Your practice does not require indention. No conditions or loops. | |
Re: Make button event which changes the color on button click. | |
Re: [CODE]from itertools import islice f = open('11.txt') # alice in wonderland guttenberg print ''.join(islice(f, 100, 110)) """Output: Presently she began again. 'I wonder if I shall fall right THROUGH the earth! How funny it'll seem to come out among the people that walk with their heads downward! The Antipathies, I … | |
Re: [CODE]with open(filenm) as infile: lines = tuple(line.rstrip() for line in infile) with open(filenm,'w') as outfile: outfile.write('\n'.join(lines)) [/CODE] | |
Re: Here is my menu system, maybe you could adapt it? [CODE]from Tkinter import * import Tkinter as tk def create_header(t,top): ## Creates the Headings frame1 = Frame(top, relief=GROOVE, borderwidth=2) label1 = Label(frame1, text=t, font=('Arial', sqsize/2), fg="red") label1.pack() top.create_window(middle, sqsize, window=frame1, anchor=N) top.pack(fill='both', expand='yes') def create_buttons(t,place,c, top): ## Creates the Buttons … | |
Re: Playing little with [URL="http://www.daniweb.com/code/snippet316585.html"]my code snippet[/URL] could give some ideas how to proceed (but you need not open the files like I did to find the text in them) | |
Re: Your design is ununderstandable, but I did something to get it print the content of given filename as it's str or ask user the filename as input: [CODE] # Lexicon Class read and write a file """This is the Lexicon Class""" class Lexicon: def __init__(self, filename=None): self.file = None while … | |
Re: You could write down some amounts from your head and the amount of change the program should suggest to return. (One your shopping receipts plus some imaginary payments for each amount in it, for example) Put those as test function unittest and run that with your function for change to … | |
Re: Why you have nested definition inside __init__? | |
Re: Use copy.deepcopy to copy list and it's dictionaries. | |
Re: endswith accepts tuple argument. What happens if there is y inside word ending with 'y'? Why you do not use slicing and join method? | |
Re: Use the CODE button, then paste correctly indented code. | |
Re: It is more accurant to say: 'I have found tonyjv's post with this code for consentric circles in Daniweb'. Somebody could think that you wrote those lines yourselves. Also it is considered necessary to show some own effort. And use the (CODE) button before pasting, putting a link to the … | |
Re: global scope lines are top-level lines outside the functions without indentation like line 6 in your code. | |
Re: You have still things left to fix Wildbamaboy only gave you start. One thing I for example do not understand is your docstring. Make some test cases for your code. | |
Re: I would suggest to change the file name repr to something else as it is one basic Python function and using it as variable is confusing. | |
Re: What Python are you using or are you another of those lost lambs? | |
Re: Here is advanced version, try to understand the logic and do regular loop of it if generator is too unfamiliar: [CODE]my_list=[1,2,3,4,5] print my_list.index(3) print next(index for index, value in enumerate(my_list) if value==3) [/CODE] | |
Re: Your formula in text gives me strange maximum: negative value. Brute force is very fast, I do not know why you need to optimize. If I only know that the number is maximum same bit length as maximum of b and c, which is known. [CODE]from __future__ import print_function import … | |
Re: Of course you are returning the windchill like vegaseat returns celcius? |
The End.