2,190 Posted Topics
Re: Note that you may have to append the path to the directory containing the file/module. An example of [URL=http://www.tutorialspoint.com/python/python_modules.htm]import[/URL] [CODE]import sys sys.path.append("/path/to/Car") import Car ## not Car.py as python appends the ".py" [/CODE] | |
Re: Lists have min and max functions which could also be used. For both code solutions, what happens if there is more than one month with the same rainfall? [CODE]def lowest_month (rainfall): lowest = min(rainfall) return MONTH[rainfall.index(lowest)], lowest [/CODE] | |
Re: This will never be true [CODE] if (curletter+key)>(25): if (curletter+key)<0: [/CODE] | |
Re: You can test for membership in the rows list (already input), assuming you want to do this on the input value. [CODE]if input_num not in rows: rows.append(input_num) # # or remove each number as it is entered input_list = [str(x) for x in range(1, 10)] while len(input_list): print "Enter a … | |
Re: Take as look at list methods [URL=http://docs.python.org/tutorial/datastructures.html]here[/URL]. You can use insert [CODE]list_start=[[1,2], [2,2], [1,3]] list_start.insert(1, [2,3]) print list.start[/CODE] | |
Re: I've added some notes on what is and is not happening. When you don't understand something it is usually good to break it into smaller pieces and solve each piece individually. This code is not even good enough to correct so start again and post back, next time include an … | |
Re: You can also use an indicator for wrong answers: [CoDE]right_answers = True while (abs(s1 - s2)!= 2): x = input("Faktor: ") y = input("Faktor: ") z = input("Rezultat: ") if z == x * y: s2 = s2 + 1 print "Trenutni rezultat : ", s1, " : ", s2 … | |
Re: [QUOTE]o, I have new_list = [52, 56, 57, 72, 85, 94]. I need to get difference between numbers from the list and average [52-51=1, ..., 72-51=21 and so on..], then raise the square of each, sum all them and divide from list length[/QUOTE] Process each number and use a list … | |
Re: I would suggest a print statement or two so you can tell what the program is doing. For future postings, we have no idea what "choice" is supposed to contain. [CODE]import random choice = raw_input("what die would you like to use: ") d4 = random.randrange(4)+1 d6 = random.randrange(6)+1 d10 = … | |
Re: [QUOTE]simple program, help[/QUOTE]I have never understood this type of title. If you don't know how to do it, then how do you know it is simple. And if it is simple, then why do you need help? Print the "nums" list inside the for() loop. It possibly contains more than … | |
Re: [CODE]MsgDataType = c_uint8 * 8 msg = MsgDataType()[/CODE]Not that you are using the same name twice. print type(msg) it may be a class in which case you would access it with msg.field_name | |
Re: Take a look at pexpect in addition to subprocess. | |
Re: Frist, you should test the findSlope function (see the python [URL=http://www.python.org/dev/peps/pep-0008/]style guide[/URL]. Function names are all lower case with underscores and you should not use "i", "l", or "O" as single digit variable names because they can look like numbers). [CODE]def findSlope (x1, y1, x2, y2): rise = y2 - … | |
Re: [CODE] for key_constant, pressed in enumerate(pressed_keys):[/CODE]If you are asking about this line (you didn't say), enumerate returns a counter and the original variable, with the counter incremented by one for each item in the list. It is similiar to this, as printing the variables will show [CODE]ctr = 0 for … | |
Re: First, you have to detect the object itself. Then you can construct a 3-4-5 triangle, or continue the same length as the base, creating a "T" with one of the sides, and see if lines drawn to the top of the "T" are the same length. There is much info … | |
Re: [QUOTE]This thread is duplicate from this one [url]http://www.daniweb.com/forums/thread317912.html[/url] see my answer there.[/QUOTE]And was copied to bytes.com. At some point you will have to write some of the code yourself. | |
Re: Line 27, string is never defined, and you should not use "string" as a variable. That name is already used by Python. [CODE] message_text = "Message Box" message.setText(message_text)[/CODE]At line 46, etc. use a variable to store the changes. [CODE] message = "attackatdawn" cap_str = message.upper() print message, message.upper()[/CODE][QUOTE]Line 49: Trying … | |
Re: [QUOTE]You can replace line 3 with line = lines.rstrip().split(',')[/QUOTE]Note that this will probably cause an error at l2.append(line[1]) because length will be too short. You should be testing for length anyway: [CODE]f = open('datagen.txt') for lines in f: line = lines.strip().split(',') if len(line) > 1: l1.append(line[0]) l2.append(line[1]) [/CODE] | |
Re: Check your post after posting. If it doesn't look right, hit the edit button and try again. Beat you TONYJV by that much. This is my first function in python and i need to get item quantity and price loops into the function Processorderitems. I took out the items loop … | |
Re: [QUOTE]It's what programming's all about We can't learn python for you, so show some effort.[/QUOTE] For any newbies, this is the never-ending question technique. The OP keeps posting questions (with no effort at all) until someone is worn down enough to write the code for them. I don't care enough … | |
Re: [QUOTE]The user enters a number and the program should output that amount of rows and colunmns.[/QUOTE]Your for() loop actually prints the same number of __rows__ as the number entered by the user. Instead, you want to use a counter to count each object when it is printed/displayed. According to your … | |
Re: Pypi is always a good place to start. I have not tried this wrapper though [URL]http://pypi.python.org/pypi/jaraco.mysql[/URL] | |
Re: I don't see "equip" declared anywhere so there is no way to tell what equip.delete() is trying to do, but there is too much code=too much wasted time, to sort through. Also, a dictionary container is your friend here. Pretty much all of the if statements can be replaced with … | |
Re: You can reverse the for loop and use a step of -1, or append the results to a list and reverse the list before printing. | |
Re: [QUOTE]i cant use this in debian lenny [/QUOTE]I don't understand why you can't use this. Also, you probably only want root access for the script, otherwise anyone can shut down your system. If you want to run it from a non-root user, then you or the program will also have … | |
Re: [CODE]This seems at odds with your analysis. Or am I missing something?[/CODE]Python uses a list to store small numbers as that is more effecient so all small numbers point to the same object in the list which is why you get a True for a=1. The "is" operator though is … | |
Re: You would do something along the lines of the following. Note that if you open the file using a program that does not encompass encoding, then you will see what appears to be some garbage letters. This in not the file's fault, but the lies with the program being used … | |
Re: bonuslist will always be the same as the saleval list bonuslist = saleval You add the bonus to the field named "bonus" but try to print "bonuslist" which you do not change. See if using a lists of lists, that is one sub_list for each [staff, sales, bonus] helps. Generally … | |
Re: [QUOTE]display the data using canvas[/QUOTE]Which GUI toolkit are you using? If it is Tkinter, begin [URL=http://effbot.org/tkinterbook/canvas.htm]at Effbot[/URL] for line drawing. Also, the polyline1 & 2 should be calculated by one function that receives the parameters and returns the number, and the same for distance1 & 2. [CODE]## pseudo-code example def … | |
Re: You probably should roll your own here, that is read one record, split on the comma's and test for length. If the length is too short, read another record, split, and append to the first, although there is probably a little more coding here since the "\r\n" is in the … | |
Re: Usually you should also strip the record first, as no data should be assumed to be 100% reliable. You may or may not want to convert to lower case as well. [CODE]for line in open('testconn.txt'): rec = line.strip() if rec.startswith('Domain') or rec.startswith('Referer'): print line [/CODE] | |
Re: Add a print statement so you know what is being compared, and hence if the append is correct or not. Also, you should first check that both lists are the same length. [CODE]h=[] for i in range(len(change2)): for j in range(len(atom)): print "comparing" atom[j], atom[i] if atom[j]==atom[i]: h.append("H") else: h.append("-") … | |
Re: You might want to post this in a more permanent place as well like [URL]pypi.python.org[/URL] or [URL=http://code.activestate.com/recipes/langs/python/]Activestate.[/URL] as they are also places that people look for code. | |
Re: Assuming MainProcess is a class, you probably want something along the lines of the following code. If that doesn't help, post back. [code]for item in proclist: MP = MainProcess(item,csvMap) p = Process(target=MP.run_something(), args=('XX',)) p.start() runlist.append(p) [/CODE] | |
Re: soft brian (es): "it doesn't run" isn't enough info, (and no one is going to waste their time trying to properly indent the code you posted so they can run it). Also, try a more descriptive title. There are people who won't even look at threads with titles like "Please … | |
Re: Add some swear words. That will make it mean. Also, add some print statements so you can see what the program is doing. And if you can not complete the problem, try it another way. Perhaps computing the mean by adding each element of the list to a total field, … | |
Re: Isn't SharpDevelop an IDE, or have they added a GUI as well? The short answer to your question is to use a toolkit that is not so obscure. There is wxFormBuilder and wxDesigner for the wx toolkit and VisualPython for starters; see also the "Python GUI Programming" and "Starting wxPython" … | |
Re: [QUOTE=Vibze;869732]Thanks for the replies but I get forbidden page everytime when i try to go to my address with additional variables in slashes. I assume there should be some .htaccess setting for the server to be able to divide the url into the "actual url" and the variables. More of … | |
Re: Eclipse has the fonts installed to print the encoding. The command line obviously does not. You can try to change the default font but that is dependent on which distro you are using as well as which terminal program (xterm is -fa font-name). | |
Re: Split on the "=" and the first "." or parse the string and pick out the digits. [CODE]s = ":enterprises.18489.1.2.1.5.1.10.0 = INTEGER: 1" t = s.split("=") v = t[0].split(".") to_replace=".".join(v[1:]) print to_replace [/CODE] | |
Re: You have to test for a length of 2 or greater, otherwise you get and index error on the [1:]s. [CODE] return matchPat(CH[1:], string[1:]) elif CH[1] == string[0] or matchPat(CH, string[1:]): [/CODE]Note also that line 10 matchPat(CH[1:], string) does not catch the return from the matchPat function so the "return … | |
Re: I would suggest a dictionary with the key pointing to a list, which would show up similar to your example D_dict = {"D1":[0, 0, 1, 0, 0, 1, 0, 0, 0 ], "D2":[0, 1, 0, 0, 0, 1, 1, 1, 0 ] } Come up with some code to read … | |
Re: [QUOTE]so please [B][U]bare[/U][/B] with me[/QUOTE]You must be a nudist. Please test your code before you post it here. [CODE]for file in [f for f in files if f.endswith(".html" or ".htm" or ".txt")]:[/CODE]So first, get the file names one at a time and print on the screen so you know you … | |
Re: Perhaps something along the lines of the following. Otherwise, you want to use 2 prompts, one for the number, and another for the word. Note that you can also use isdigit() to test for a number, but it doesn't really matter which one you use. [CODE]def check_input(low, high): prompt = … | |
Re: For unique descriptions, you would want to test the list also, only appending if that color is not already in the list, or use a set. Also, strip() both the description and the word before adding to the dictionary to get rid of spaces and newlines. Then you would use … | |
Re: [QUOTE]but I need to return the result of the ButtonRelease-1 to main[/QUOTE] I for one have no idea what this means as the URL referenced contains many examples. | |
Re: You should be able to use .configure(background=color) or whatever, but I have not tried it with menus [URL]http://pmw.sourceforge.net/doc/howtouse.html[/URL]. | |
Re: To debug code like this, you have to break it down into individual steps to know where the error lies. [CODE] for p in media.get_pixels(pic): x = (sum(range(media.get_red(p)))) print x ## ## with minimum/terse print statements, it becomes ctr = 0 for p in media.get_pixels(pic): if ctr < 5: ## … | |
Re: Unless I am missing something, look up the key from the first dictionary in the second dictionary. | |
Re: A good example of using a class is in [URL=http://hetland.org/writing/instant-python.html] this tutorial[/URL]. Note especially the use of "self" and the indentation. |
The End.