2,190 Posted Topics

Member Avatar for Teiji

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]

Member Avatar for TrustyTony
0
146
Member Avatar for VectorAKA

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]

Member Avatar for woooee
0
270
Member Avatar for AutoPython

This will never be true [CODE] if (curletter+key)>(25): if (curletter+key)<0: [/CODE]

Member Avatar for AutoPython
0
200
Member Avatar for Limiter

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 …

Member Avatar for Limiter
0
157
Member Avatar for pythonlearning

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]

Member Avatar for pythonlearning
0
145
Member Avatar for JasonQiao

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 …

Member Avatar for JasonQiao
0
213
Member Avatar for n3red

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 …

Member Avatar for KrazyKitsune
0
174
Member Avatar for blast

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

Member Avatar for woooee
0
650
Member Avatar for DragSkull

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

Member Avatar for ScottieF
0
153
Member Avatar for pixelss

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

Member Avatar for TrustyTony
0
110
Member Avatar for convoluted

[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

Member Avatar for convoluted
0
2K
Member Avatar for danholding
Member Avatar for mikeyj9009

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

Member Avatar for woooee
0
102
Member Avatar for lewashby

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

Member Avatar for woooee
0
6K
Member Avatar for iwanttolearnc

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 …

Member Avatar for woooee
0
99
Member Avatar for haojam

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

Member Avatar for woooee
0
249
Member Avatar for hbluthi

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 …

Member Avatar for hbluthi
0
116
Member Avatar for rahul8590

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

Member Avatar for TrustyTony
0
202
Member Avatar for evertron

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 …

Member Avatar for woooee
0
88
Member Avatar for KrazyKitsune

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

Member Avatar for KrazyKitsune
0
168
Member Avatar for evertron

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

Member Avatar for evertron
0
236
Member Avatar for jingo1126

Pypi is always a good place to start. I have not tried this wrapper though [URL]http://pypi.python.org/pypi/jaraco.mysql[/URL]

Member Avatar for Reverend Jim
0
109
Member Avatar for Thropian

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 …

Member Avatar for Thropian
0
4K
Member Avatar for tpkemme

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.

Member Avatar for TrustyTony
0
137
Member Avatar for ganeshredcobra

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

Member Avatar for Gribouillis
0
2K
Member Avatar for Roadphantom13

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

Member Avatar for forsakenedzero
0
5K
Member Avatar for G_S

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 …

Member Avatar for woooee
0
7K
Member Avatar for evertron

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 …

Member Avatar for woooee
0
112
Member Avatar for communitygirl90

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

Member Avatar for strider1066
0
161
Member Avatar for PaulStat

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 …

Member Avatar for d5e5
0
2K
Member Avatar for Ashena

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]

Member Avatar for TrustyTony
0
14K
Member Avatar for dustbunny000

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("-") …

Member Avatar for Gribouillis
0
127
Member Avatar for G-Do

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.

Member Avatar for woooee
2
1K
Member Avatar for jeffrey.pry

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]

Member Avatar for woooee
0
165
Member Avatar for softbrianes

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 …

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

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

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

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

Member Avatar for woooee
0
181
Member Avatar for Vibze

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

Member Avatar for Schol-R-LEA
0
2K
Member Avatar for gishi

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

Member Avatar for TrustyTony
0
370
Member Avatar for novice20

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]

Member Avatar for woooee
0
120
Member Avatar for snow56border

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 …

Member Avatar for TrustyTony
0
375
Member Avatar for udev

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 …

Member Avatar for udev
0
117
Member Avatar for roboguy

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

Member Avatar for TrustyTony
0
259
Member Avatar for kannibalkiwi

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

Member Avatar for kannibalkiwi
0
97
Member Avatar for mandoza671

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 …

Member Avatar for mandoza671
0
158
Member Avatar for OlyDLG

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

Member Avatar for OlyDLG
0
319
Member Avatar for python_user

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

Member Avatar for woooee
0
63
Member Avatar for c2q

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

Member Avatar for woooee
0
178
Member Avatar for Ashena

Unless I am missing something, look up the key from the first dictionary in the second dictionary.

Member Avatar for Ashena
0
107
Member Avatar for recyan

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.

Member Avatar for recyan
0
2K

The End.