4,305 Posted Topics
Re: I am a little confused here. What are your resizing, the frame, the panel, the image? I changed your code so I could see the meat and used it with a larger image ... [code=python]import wx class MyFrame(wx.Frame): def __init__(self, parent=None, id=-1, title=None): wx.Frame.__init__(self, parent, id) self.panel_1 = wx.Panel(self, -1) … | |
Re: One of the more simple ways to do this is to use Python module HTMLParser ... [code=python]# extract text from HTML code of a web site import urllib2 import HTMLParser import cStringIO class HTML2Text(HTMLParser.HTMLParser): """ extract text from HTML code """ def __init__(self): HTMLParser.HTMLParser.__init__(self) self.output = cStringIO.StringIO() def get_text(self): """get … | |
Re: The function extend() adds the contents of another list to your list ... [code=python]listA = [1, 2, 3] listB = [4, 5, 6] # make a simple non-alias copy listC = listA[:] listA.append(listB) print listA # [1, 2, 3, [4, 5, 6]] listC.extend(listB) print listC # [1, 2, 3, 4, … | |
Re: When you send a mutable object like a list to a function as an argument, a pointer to the object is established (allows the objects to be mutable). Inside the function you have created a simple alias copy of the list, that still has the same pointer reference. With a … | |
Re: My suggestion would be to use the newer string functions and to add some comments ... [code]file = open("Test.txt", "r") text = file.read() file.close() word_list = text.lower().split(None) word_freq = {} for word in word_list: word_freq[word] = word_freq.get(word, 0) + 1 keys = sorted(word_freq.keys()) for word in keys: print "%-10s %d" … | |
Re: If your module is in folder c:\Python25\myFolder then you can tell Python to look there by appending PYTHONPATH ... [code=python]# appends to PYTHONPATH the location of your custom module folder # use this in the beginning of your program import sys sys.path.append(r"c:\Python25\myFolder") [/code]To see the folders where Python normally looks … | |
Re: Replace del lines[0:4] with lines = lines[4:] | |
Re: This might just help you ... [code=python]import wx class MyFrame(wx.Frame): def __init__(self,parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(300, 200)) toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER) # image file is in the same folder as the source code # otherwise give a full path name toolbar.AddSimpleTool(1, wx.Image('quit.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'quit', … | |
Re: My suggestion, use code tags around your code and stop using livewires, it's an old module and really not Python ... [code=python]x = input("Enter an integer number: ") y = 1234 n = 0 while x <> y: print "need", y, "you entered", x # limit a possible endless loop … | |
Re: [QUOTE=MitkOK;589570]I've just started learning Python :icon_cool:[/QUOTE]Welcome to the DaniWeb Python community, looks like you are doing great. | |
Re: Pardon my curiosity, but what C++/Python package are you using? | |
Re: Remember, function calls are expensive in Python (and some other laguages), so keep them to a minimum within the loop. | |
Re: If searchSpace[0] is an instance of class TData, then what would searchSpace[0].ac be? | |
Re: I have used py2exe with PIL programs successfully with Windows XP. However the same thing on Windows Vista scews up royally. | |
Re: Anything the cocktail girl brings me, be it a ... Manhattan, martini, Gibson, gimlet, old-fashioned, champagne, sidecar, horse's neck, Margarita, Bronx, pink lady, whisky sour, black Russian, white Russian, orange blossom, piña colada, mai tai, mimosa, Rob Roy, Sazerac, blue blazer, old Hickory, Vieux Carré, green opal, jitters, Daiquiri, Bloody … | |
Re: b04e3ian, please use 4 spaces per indentation and try not to exceed 72 characters per code line, it will make your code much more readable for all of us. Good luck with your game and welcome to DaniWeb. | |
I am keeping these to 100 pixel height thumbs so the JPEGs range between 5 and 15k (trying to safe Dani some disk space). You give me an educated guess what plane it is. I will (or you should) acknowledge the first correct guess. | |
Re: You may want to explain to the rest of us what IDEAL is. | |
Re: I simply get 1 I would also avoid using object as a variable name since it is a built in term for the basic Python object. | |
Re: If I would have to write an office suite to compete with Microsoft's Office, I would use Java, as has been successfully done with "Open Office". For projects that are less gigantic, and I need to develop quickly, I would use Python. | |
Re: In line 11 of your code you still go back to the originating function, that's called recursion. You should not do that! | |
Re: It's got to be the way your data file has been written. Try this ... [code=python]str1 = """\ 88 10112213 33332332 22011220 23110122 21231102 12222321 32131132 10023232 """ # save your data file fout = open('slink.txt', 'w') fout.write(str1) fout.close() f = open('slink.txt', 'r') rows = int(f.read(1)) cols = int(f.read(1)) f.read(1) … | |
Re: If you use Windows OS, Pyscripter has a nice debugger that I use a lot. | |
Re: Your problem is that book.items() gives you a key, value pair where value is most likely a tuple (year, roles). You have to edit your function like this ... [code=python]def saveBook(book): store = open(filename, 'w') for name, val in book.items(): year, roles = val store.write(name + '\n') store.write(year + '\n') … | |
Re: Looks like your problem is in line 7, you are using a list as default argument. The addresses of a function's default arguments get set at compile time. When a mutable object like a list is used as a default argument it will have this fixed address, adding more elements … | |
Re: So lightning strikes and you count off let's say ten seconds before you hear the thunder. Sound travels at 1100 ft/second, so the distance will by 10 times 1100ft. | |
Re: I think you need to give us a bit more detail. | |
Re: I saw one of his last concerts in May 1977 at the University of Michigan. He was old and puffy looking from all the steroids, but his singing had not suffered. He was only able to do half a show. Despite all of this the show was dynamite. His final … | |
Re: I am discussing that in one of my Python code snippets, take a look at: [url]http://www.daniweb.com/code/snippet326.html[/url] There is one caveat, Peter has not updated his module for a while, and you need the MS speech engine. | |
Re: Give VPython a try, a free 3D modeling/simulating package ...[code=python]# a rotating cube using vpython from http://vpython.org # also known as visual python import visual as vs # set up the frame vs.scene.width = 500 vs.scene.height = 500 vs.scene.center = (0,0.5,0) vs.scene.title = "rotating cube" cube = vs.box(pos=(0,0.5,0), axis=(1,1,1), length=1.2, … | |
Re: You can find all the information on this popular simulation system at: [url]http://www.alcyone.com/software/cage/[/url] | |
Re: Look at the code in: [url]http://www.daniweb.com/forums/post570512-4.html[/url] ... and you will figure it out. | |
Re: I would recomment to always use the namespace of a module. It makes your code much easier to understand. Here is the module ... [code=python]# a simple module save as test.py def printA(): try: print a except NameError: print 'variable undefined' # test the module as such if __name__ == … | |
Re: If you use frame as a parent you can do it easily ... [code=python]# using frame as the parent you can access its arguments # (does not work with root itself) import Tkinter as tk root = tk.Tk() frame = tk.Frame(width=500) # test frame 'dictionary' print frame['width'] # 500 root.mainloop() … | |
Re: [QUOTE=sneekula;566789]Spending time with my family and my GF Cooking Walking[/QUOTE]I always thought you were some kind of car buff. What happened? | |
Re: Here I done it! I wasted a perfectly good hour playing air hockey and enjoyed every minute of it! | |
Re: When you swap the key:value pairs you can get value to key collisions since keys have to be unique. The standard way is to but collisions into a list ... [code=python]# invert a dictionary and take care of value to key collisions def invert_dict(d): inv = {} for k, v … | |
Re: Rewrite your code this way ... [code=python]def histogram(s): d={} for c in s: d[c] = d.get(c, 0) + 1 return d h=histogram('brontosaurus') print h """ my result --> {'a': 1, 'b': 1, 'o': 2, 'n': 1, 's': 2, 'r': 2, 'u': 2, 't': 1} """ [/code]To better understand what is … | |
Re: There is a Python snippet telling you how to work with py2exe right here on DaniWeb: [url]http://www.daniweb.com/code/snippet499.html[/url] | |
Re: Since EnderX holds the view of a small but vocal minority, maybe he/she should explain his/her reasoning. | |
Re: If your data file is created from a list of lists, then you you need to save(dump) and load it as a complete object using Python module pickle. If your data file is just a text file of lines that look like lists, then you have to do some processing … | |
Re: First of all, let me welcome you to the DaniWeb Python forum! In your code you are almost there, but you can only concatenate strings ... [code=python]import datetime as dt # US format month/day/year #dateStr1 = '7/14/2006' #dateStr2 = '5/1/2007' mm1 = '01' # need to be strings dd1 = … | |
Re: I understand that the Martian pilot they recovered from the last crashed UFO is on display in Area 51, and actually is a female. | |
Re: You are on the right track. Read your tutorial, do the code samples, and try to solve the problems. Python, being an interpreter, makes it easy to quickly test the code you write. As you get a little more experienced change the code and see how it behaves. | |
Re: [QUOTE=Mahen]I completely agree with U, I even have two free compilers on my computer, LccWin32 & DevCpp but the problems is that they contain too much bugs, and working on them does not tell us where the bug is comming from, the compiler or the code. :cool:[/QUOTE] Dev-C++ works just … | |
Re: Try it this way ... [code=python]# recommended Python style is to start # class names with an upper case letter # function names with a lower case letter class TestClass(object): def show(self, data=None): print data def funk(data): instance.show(data) def main(): #instance = TestClass() funk("hello") # create an instance of the … | |
Re: Move your while loop for more data into function main(). Once you return from validated_input() it will pop out of the loop there. | |
Re: One approach would be to group the lines in the contacts string into a list of [first, last, number] lists ... [code=python]# assume your contacts string looks like this after file read contacts = """\ Adam Adler 12345 Bart Johnson 23456 Carl Lark 34567 Don Herbst 45678 """ # remove … |
The End.