3,386 Posted Topics

Member Avatar for dustbunny000

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]

Member Avatar for TrustyTony
0
89
Member Avatar for Limiter

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, …

Member Avatar for TrustyTony
0
300
Member Avatar for Razgriz411

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

Member Avatar for TrustyTony
0
87
Member Avatar for n3red
Member Avatar for lucksoar

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 …

Member Avatar for TrustyTony
0
199
Member Avatar for blast

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]

Member Avatar for woooee
0
650
Member Avatar for pythonlearning

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)

Member Avatar for pythonlearning
0
161
Member Avatar for sravyen

[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 …

Member Avatar for TrustyTony
0
7K
Member Avatar for DragSkull

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 …

Member Avatar for ScottieF
0
154
Member Avatar for pixelss

[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, …

Member Avatar for TrustyTony
0
110
Member Avatar for pacers10

[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 …

Member Avatar for TrustyTony
0
129
Member Avatar for Archenemie
Member Avatar for testie

[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]

Member Avatar for TrustyTony
0
573
Member Avatar for newbieha

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= …

Member Avatar for TrustyTony
0
2K
Member Avatar for ch1zra

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]

Member Avatar for Gribouillis
0
144
Member Avatar for danholding
Member Avatar for Gribouillis
0
269
Member Avatar for lewashby

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.

Member Avatar for Gribouillis
0
192
Member Avatar for lewashby

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]

Member Avatar for woooee
0
6K
Member Avatar for ZigZagMan

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 => …

Member Avatar for TrustyTony
0
75
Member Avatar for Don Brooklyn

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?

Member Avatar for TrustyTony
0
111
Member Avatar for sravi.pearl
Member Avatar for TrustyTony
0
170
Member Avatar for barney1

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.

Member Avatar for TrustyTony
0
546
Member Avatar for rahul8590

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 …

Member Avatar for TrustyTony
0
202
Member Avatar for Bombshock

if line ends with ms, rpartion, partitition, float. This sequence of functions with correct arguments should work.

Member Avatar for TrustyTony
0
149
Member Avatar for evertron

[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 …

Member Avatar for woooee
0
88
Member Avatar for KrazyKitsune
Member Avatar for evertron

[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 = …

Member Avatar for evertron
0
236
Member Avatar for Roelof Wobben

You are at least forgetting to push (CODE) before pasting code and you dropped 'i' from import.

Member Avatar for Reverend Jim
0
125
Member Avatar for tpkemme

[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 …

Member Avatar for TrustyTony
0
152
Member Avatar for ddalgibbang
Member Avatar for Gribouillis
0
115
Member Avatar for tpkemme

[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 …

Member Avatar for TrustyTony
0
137
Member Avatar for Overachievious

[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]

Member Avatar for TrustyTony
0
226
Member Avatar for KrazyKitsune
Re: if

[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?

Member Avatar for griswolf
0
109
Member Avatar for neely615

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]

Member Avatar for neely615
0
580
Member Avatar for dustbunny000

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]

Member Avatar for TrustyTony
0
849
Member Avatar for doctorjo5

How about using cgi module? When I entered it goes ofter POST of the input to my main index page.

Member Avatar for Schol-R-LEA
0
222
Member Avatar for Ashena

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 …

Member Avatar for TrustyTony
0
14K
Member Avatar for dustbunny000
Member Avatar for Nick Evan
-1
88
Member Avatar for dustbunny000

[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.

Member Avatar for Gribouillis
0
127
Member Avatar for arareyna

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.

Member Avatar for Gribouillis
0
3K
Member Avatar for softbrianes
Member Avatar for pacers10
Member Avatar for TrustyTony
0
64
Member Avatar for pacers10

item is undefined. If type of mean is float, then alist > mean as 'list' > 'float'

Member Avatar for Schol-R-LEA
0
95
Member Avatar for pacers10

[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" : …

Member Avatar for Schol-R-LEA
0
81
Member Avatar for Don Monroe

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): …

Member Avatar for TrustyTony
0
324
Member Avatar for Saboo-Coder
Member Avatar for TrustyTony
0
108
Member Avatar for novice20

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]

Member Avatar for ptmcg
0
231
Member Avatar for gishi

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 …

Member Avatar for TrustyTony
0
370
Member Avatar for novice20

[CODE]data.replace(':enterprises.18489.1.2.1.5.1.10.0 = INTEGER: 1','...........XXXXX=INTEGER:1') [/CODE]

Member Avatar for woooee
0
122
Member Avatar for --Fire--

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. …

Member Avatar for Archenemie
0
748

The End.