2,190 Posted Topics
Re: The pointer is positioned at the end of the file so nothing is read. [code]import tempfile if __name__ == '__main__': test = tempfile.NamedTemporaryFile() test.write('asdfsadfsadfsadfasdfasdfsadfsdfsadfsadfs') test.seek(0) ## offset=0 --> beginning of file print "\n test read", test.read() print test.name [/code] | |
Re: [quote]whats the best way to just show a blank if no number is entered[/quote]If no number is entered, the length would be zero. [code]import easygui def check_numbers(number_entered, ctr): #Set list for networks networks = [ ["083", "3 Ireland"], ["085", "Meteor"], \ ["086", "02"], ["087", "Vodafone"] ] if len(number_entered): # some … | |
Re: [QUOTE=;][/QUOTE] From the docs [url]http://docs.python.org/library/subprocess.html[/url] [quote]Popen.wait() Wait for child process to terminate. Set and return returncode attribute. Warning This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. … | |
Re: [QUOTE=;][/QUOTE] Try replacing root.destroy with root.quit. Possibly the root window is destroyed but Tkinter is still running. | |
Re: [QUOTE=;][/QUOTE] [quote]The program has to take as input a .csv file and manipulate it and plot it accordingly.[/QUOTE]The Python wiki contains a section on [url=http://wiki.python.org/moin/NumericAndScientific/Plotting]plotting tools[/url]. Other than that your question is impossible to answer as we have no idea if it is a 2D or 3D, bar or graph, … | |
Re: [QUOTE=;][/QUOTE] Lists are passed by reference, so the tuple contains the memory address of the list, not the list itself, and that doesn't change. Both of these statements will fail [code]my_tuple = (1, 2, 3, [4, 5, 6]) new_list = [4, 5, 6] my_tuple[3] = new_list ## new memory address … | |
Re: [QUOTE=;][/QUOTE] The obvious response is to find "TYPE=" in the string, but that is so obvious that I must not understand exactly what you are asking. | |
Re: [QUOTE=;][/QUOTE] Although we don't know the format of the file, this is probably a never-ending loop as you are iterating over, and appending to, the same list. [code]for data in citynames: citynames.append(data[0])[/code]Run this snippit as it limits the list to a length of 100, instead of an infinite loop. [CODE]x … | |
Re: [quote]numglobals.frame_19.Show()[/quote]It appears that you haven't defined numglobals.frame_19. Check the variable name and also see if any of the others work. Note also that numglobals has not been passed to the function so the function may not be aware of it. | |
Re: [QUOTE=;][/QUOTE] First, there are two types of variables in classes, [URL=http://diveintopython.org/object_oriented_framework/class_attributes.html]attributes and instance variables[/url]. I think you want instance variables, so you can have more than one human for example, with separate values for each one. [code]class Human: def __init__(self): self.isplayer = False self.nhealth = 20.0 def health_add_one(self): self.nhealth += … | |
Re: Define the math first. The two circles are colliding if the distance between the centers is less than or equal to the (radius of circle one + the radius of circle two. Dry it out on paper first). | |
Re: [QUOTE=;][/QUOTE] You can just code a while() instead of the if() and while(). [code]hours = 0 while int(hours) > 60 or int(hours) < 1: hours=raw_input('Hours worked:') # # the following is poor syle; use if statement instead #if hours == 'DONE': #break #else # if hours.upper() != 'DONE': hwage = … | |
Re: [QUOTE=;][/QUOTE] There is a space between the "def" and the function name, so it is def __init__(self): | |
Re: [QUOTE]Is python int by default a 32 bit- signed int?[/QUOTE]Python uses the system's, so 32 bit on a 32bit system and 64 bit on a 64 bit system. Note that there is no difference in length between a signed integer and an unsigned integer. A signed integer just uses one … | |
Re: [QUOTE=;][/QUOTE] [quote]I try to remove the wx.GridSizer and replace it with another one.[/quote]The [url=http://www.wxpython.org/docs/api/wx.Sizer-class.html]wxpython docs[/url] list Detach, Remove, and RemoveSizer for a Sizer widger (GridSizer is a subclass of Sizer). So it would be something like (sorry, 186 lines of code is more than I want to wade through, though … | |
Re: [QUOTE=;][/QUOTE] Are you using Python 2.x or Python 3.X as one uses raw_input and the other uses input?[code]# int converts input to an integer so delete it ed = int(input('Would you like to encrypt or decrypt a message? ')) # if ed == 'encrypt' or 'Encrypt' or 'ENCRYPT': # should … | |
Re: If it's not a tie, this will return None if the first test fails. [CODE]for row in WAYS_TO_WIN: if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY: winner = board[row[0]] return winner if EMPTY not in board: return TIE return None # #---------------------------------------------------- if EMPTY not in board: ## only test … | |
Re: [QUOTE=;][/QUOTE] This is called "non-sense code" (not my word). It is more straight forward to use [code] if not reply.isdigit() : continue # Convert it to number number = int( reply ) # # if reply.isdigit() : # rest of instructions # Convert it to number number = int( reply … | |
Re: First, what SQL db are you using. Assuming SQLite, the following code works. Note that "Urgent Help" does not stimulate us since it usually means that you have waited until the last minute to do some homework. I am guessing that the problem is that you don't close the db … | |
Re: [QUOTE=;][/QUOTE] To start you off (untested): [code]def find_longest_word(trigger_sentence): """ 2. = find the longest word in the trigger sentence """ ## container for the longest word or words longest_list = [0] ## assumes no punctuation for word in trigger_sentence.split(): ## new word found so re-initialize the list if len(word) > … | |
Re: [QUOTE=;][/QUOTE] You can try either [URL=http://pyserial.sourceforge.net/]PySerial[/url] or [url=http://pyusb.sourceforge.net/docs/1.0/tutorial.html]PyUSB[/url]. | |
Re: [QUOTE=;][/QUOTE] To associate name and score you would use a list, tuple or dictionary of pairs, so as to keep them together. The name and score that you print do not necessarily go together. The Python sorting HowTo is [url=http://wiki.python.org/moin/HowTo/Sorting/]here[/url]. [code]import operator name_score = [] ## example data name = … | |
Re: [QUOTE=;][/QUOTE] The first thing you have to do is to store the points (usually in a list). Then calculate m. Σxiyi = sum of the xy products, and Σxi^2 = sum of the x's squared. There are many pages explaining regression lines on the web. If you aren't sure how … | |
Re: [QUOTE=;][/QUOTE] You would have to read each record ("lines" is a word processing term and many types of files do not have lines) until you reach the first "{". Then store or print the records until the next "}". Then switch off an indicator. Note that you might want to … | |
Re: [QUOTE=;][/QUOTE] It depends on which version of Python you are using as x could be a string or an integer so print the type(). [code] x = input('write something: ') print type(x) assert("1"==1), "Not equal" [/code]And don't use tabs to indent as the tab can be set to anything on … | |
Re: [QUOTE=;][/QUOTE] [code]frame_top=Frame(root,name='frame_top') frame_top.pack() name_label = Label ( frame_top,text='Name' ) name_label.grid(row = 1, column =0) [/code]You can not use both grid() and pack() in the same program. See the Warning [url=http://effbot.org/tkinterbook/grid.htm]here[/url], and then pick one or the other. | |
Re: [QUOTE=;][/QUOTE] Note that the variables in the original post are set to the value of lowercase "o" but the principle is the same. Another example of why not to use it as a single letter name. You could also use a list of 81 elements, ignoring the [0] element, although … | |
Re: [QUOTE=;][/QUOTE] [quote]i don't understand [/quote]That's because you don't know what the program is doing, so add some print statements, for example:[code]def get_k(data): print "get_k data", data for k in data: print "testing", k return k [/CODE]Also, both functions are the same so eliminate one of them, and it is not … | |
Re: [QUOTE=;][/QUOTE] The answer depends on what OS you are running, but hopefully all OS's won't let you determine anything for any other user, especially root, except if you are already root. So the only way you can determine if there is a different user is if you run the program … | |
Re: [QUOTE=;][/QUOTE] I would use multiprocessing. See Doug Hellmann's "Signaling between processes with event objects" [URL=http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-2.html]here[/URL]. In multiprocessing, you can also use a dictionary or list to store a value. Some examples, plus see "shared namespaces" [URL=http://www.doughellmann.com/PyMOTW/multiprocessing/communication.html#shared-namespaces]here[/URL]. Start with running two processes and then add in the variable. | |
Re: Line 41 = Line 32 in your code. It is an infinite loop; [CODE]while channels < prevchannels: randint(0,15) [/CODE] Also the variable "channels" has not been defined for the findchannel scope. [Code]def findchannel(state): if state==1: prevchannels=channels <--- channels not yet defined [/CODE]I would suggest that you add a test function … | |
Re: [QUOTE=;][/QUOTE] Please mark this thread "Solved". | |
Re: [QUOTE=;][/QUOTE] I thought you wanted a goose (but it won't come from me). Why do you call "picker" twice? [CODE]def run(): """this function runs the program""" word = picker(picker(combine)) [/CODE] Also, you can reach the maximum recursion level since run() calls decision() which calls run(), etc. And there is more … | |
Re: [QUOTE=;][/QUOTE] You should probably ask this on the [URL=http://www.qtforum.org/forum/3/qt-designer.html]Qt forum[/URL] as this doesn't have anything to do with Python. I would suspect, but don't have any idea, that it has to do with the 2 separate installations for the two versions of Python. | |
Re: [QUOTE]recreate the script from class[/QUOTE] We don't have the script from class and don't do your homework for you. [QUOTE]Anyone up for this coding challenge? I'm interested to see who can get the code the fastest[/QUOTE]That's just calling us stupid. | |
Re: [QUOTE=;][/QUOTE] Qt also has to be installed as PyQt is just a wrapper between the two. [quote]import sipconfigure no module named sipconfigure[/quote] Sip should be included in Qt4. This should be the [url=http://qt.nokia.com/downloads/downloads#lgpl]download[/url], but am not sure since on Linux we just ask the repository to install it. | |
Re: [QUOTE=;][/QUOTE] You can easily convert a date to a datetime object. I would suggest a function which you pass the date, shelf life, and date entered by the user. There are timedelta examples in the [URL=http://docs.python.org/library/datetime.html]docs[/URL]. Also, datetime objects can be subtracted from each other and can be compared (datetime_1 … | |
Re: [QUOTE=;][/QUOTE] You have to use the absolute or full path. [CODE]##-------------------------------------------------------------------- def get_files(parent): files_list = os.listdir(parent) for a in files_list: full_name = os.path.join( parent, a ) if os.path.isdir(full_name): get_files(full_name) else: print full_name get_files("/home") [/CODE] | |
Re: I would use 2 comboboxes and 2 buttons. Of course each of the buttons will be bound to different functions. Post some code for additional help. | |
Re: You do not have an instance of the class "inv" so the program will not run as is. Especially, see the "To create a Point" part [URL=http://greenteapress.com/thinkpython/html/book016.html]here[/URL], which explains instantiation. You would pickle.dump and pickle.load the list "inventory". I would strongly suggest that you print it as you go along … | |
Re: [QUOTE=;][/QUOTE] What is the purpose of this code? If it has a legitimate purpose then I will respond, but if you are just yanking our chain, then please don't abuse the volunteers' time. A hint: divide the length by 2 and print the first half and second half, although you … | |
Re: [QUOTE=;][/QUOTE] You can use a tuple to replace several parts of the code in fact, but first this: [CODE]#ycoord=y ## replace with the following ycoord = int(y) #if ycoord>8: ## replace with the following if 1 <= ycoord <= 8: ## code goes here xcoord=xcoord.lower() x_choices = ('a', 'b', 'c', … | |
Re: I would suggest you start with [URL=http://effbot.org/tkinterbook/grid.htm]grid[/URL] which allows you to specify a row and column. This is a tic-tac-toe program that uses a 3X3 grid to place the buttons. [CODE]rom Tkinter import * from functools import partial class TicTacToe: def __init__(self, top): self.top = top self.button_dic = {} ## … | |
Re: [QUOTE=;][/QUOTE] Use random.shuffle instead. [CODE]random.shuffle(endings) for ctr, beginning in enumerate(beginnings): ## assumes there are at least as many endings as beginnings f3.write('%s %s\n' % (beginning, endings[ctr]) [/CODE] | |
Re: [QUOTE=;][/QUOTE] [QUOTE]File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 6, in <module> File "/myHomeDirectory/NetBeansProjects/creatureLists/src/Creatures.py", line 9, in Creature NameError: name 'false' is not defined[/QUOTE] This says that line 6 in "Creatures.py" is calling line 9 = false not defined. Nothing like that in the code you posted. Are you running from another directory that also … | |
Re: [QUOTE=;][/QUOTE] There is no way to get it to match anything other than the entire string, so there is another problem with the program logic, i.e. you are telling it something different. [CODE]itemname = ["email to", "password", "user"] for w in ("Password","User","Server", "to", "email", "Email to"): if w.lower() in itemname: … | |
Re: [QUOTE=;][/QUOTE] There are two online book that I like, [URL]http://www.greenteapress.com/thinkpython/html/index.html[/URL] and [URL]http://diveintopython.org/toc/index.html[/URL]. There are others at the Python Wiki [URL]http://wiki.python.org/moin/IntroductoryBooks[/URL]. | |
Re: [QUOTE=;][/QUOTE] Some print statements should help: [CODE]for i in number[1]: print "test i =", i if int(i) >= 5: print " deleting", number[0] del number[0] print " deleting", number[0] del number[0] print " deleting", number[0] del number[0] print " after, number =", number, "len(number) =", len(number) [/CODE]And __definitely__ test this … | |
Re: [quote], it gives me memory locations for each instantiation[/quote]That is true as that is what you are storing in the list. First, this statement, random.randint(1,3) == a should either yield a True or False (as it is an assert that one side of equation equals the other), or an error … | |
Giudo Van Helsing today announced that the use of a main() function in Python will now generate an error. After stating that "Python is not C" he went on to say that for backward compatibility the programmer can import a module for programs already using main(). "...and since the people … |
The End.