15,190 Topics
![]() | |
[code]def main(): splash() wordTotal = 0 longestWord = 0 fin = open("constitu.txt") for line in fin: #n = fin.readline() wordLine = line.split() #word = wordLine.split() wordTotal += len(wordLine) #if len(word) >= 15: #longestWord += 1 #print word print "This constitution has ",wordTotal, " words." def splash(): print "This program is … | |
I have python 2.5.2 on my Debian system n want to upgrade it to python 2.6. Got to know that apt-get install package searches for package in /etc/apt/sources.list I have downloaded python 2.6.2. How to add an entry to the file /etc/apt/sources.list ? :( | |
Hi everyone, I am trying to create a list of objects in python. I get the listing of all of the files from the directory that I want. Then I open each file and read it into an appropriate object and append it to the list. For some reason when … | |
Howdo you delete a name from the local namespace and occurs as a free variable in a Nest block? | |
[CODE]def exportTextList(fileInput, wordList): fileOpen = open(fileInput) for line in fileOpen: line = line.rstrip("\n\r") lineList = line.split() wordList = wordList + lineList return wordList def main(): fileInput = 'PlayerNames.txt' wordList=[] exportTextList(fileInput, wordList) print wordList[/CODE] My code summary: I'm taking a txt file, playernames, and i'm stripping all of the line breaks … | |
I am having trouble with this problem, I need to enhance the red intensity of each pixel This is what i have [CODE]import cImage def makeRedScale(imageFile): myImageWindow = ImageWin("Image Processing",600,300) oldImage = fileImage(imageFile) oldImage.draw(myImageWindow) width = oldImage.getWidth() height = oldImage.getHeight() newImage = emptyImage (width,height) for row in range(height): for col … | |
Hi, How do I find the frequency of each item in a list in Python? For example if there are five 'apple', two 'banana', and so on in the list, how do I write a program so that it displays the item as well as the number of times it … | |
Hi guys, Have been doing some wxPython programming and haven't had any major issues until I wanted to display images! Basically I take readings from an external device (simple input device) and set the image in a panel based on this reading. However it seems that the picture does not … | |
Please someone help to print function has to print numbers like Snack and ladder game when 2 variables rows and columns are passed to a function. ex: fun(4,3) 12 11 10 7 8 9 6 5 4 1 2 3 | |
Hello: I've been attempting to create a treemap (binary search tree) insertion and display function for a bit and am puzzled by the recursive calls. I've tried quite a few things, but the problem seems to be in my mapInsert function. Here's all the code I've written so far in … | |
The following is a recursive function designed to return the factorial of a number. [CODE] def factorial(number, target): if number == 1: return target else: target = target*number factorial((number-1), target) print factorial(7, 1) [/CODE] As you'll see if you run it however it doesn't return my 'target' variable (the factorial … | |
I have dictionary with single element lists. [CODE]dictionary={'a':['A'], 'b':['B'], 'c':['C']} [/CODE] How can i change it to [CODE]{'a':'A', 'b':'B','c':'C'}[/CODE] | |
Hi I have a question about a problem I'm having with raw_input function in python. I'm writing a CL program that requires a comment to be entered by the user, however problems arise when someone makes a mistake entering said comment. [CODE=python]comment = raw_input(Enter comment: )[/CODE] User Input: Archie^?ve testing, … | |
I dont know what goes wrong in this piece of code?!! I keep getting the following error. File "<stdin>", line 11 t1.append(list[temp]) ^ SyntaxError: invalid syntax [CODE]tl = [] for inlist in token_list: temp=[] for token in inlist: temp.append((zlib.adler32(token,65521)) tl.append(temp)[/CODE] | |
I have a class with a button, it runs the command automatically when the gui is constructed (which i dont want it to do) but then doesnt work again after. What am I doing wrong? Builtin commands such as endcommand work as they should. relevant excerpts (ignore the indent problem … | |
Hello, I have been working on this code but I can't seem to make it work. I want to implement function index() that takes as input the name of a text file (as a string) and a list of words. For every word in the list, the function will print … | |
Okay, I started learning Python last weekend on Saturday with some tutorials and a book. With this being my first programming language my program won't amaze you :P The program I made is a calculator for working out how much turf a person would need given the length and the … | |
Is it possible to sort a list of numbers from largest to smallest? Like if I had a list of numbers in variable a | |
im wanting to sort files by size and pick the top 20 i have managed this with the glob.glob statement but it does not work quickly and does not pick up if a file is modified/ added while the code is running. i have worked out how to do this … | |
Hi I am in a web programming class and have been struggling greatly with this assignment. I am not very familiar with Functions and so forth but I have been truthfully working on this for a few days now. I am at the point where I am stuck. I would … | |
Takes an XML, XHTML, HTML, Javascript or CSS file and creates a pretty printing version. | |
I am new in Python. May any one tell me how to validate XML file in python from DTD and Schema document.... | |
[CODE]f = open("summatest.01.sis", "rt") n = (f.readline()) jada_elemendid = f.readline().strip().split(' ') otstav_summa = f.readline().strip() f.close() # Valjund vfal = file("sum.val", "w") lmargid = [] def otsi(k): if (k < n): print n k = k + 1 lmargid.append("+") if otsi(k): return True lmargid.append("-") print lmargid else: z = jada_elemendid[0] for … | |
In python it will give a decimal like 52.2 and I was wondering if there was a way to make it round all decimals up to the next number like 53. | |
If I have a list and I already have split the line in the file. I also have figured out the code to average the numbers in the list now I have want to figure out a way to somehow take the average from the list of numbers and give … | |
Hello fellows... Is there something like static function variables in python? I know there are static attributes of a class, but what if i want to use a static variable inside a function? somthing like this (stupid) code in c++ for example: [code]int static_num() { static int x = 0; … | |
To maximize the value of the knapsack The output should like this >>>Bags=[mkBag('cooper',30,120),mkBag('silver',20,100),mkBag('gold',10,60)] >>>knapsack(Bags,50) [('gold',1.0),('silver',1.0),mkBag('copper',0.666666666)] [CODE] class Bag(): __slots__ = ('name', 'weight','value', 'ratio') def mkBag(name,weight,value): bag=Bag() bag.name = name bag.weight = weight bag.value = value bag.ratio=value//weight return bag def printbag(bags): print("Name:", bag.name, "Weight:",bag,weight,"Value:", bag.value) def knapsack(bags,maxweight): bags=sorted(bags, key=lambda mkBag: mkBag.ratio) … | |
Hello, We are trying to use Django with couchdb, is this a good idea??? It is going to be a health software, so is it better to use couchdb. Also we are going to use wtforms. Will this make a good combination for a complete software. Any more suggestions will … | |
Hello, I'm a new python user and I'm trying to create a python program that will run on a targate and communicate with the terminal. The main idea is to run several commend and short programs and analyze the results. for example running those 2 commands: cd /home/user/folder ls | … | |
below is how an snmp get is issued using pysnmp errorIndication,errorStatus,errorIndex,varBinds = cmdgen.CommandGenerator().getCmd( cmdgen.CommunityData('xxxx', 'xxxx', 1), cmdgen.UdpTransportTarget(('192.168.5.157', 161)), (1,3,6,1,4,1,18489,1,2,1,4,5,[B]1[/B],0)) In the OID part, the integer in bold keeps changing from 1 to 38. I need to put the above in a loop, instead of issuing 38 seperate gets. how can … |
The End.