2,190 Posted Topics

Member Avatar for jone kim
Member Avatar for crazy99

Some info on what you are trying to do [Reading Files](http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm) [Lists and Dictionaries](http://hetland.org/writing/instant-python.html) or http://www.diveintopython.net/native_data_types/lists.html and http://www.diveintopython.net/native_data_types/index.html#odbchelper.dict See if this code helps get you started f = open('profiles.txt', 'r').readlines() for line in f: line = line.strip() print line if "," in line: line_as_list = line.split(',') if len(line_as_list) > 1: …

Member Avatar for crazy99
0
342
Member Avatar for sainitin

> Traceback (most recent call last): File "compundids.py", line 13, in<module> record = Entrez.read(handle) There is something wrong with the read. Does your input file have any empty records? Add a print statement to print "line" before the error to see which record is causing this.

Member Avatar for woooee
0
275
Member Avatar for JenniferT1980

> I want to either figure out how to open the individual python files when I click on a button That is too much code to go through, but you would include the "open the file" code in the call back function. ~~~ try: import Tkinter as tk ## Python …

Member Avatar for JenniferT1980
0
182
Member Avatar for paulzef

We don't have the code that creates "maze" so have no idea what kind of object it is, but you should access it the same way whatever the object. if maze[row-1,col] == 'O' or 'F': --> this doesn't make sense to me and will always be "True" if maze(row,col) == …

Member Avatar for TrustyTony
0
197
Member Avatar for jon92

[Dive Into Python](http://www.diveintopython.net/scripts_and_streams/command_line_arguments.html) has a good command line tutorial IMHO.

Member Avatar for woooee
1
116
Member Avatar for Programmer_Girl

When I run the code, it results in this error > File "./test_1.py", line 110, in <module> l,w=eval(input("Please enter length and width of room #"+str(x))) TypeError: eval() arg 1 must be a string or code object eval() is used to evaluate formulas or code so is not appropriate here and …

Member Avatar for Programmer_Girl
0
686
Member Avatar for gbonline

> the problem is when i click the vnc button, this app has own windows - for ask password and show messages like "unable to connect" - and this stay under the fullscreen main window. You can use focus_set, i.e self.parent.focus_set(), self.password_entry.focus_set(). Start by reading [this page](http://effbot.org/tkinterbook/tkinter-dialog-windows.htm)

Member Avatar for gbonline
0
265
Member Avatar for adrigreat14

Receive the variables as a tuple and then use each item as your variable. [code]def test_num_variables(*args): print "number of variables =", args, type(args), len(args) os = -1 if None in args: os=args.index(None) print "finding None =", os, args[os] else: print "None was not found" return ## assumes that the check …

Member Avatar for adrigreat14
0
281
Member Avatar for White Eagle

>So how would I replace "-" with the correctly guessed letter There are 3 containers here, the "secret word", the hangman list, and the letter quessed. You would iterate over the "secret word" and compare letters. If the letters match then replace the "-" at the same postion in the …

Member Avatar for woooee
0
187
Member Avatar for woooee

When clicking the "Edit" button on an existing post, you are presented with the post and just an "Edit Post" and "Cancel" button at the bottom, neither of which post the edited version. Is there a FAQ for the new methods? If not then there should be. Also posting a …

Member Avatar for TrustyTony
0
258
Member Avatar for braybray

If you want to use split (and how do you post code that is not indented, like the following. If we have to add 4 extra space to every freaking line of code that we post, I'm finding a new forum) test_line="Youngstown, OH[4110,8065]115436" # your way for item in test_line.split(): …

Member Avatar for woooee
0
169
Member Avatar for boiishuvo

Start by testing your functions. This is very basic stuff. So in the function "table", print tableString at the end. Also you should be getting a syntax error on this line if name = 'main': Try [one of the many tutorials](http://hetland.org/writing/instant-python.html) on the web. The correct way for "name = …

Member Avatar for woooee
0
342
Member Avatar for 4evrmrepylrning

[quote]I need to find the records that contain duplicate <id> tags.[/quote]Which duplicate records do you want to delete, the first or last? In any case, with a 3GB file you probably want to iterate over the file one record at a time instead of trying to read it into memory. …

Member Avatar for Gribouillis
0
277
Member Avatar for A_Dubbs

Run this code with some added print statements and see if it helps. [CODE]for i in range(n): y = input("Enter number: ") print "after input y =", y y = y + y print "after adding y =", y, "\n" [/CODE]

Member Avatar for B dawg
0
941
Member Avatar for Sunciti

Copied to preserve the code tags. [code]def program(List, Name, Detail): for entry in List: if entry[0] == Name: ## changed to add to the entry containing "Name" not ## entry[1] as it is [Detail, Counter] so would become ## [Detail, Counter, [Detail_2, Counter_2]] entry.append([Detail,Counter]) ## "Counter" has not been declared …

Member Avatar for misokolsky
0
8K
Member Avatar for QuietShot59

For future reference there isn't much response for someone who can solve there own problem with a few print statements. This will get you started but there are errors in your logic. [code]for x in Alpha: y = 25- count print "first x, y", x,y while x in I > …

Member Avatar for woooee
0
187
Member Avatar for Yoink

[code] if maxLength(num) > MAXLEN: MAXLEN = maxLength(num) MAXNUM = num print ("\n%d has the longest chain of %d\n") % (MAXNUM, MAXLEN) [/code] The maxLenth function does not process the number more that once because of the "return num" statement, so the largest number will always be at the end …

Member Avatar for TrustyTony
0
597
Member Avatar for aj9393

Usually import statements are at the beginning of the program, and you then call a function within the imported program. [code]import _level1 elif choice in ['go north', 'Go north', 'Go North', 'n', 'N', 'north', 'North']: print " " _level1.function_to_run() [/code]

Member Avatar for woooee
0
213
Member Avatar for petrovitch

That can be a permission problem. Make sure that user has access to program file and the directory it is in.

Member Avatar for woooee
0
71
Member Avatar for scott_liddle

[quote]i[I]'ve managed to read in the file, and store it as a dictionary,[/quote]Probably not in the way you think. Print the dictionary and see what it contains. The dictionary key is the respondant's number, not the question number so at best you can count how many questions the respondant voted …

Member Avatar for hughesadam_87
0
116
Member Avatar for fafa70

Use a class and instance variables. You can call separate functions within the class using multiprocessing and they will all have access to the instance variables.

Member Avatar for woooee
0
210
Member Avatar for welshly_2010

Use a list [code]some_dict={} for key in ["a", "b", "a", "c", "c"]: if key not in some_dict: some_dict[key]=[] some_dict[key].append(key) print some_dict [/code]

Member Avatar for TrustyTony
0
214
Member Avatar for puddlejumper406

Also, you should check that numbers were entered on input and ask the use to enter again if there was an error. The program now will error out if you try to eval an entry that is not a number.

Member Avatar for woooee
0
312
Member Avatar for suly

Start with the simple basics; print big_list and make sure it contains what you think it does and is in the form you expect to be in. You can also add a print statement after for item in big_list: to print the item, but it is basically the same thing.

Member Avatar for woooee
0
184
Member Avatar for welshly_2010

Print some of the details, like the date. [code] line_of_list = line.split() date_port = ' '.join(line_of_list[0:2]) ## month and day date_list = date_port.split(':') ## no ':' in date_port [/code]And has_key is deprecated so use "in" instead. [code]## if desc_ip.has_key(ip_address): if ip_address in desc_ip: [/code]

Member Avatar for Gribouillis
0
91
Member Avatar for dmv091

First, you use the button variable for 2 different things [code] button1=Button(win,Point(2.5,2.5),3,2,"Button 1") button1=1 [/code]It can't be both at the same time. Next, find a tutorial for the graphics module so you know how to spell the text widget, and how to add it to the window. Next, each of …

Member Avatar for woooee
0
468
Member Avatar for lfmconsummates

This should give you an idea. There is also a problem with get_code(). You should first test what you post as much as possible. [code]def decode(code_dict,message): coded_message = [] for ch in message: if ch in code_dict: coded_message.append(code_dict[ch]) else: coded_message.append(ch) print "".join(coded_message) decode({"t":"x", "b":"y"}, "the quick brown fox") [/code]

Member Avatar for lfmconsummates
0
187
Member Avatar for hughesadam_87

IMHO the only time to use the keyword "is" is when you want to test that 2 objects point to the same block of memory, otherwise you can get unexpected results. This is a simple example of equal returning a True and is returning a False for the same comparison. …

Member Avatar for Gribouillis
0
166
Member Avatar for fafa70

The only time you can do multiple things at once is when you use a tool for that, like multiprocessing or parallelpython, otherwise you have to do things one at a time.

Member Avatar for fafa70
0
4K
Member Avatar for aj9393

The else statement will execute for all input except 'n'. That includes upper case 'N'. You want something more along the lines of the following. Also, use a while statement to call the function multiple times. When level() calls itself you can reach the recursion limit. [code] choice = choice.lower() …

Member Avatar for woooee
0
364
Member Avatar for chopper25

There are two ways to do this. 1. Use a list of lists. The inner list contains the cut off grade and an int which is incremented each time a grade is found in each category. You can loop through the grades once and find the first grade in the …

Member Avatar for woooee
0
594
Member Avatar for hughesadam_87

.join() is more efficient than string concatenation, so I would expect to see at least one join(). Also, don't use "i", "l", or "O" in an interview. [code]for outer in range(1,13): print '\t'.join(str(outer*inner) for inner in range(1, 13)) [/code]

Member Avatar for hughesadam_87
0
121
Member Avatar for R.S.Chourasia
Member Avatar for crazy99

First, test that row1 < row2 and the same for columns. Also you should test for them being in the correct range. Then you can iterate using a for loop for rows and a sub-loop for columns and this code assumes that "board" is a list of lists. [code]def is_occupied(row1, …

Member Avatar for crazy99
0
373
Member Avatar for hondros

Replace this [CODE]def show(comp_board): print """_____________________________________________ |===|_0_|_1_|_2_|_3_|_4_|_5_|_6_|_7_|_8_|_9_| |_A_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|""" %(comp_board[0][0], comp_board[0][1], comp_board[0][2], comp_board[0][3], comp_board[0][4], comp_board[0][5], comp_board[0][6], comp_board[0][7], comp_board[0][8], comp_board[0][9]) print "|_B_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[1][0], comp_board[1][1], comp_board[1][2], comp_board[1][3], comp_board[1][4], comp_board[1][5], comp_board[1][6], comp_board[1][7], comp_board[1][8], comp_board[1][9]) print "|_C_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[2][0], comp_board[2][1], comp_board[2][2], comp_board[2][3], comp_board[2][4], comp_board[2][5], comp_board[2][6], comp_board[2][7], comp_board[2][8], comp_board[2][9]) print "|_D_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[3][0], comp_board[3][1], comp_board[3][2], comp_board[3][3], comp_board[3][4], comp_board[3][5], …

Member Avatar for woooee
0
2K
Member Avatar for layneb131

You can simplify this as follows (continue and sometimes break often signifies a better logic exists). [code]import random #i [I] think you wanted strings here #r = "rock" #p = "paper" #s = "scissors" #a list of the weapons weapons = ["rock", "paper", "scissors"] ## separate variables are not necessary …

Member Avatar for layneb131
0
197
Member Avatar for straylight

You have to know what you are coding before you can write the code. What solution are you trying to write. Just throwing code against the wall to see what sticks doesn't work. If you draw it out, it becomes somewhat clear. Hint: it has to do with the length …

Member Avatar for woooee
0
169
Member Avatar for jone kim

You did not state any error so there is no question to answer. In Python we generally use the "in" operator instead of iterating. Also, sets will allow you to get the difference between string2 and string1 which is what you want.[code]# Pseudo code list_2 = [] for ch in …

Member Avatar for TrustyTony
0
204
Member Avatar for minimee120

Key in "python first last middle name" in the Daniweb search box. You are one of many asking this question.

Member Avatar for minimee120
0
165
Member Avatar for apeiron27

Data length is data length and will be the same no matter where you split. If you read one record at a time instead of the entire file it should not be a problem. More info is necessary though. What code are you using and how big is the file. …

Member Avatar for woooee
0
98
Member Avatar for bebedjou

For starters you can almost always use a list or dictionary instead of many if/elif statements. Also, globals are not necessary for this problem and point to a lack of understanding. [code]## replace of of these if/elif with a list of lists """ if amount = 4: riskCode = 1 …

Member Avatar for woooee
0
2K
Member Avatar for paul.hahn

You have to return the list that stores the textvariables and pass it to the next function. Also, you should really be using a [url=http://www.diveintopython.net/object_oriented_framework/defining_classes.html]class structure[/url] for this. [code]from Tkinter import * from functools import partial data = [ ('a', 0, 'liters soda'), ('b', 0, 'liters beer'), ('c', 0, 'liters …

Member Avatar for paul.hahn
0
10K
Member Avatar for unigrad101

You don't test for distance becoming negative (which is also a "True" condition-only zero is False) and you want to count the number of steps. As it is now, "steps" will always be slightly greater than 1000 since you add steplen every time. Figure it out by printing where necessary. …

Member Avatar for slate
0
130
Member Avatar for roe1and

There isn't enough data to be exact on the extraction process, but you can use a dictionary to test for "100", "245", etc. and call a function based on the key. I have used a common function to extract the data. If this is possible on all data types then …

Member Avatar for woooee
0
300
Member Avatar for ohblahitsme

If you have 5 rooms shaped as a plus sign, with room #5 in the middle, you would create the relationships with a dictionary as follows. [code]def room_function(room_no): print "running function for %s" % (room_no) """ room #1=North clockwise so room #4=West and room #5=the middle rooms_dict is keyed on …

Member Avatar for woooee
0
170
Member Avatar for python-noob

You would substitute a record from a file in place of the raw_input and send it to the function named "change". [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutfiles.htm]Opening and reading files[/url].

Member Avatar for python-noob
0
429
Member Avatar for minimee120

You really only need to use the first and last space, but count can be used to find how many spaces to index. [code]fullname = "one two three four five" ct = fullname.count(' ') idx=0 idx_list=[] for ctr in range(ct): idx=fullname.find(" ", idx) idx_list.append(idx) idx += 1 print idx_list first=fullname[:idx_list[0]] …

Member Avatar for minimee120
0
247
Member Avatar for JOSED10S

Isn't "a boad" a place where you live (sorry couldn't pass that up). An easy to understand example follows. You will have to substitute the variable for the hard-wired ">", and come up with some decent code to input things, as well as "or print Invalid board! if the board …

Member Avatar for JOSED10S
0
201
Member Avatar for moroccanplaya

Vegaseat has a nice example in the "Python GUI Programming" sticky, but I refuse to be someone else's research assistant. If memory serves it is somewhere in the middle of the thread's pages.

Member Avatar for moroccanplaya
0
1K

The End.