2,190 Posted Topics

Member Avatar for [V]

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]

Member Avatar for woooee
0
238
Member Avatar for Gsx

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

Member Avatar for TrustyTony
0
156
Member Avatar for [V]

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

Member Avatar for TrustyTony
0
199
Member Avatar for Python Joe

[QUOTE=;][/QUOTE] Try replacing root.destroy with root.quit. Possibly the root window is destroyed but Tkinter is still running.

Member Avatar for Python Joe
0
499
Member Avatar for nighthawk10

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

Member Avatar for vegaseat
0
296
Member Avatar for Lardmeister

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

Member Avatar for vegaseat
0
187
Member Avatar for kuchi

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

Member Avatar for woooee
0
73
Member Avatar for jarograv

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

Member Avatar for woooee
0
303
Member Avatar for aplh_ucsc

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

Member Avatar for Gribouillis
-1
327
Member Avatar for karlamadeus

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

Member Avatar for griswolf
0
229
Member Avatar for Fo.katia

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

Member Avatar for vegaseat
0
409
Member Avatar for RewindPlay

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

Member Avatar for woooee
0
136
Member Avatar for ROTC89

[QUOTE=;][/QUOTE] There is a space between the "def" and the function name, so it is def __init__(self):

Member Avatar for ROTC89
0
3K
Member Avatar for novice20

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

Member Avatar for vegaseat
0
9K
Member Avatar for dare599z

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

Member Avatar for dare599z
0
2K
Member Avatar for Speleo

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

Member Avatar for predator78
0
273
Member Avatar for katscandybar

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 …

Member Avatar for woooee
0
155
Member Avatar for kannibalkiwi

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

Member Avatar for woooee
0
163
Member Avatar for Dude2714

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 …

Member Avatar for woooee
0
192
Member Avatar for koveras vehcna

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

Member Avatar for woooee
0
206
Member Avatar for python01

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

Member Avatar for python01
0
180
Member Avatar for e-papa

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

Member Avatar for e-papa
0
221
Member Avatar for srw0801

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

Member Avatar for srw0801
0
441
Member Avatar for Learn_Pyhton

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

Member Avatar for TrustyTony
0
154
Member Avatar for G_S

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

Member Avatar for G_S
0
115
Member Avatar for kiranbkrishna

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

Member Avatar for TrustyTony
0
370
Member Avatar for jarograv

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

Member Avatar for woooee
0
205
Member Avatar for gabb810

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

Member Avatar for vegaseat
0
219
Member Avatar for buster2209

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

Member Avatar for buster2209
0
4K
Member Avatar for bilik

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

Member Avatar for woooee
0
147
Member Avatar for ThePythonNoob

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 …

Member Avatar for lrh9
0
211
Member Avatar for TechnoDarrel
Member Avatar for e-papa

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

Member Avatar for e-papa
0
672
Member Avatar for e-papa

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

Member Avatar for e-papa
0
282
Member Avatar for shawntheking

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

Member Avatar for TrustyTony
-1
83
Member Avatar for e-papa

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

Member Avatar for e-papa
0
130
Member Avatar for banannamoofin

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

Member Avatar for woooee
0
2K
Member Avatar for dlazzeri

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

Member Avatar for dlazzeri
0
163
Member Avatar for levic22

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.

Member Avatar for woooee
0
87
Member Avatar for ThePythonNoob

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 …

Member Avatar for woooee
0
77
Member Avatar for diniboi

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

Member Avatar for diniboi
0
195
Member Avatar for jarograv

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

Member Avatar for TrustyTony
0
1K
Member Avatar for levic22

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 = {} ## …

Member Avatar for vegaseat
0
837
Member Avatar for jkrueger

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

Member Avatar for jkrueger
0
257
Member Avatar for WigglesMcMuffin

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

Member Avatar for WigglesMcMuffin
0
187
Member Avatar for Swift2

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

Member Avatar for Swift2
0
84
Member Avatar for e-papa

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

Member Avatar for e-papa
0
359
Member Avatar for Emred_Skye

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

Member Avatar for Emred_Skye
0
189
Member Avatar for Zaffron

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

Member Avatar for woooee
0
462
Member Avatar for woooee

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 …

Member Avatar for griswolf
0
191

The End.