3,386 Posted Topics
Re: Also generator for loop would not be so bad as OP is considering itertools: [CODE] import random def test(number): for count in range(number): yield random.random() the_list = list(test(5)) print the_list[/CODE] | |
Re: It is customary to give the error message right after the input, not to take bunch of lines and then tell which lines are not valid if the program is used interactively, not reading from file input. One of handiest ways of dealing input from user is having own function, … | |
Re: People want to see your current understanding from reading your code, which you can paste in to your message after pushing the (code) button. Same you can do for any error messages and sample input and output. From advanced view you can attach pictures like screen shots and zipped archives | |
Re: What is error message? What is it supposed to do? I see one class definition but not any creation of objects or the pygame main loop (which is explicit, not hidden). At least at line 8 you seem to have second parameter misplaced inside quotes: [url]http://www.pygame.org/ctypes/pygame-api/pygame.font.Font-class.html#__init__[/url] I added in beginning … | |
Re: Here is wonderfull answer: [url]http://www.google.fi/url?sa=t&source=web&cd=1&ved=0CB0QFjAA&url=http%3A%2F%2Fdocs.python.org%2Ftutorial%2F&ei=g9C2TLDtI4WSOrWjuagJ&usg=AFQjCNGHgDIQyUXe76XiQvHhM6kr8-qTAA&sig2=Z10CrL9u3BpGs9jkN31Beg[/url] | |
Re: it is possible, though simpler is to make a number range of n repeated key_num//n +1 times, shufle and then divide list of keys by taking zip(my_dict.keys(), index_list) | |
Re: [QUOTE=Gribouillis;1364028]Here is what my console says [code=python] Python 2.6.5 (r265:79063, Jul 14 2010, 13:38:11) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pexpect >>> [/code] so pexpect works for python 2.6.5. :) There is a package python-pexpect on my Mandriva 2010. Check packages … | |
Re: You could use something like: [CODE]import random valid_range= (4,6,10,12,20,100) choice = 0 while not 0 < choice <= len(valid_range): try: choice = int(raw_input("what die would you like to use: "+''.join("\n\t%i) upto %i" % (ind+1,top) for ind, top in enumerate(valid_range)) + '\n\t')) if not 0 < choice <= len(valid_range): raise ValueError … | |
Re: [QUOTE=snippsat;1364139]Just to put in one line. You can try to understand the code and spilt it more upp. If it a school task you have to explain and understand the code. [CODE]>>> sum([float(item) for item in i.split(',') for i in open("numbers.dat")]) 47.0 >>> [/CODE][/QUOTE] To make code more Pythonically correct, … | |
Re: [CODE]Import # keywords are lower case, objects upper case in Python by convention, what is purpose of this variable t = open(""),"r") # where is this variable used, don't you think that opening and closing parenthesis should be equal number def findWord(aline):# blocks are indented after line with :, not … | |
Re: Why not simply os.listdir(os.getcwd())? | |
Re: [code=python] def sequenceprint(s): """Prints out the input string in succession""" i = 0 while i < len(s): print s[0:i+1] i = i + 1 [/code] | |
Re: Notice that because of recursion limit of Python, you can sort only very short lists with recursive algorihm. Therefore iterative version would be lot better (and best would be the built in sort). [CODE]import random def it_selsort(seq): result = [] while seq: min_in_seq = min(seq) seq.remove(min_in_seq) result.append(min_in_seq) return result tosort= … | |
Re: You could create file of same name from read in file from ziparchive, you will not get same file attributes though: [CODE]from zipfile import ZipFile as zf with zf('j:/Lataukset/Vb6501.zip') as f, open('MSBIND.DLL', 'wb') as out: out.write(f.read('Vb6501/MSBIND.DLL')) [/CODE] | |
Re: Why you do not do everything in Python? What external program does except creating the directory? | |
Re: put in print or assert statements to get values of variables at point of error. You did not include image files to run your code. | |
Re: You can assign tuple of values to tuple of variables in Python [CODE]>>> a,b = 0,1 >>> print(a,b) (0, 1)[/CODE] You can also do this: [CODE]>>> yes, no = 'YN' >>> print(yes) Y >>> print(no) N [/CODE] | |
Re: You generate though all factors, not only prime factors, and the print on line three does not also work as num is integer. The number of possible factorings increase much faster than number of prime factors (as for each number which has power n you take every power 1..n => … | |
Re: I do not understand the a variable which is overwritten and never used. Why don't you just substract the new origin from all points? | |
Re: Looks like copy paste code. What documents have you studied? What kind of changes have you tried? | |
Re: Look up yield from python documentation and change return to yield in two helper_functions. Alternatively collect the result in the [iCODE]for[/iCODE] in string variable or list. | |
Re: Also your indention is of (maybe only copy paste error). And it is good practice to learn to use with statement which automatically will close the file for you after processing and also if there is error in file handling in the block. Here is shown how to get easier … | |
Re: if line ends with ms, rpartion, partitition, float. This sequence of functions with correct arguments should work. | |
Re: [code] print "This program calculates a total after the user enters: \n the Item, Quantity and Price" #define process function def Processorderitem(quantitylist,pricelist): #discount variable so it can be changed discount = .03 subtotal = 0 for i in range(len(quantitylist)): for j in range(len(pricelist)): subtotal[i] = quantitylist[i] * pricelist[j] while quantity … | |
Re: [code]num = 0 #user input num = int(raw_input('Give me a number up to 10: ')) for a in range(0,num +1,1): print "*" * a #make a space for the next rows that count down print for a in range(num,0,-1):print'*' * a print'done' #a different way num = 0 num = … | |
Re: You are at least forgetting to push (CODE) before pasting code and you dropped 'i' from import. | |
Re: [QUOTE=slate;1359132][CODE] while not is_indented(text): print("Please apply code tag to your code!") [/CODE][/QUOTE] Maybe more exactly (code start tag misspelled to get the code tag work here): [CODE]while poster.isnewbie() and post.hascode() and not '[ CODE]' in post: print("Be kind and add code tags around your code when posting or you lose … | |
Re: Reducing by one bit counter by /2 -> log2 of counter times. | |
Re: [QUOTE=tpkemme;1358707]so now that i have gotten farther in the code, it prints the substrings correctly, but i can't get the program to stop correctly. basically, i'm looking for the longest common substring. i need help with last part. it correctly finds all the substrings but it doesn't stop at the … | |
Re: [CODE]import string string_in = " Many critics consider........" alphabet = set(string.ascii_uppercase) string_in = string_in.upper() print sorted(((string_in.count(c),c) for c in set(string_in) if c in alphabet), reverse = True ) [/CODE] | |
Re: [QUOTE=KrazyKitsune;1357173]I see. So the dispatcher are the choices? Then how about implementing inputs and something like 4+6 or 10+2?[/QUOTE] Not allowed to use eval? | |
Re: Maybe something like this: [CODE]import os for textfile in (filename for filename in os.listdir(os.curdir) if filename.endswith('.txt')): oklines = [line for line in open(textfile) if not (1569 < float(line.split()[0]) < 1575)] with open(textfile,'w') as outfile: outfile.write(''.join(oklines)) [/CODE] | |
Re: You can use recipe from my post: [URL="http://www.daniweb.com/code/snippet293490.html"]text file based information access by field name and number[/URL] | |
Re: How about using cgi module? When I entered it goes ofter POST of the input to my main index page. | |
Re: Then you can compress woooee answer to single line if you like: [CODE]test = """ID: 2 Time: 76 Op: GET Domain: facebook.com LPath: /common/css/common.css Referer: http://google.com User-Agent: Mozilla/4.0 ID: 3 Op: GET Domain: rfi.fr LPath: /common/css/common.css Referer: http://yahoo.com """ print '\n'.join(line for line in test.splitlines() if any(line.startswith(word) for word in … | |
Re: This is double thread see Gribouillis answer in other thread. | |
Re: [code]found = - 1 for search in list2: if seach in list1[found+1:]: found = list1.index(search) #handle correct case else: # not found case[/code] Show effort by finishing the code. This code as is would start again from begining if there is not matching letter in list2. | |
Re: I think Gribouillis function works beautifully. Just use that for time column and use int() for other values in line. Post your code and error messages and description of your efforts to solve the problem if you get stuck. | |
Re: numbers is not defined, random.randint needs lower and upper limit | |
Re: item is undefined. If type of mean is float, then alist > mean as 'list' > 'float' | |
Re: [QUOTE=pacers10;1354335][CODE]import copy def wordReplace (wordText): wordDict = { "hello" : "avast" , "excuse" : "arrr" , "sir,boy,man" : "matey" , "madam" : "proud beauty" ,"officer" : "foul blaggart" , "the" : " th'" , "my": "me" , "your" : "yer" , "is": "be" , "are" : "be" , "restroom" : … | |
Re: If you are doing the merge to loop the both lists in one go, you do not need to do so. Standard library way for this is to do itertools.chain(list1, list2). [CODE]import itertools as it seq1 = (1,2,3) seq2 = ['a', 'b','c'] print 'with itertools' for item in it.chain(seq1, seq2): … | |
Re: you repeat the lines the parameter times to make the picture higher. | |
Re: For example: [CODE]interesting = [dataline for dataline in open('data.txt') if any(part in dataline for part in ('/dev/hd','0x34'))] print ''.join(interesting) [/CODE] | |
Re: And what code page have you set up for the windows dos? I found CHCP 1252 works best for me, before I thought I had to live with code page 850 or 437, but fortunately it is not true. I have not tried how well the code page chcp 65001 … | |
Re: [CODE]data.replace(':enterprises.18489.1.2.1.5.1.10.0 = INTEGER: 1','...........XXXXX=INTEGER:1') [/CODE] | |
Re: you should determine minimum environment for running python interpreter and see what additional low level functions need to be implemented. I think that actual primitives of booting you can leave out. I can not imagine you writing FAT and EXT4 drivers, not to speak USB or Sata drivers in Python. … |
The End.