4,305 Posted Topics
Re: The way your class is written the list 'fld' is global to all instances of the class. You need to write your class this way ... [code=python]class A: id = "" #fld = [] def __init__(self, id): self.fld = [] self.id = id [/code] | |
Re: Office Suite: Open Office (does everything MS Office does) Image Viewers: XnView or IrfanView (small and nimble) Programming Editor: ConText (robust, handles a number of languages) | |
Re: The wx.StaticBitmap() is pretty well static. To be able to clear the old image you best use a canvas to display your image ... [code=python]# show a JPEG image using a wx.PaintDC() canvas # allows you to clear any previous image on the canvas import wx class ImagePanel(wx.Panel): """ create … | |
Re: Both pygame and wxPython allow you to play media files. | |
Re: Different Operating Systems use different CR, Linux uses '\n' and Windows uses '\r\n' and the Mac uses '\r'. This might cause your problem. Take a hexeditor and look at your file. If you have a two byte CR you will have to replace accordingly. | |
Re: Try ... [code=python]names = [ "main", "secondary", "tertiary" ] for item in names: cmd = "__import __(%s)" % item eval( cmd ) [/code] | |
Re: Try ... [code=python] frame.SetSize((x, y)) # another way, wx.Frame has a ShowFullScreen method # strips all border decorations and buttons # (False restores original frame) myFrame.ShowFullScreen(True, style=wx.FULLSCREEN_ALL) [/code] | |
Re: One way ... [code=python]d = {'Jim': 19, 'Slim': 45, 'Peter': 23, 'Joe': 30, 'Mark': 27} q = ['Frank', 'Hank', 'Joe', 'Luke', 'Paul'] for key in d.keys(): if key in q: print key [/code] | |
Re: Not quite sure what you want, but maybe this will help ... [code=python]word = raw_input("Enter a word: ") for c in word: c = c.upper() print c, "=", ord(c) - 64 """ my output for instance --> A = 1 B = 2 S = 19 O = 15 L … | |
Re: You could use the pygame module ... [code=python]# display text in a given font # get the total text width import pygame as pg # initiate pygame pg.init() # color tuple(r,g,b) yellow = (255,255,0) # create a 480x80 window/frame screen = pg.display.set_mode((480, 80)) # create a surface (canvas) surface = … | |
Re: Depends a little on what applications you want to write. Tkinter may be all you ever need. Once things get more demanding you then can switch to wxPython, PyGTK or PyQT. Knowing Tkinter will make the learning curve of these other toolkits a little easier. | |
Re: Looks like Windows Vista screws you up. The above PyQt-Py2.5-gpl-4.4.2-1.exe installed perfectly fine on my Windows XP machine. I tested dangermini's pyqt code and it works without a hitch. Not quite sure why he has a problem? | |
Re: I would stick with the stable production release: [url]http://www.python.org/ftp/python/2.5.2/python-2.5.2.amd64.msi[/url] Python30 is still alpha and won't be stable until the fall of this year. I know it's tempting to play with the new features. | |
Re: [QUOTE=Dunganb;623322]Here was my solution to the problem: [code]word = 'cake' cakeList = [] mixedList = ["cake", 12, "cakecar", "cAKe", "orange", "apple", "1cake", "cake1"] for x in mixedList: if word in str(x).lower(): cakeList.append(x) print cakeList[/code] With the output: [ICODE]['cake', 'cakecar', 'cAKe', '1cake', 'cake1'][/ICODE] Each element in mixedList is searched for the … | |
Re: Just installed PMIDI-1.1.win32-py2.5.exe on my XP machine running under Python25 and it works just fine with the sample code given. | |
Re: Here is an example using PIL ... [code=python]# generate a true opaque watermark with the Python Image Library (PIL) # free download from: http://www.pythonware.com/products/pil/ from PIL import Image, ImageEnhance def reduce_opacity(im, opacity): """returns an image with reduced opacity""" assert opacity >= 0 and opacity <= 1 if im.mode != 'RGBA': … | |
Re: Here is one way to access key, value pairs sorted by key ... [code=python]stats = { "ECSE":45, "LCSI":37, "ECOM":20, "ABIT":6, "ACSM":12, "AEXH":2, "AEXP":9, "BULS":8, "APME":7, "BBMB":1, "EBCL":5, "EEEL":27, "LDES":4, "LMAT":31, "LPHY":22, "LPSC":41, "LUHU":15, "LUPS":11, "LUSS":10 } # create a list of (key, value) tuples kvt = [(k, v) for k, … | |
Re: Hey slate, nice code. You sure pulled a number of Python features out of the box. I am always amazed how many ways there are to solve a problem. Just don't stop learning. | |
Re: Turbo C? I didn't know anybody still used this old horse! Anyway, I found something in my archives and removed the dust! This reads a character file, you want to read a binary file. The end of file marker will be different. Well partner, it's a start! [PHP]/******************************* fgetc.c ******************************** … | |
Re: Unusual, but here is one way to do this ... [code=python]data = "Every man has a price. Every woman has a price?" # optional remove punctuation marks data = "".join(c for c in data if c not in '.,!?') my_list = data.split(None) pair_list = [] for ix, s in enumerate(my_list): … | |
Re: [QUOTE=zls11610;607995]what function can converte a real to string[/QUOTE]str() | |
Re: Shouldn't it be ... [code=python]if LawRecite == True: speaker.Speak(LOR1) speaker.Speak(LOR2) speaker.Speak(LOR3) #speaker.Speak(random.choice(LOR4)) else: speaker.Speak('Yes please what?') [/code] | |
Re: Simply put the nested loop into a function and use return to break out ... [code=python]def exit_nested_loop(): w = h = 100 # for testing for x in range(0, w): for y in range(0, h): print x, y stop = raw_input("Stop? y/n") if stop == "y": return exit_nested_loop() [/code]If you … | |
Re: Why do you give the same name to your class and your function? | |
Re: If your lists have other lists nested in them, then you need to use module copy and make a deepcopy. | |
Re: [QUOTE=Nichito;526044]hey!! since when are you a mod? congrats!!![/QUOTE]Hey JB, I want to congratulate you too! | |
Re: The closest thing I know to solve your problem is the Boo language. It uses pretty much Python syntax but compiles with the Microsoft.NET C# compiler. Take a look at: [url]http://www.daniweb.com/code/snippet429.html[/url] | |
Re: In Python you can set up a dictionary to mimic switch/case ... [code=python]def choose(s): return { '1' : lambda:"You inputted one.", '2' : lambda:"You inputted two.", '3' : lambda:"You inputted three." }[s]() var1 = raw_input("Input a number between one and three.") print choose(var1) [/code]Even in C the switch/case statement is … ![]() | |
Re: Look into Python module shelve. It works like a dictionary for your data and saves all updates automatically as long as it is open. | |
Re: Can you give us just a short subset of the .csv file? We are not allowed access to the page. This way we can help you. | |
Re: Your function betsort(integer_array) should look like this ... [code=python]def betsort(x): n = len(x) for k in range(n, 1, -1): flag = 0 for i in range(0, k-1): if x[i] > x[i+1]: swap(x, i, i+1) flag = 1 if flag == 0: break [/code] | |
Re: Python has a high speed module for this sort of thing, take a look at module difflib in the Python manual. Initially you would do a line by line compare and identify the lines that are different. If you need more help, ask the forum. | |
Re: Well JB, when you are the front runner you have to put up with the envy of others. | |
Re: Today Microsoft Chief Executive Steve Ballmer said Microsoft is growing impatient more than two months after the Redmond, Washington-based software behemoth made its unsolicited takeover offer for Yahoo. Yahoo Inc. has three weeks to accept Microsoft Corp.'s $31 per share cash-and-stock offer, or Microsoft will mount a proxy battle to … | |
Re: Very nice example of threading a1eio! Could you do all of us a favor and contribute that to the Python code snippets? It would be much appreciated! My appologies, but just a hint to stay in the Python code guidelines, in the snippet could you start your class with an … | |
Re: Actually, the next version of Python (3.0) will use '/' for floating point divisions and '//' for integer divisions. Pascal for instance has '/' for floating point divisions and 'div' for integer divisions since inception 30+ years ago. | |
Re: Hehe! When I grow up I would love to look like Albert Einstein. Even the real eggheads listened to him. | |
This was a comment from ee_programmer in reference to one of the Python code snippets. [code=python]""" I was expecting the first class instance to only have one dictionary entry {'person0': 0} rather than two dictionary entries. Similar expectation with second class instance. How do I create and assign value to … | |
Re: DrPython requires the wxPython GUI toolkit to be installed first, both should work under Ubuntu. Another nice IDE is UliPad from: [url]http://code.google.com/p/ulipad/[/url] Again this one requires wxPython installed. Should work under Ubuntu. | |
Re: You problems are very basic, function raw_input() returns a string, but in your if statement you are trying to compare it with an integer. That means choice == 1 needs to be choice == '1' and so on. Don't use a Python function name like 'list' as a variable name. … | |
Re: You simply do that within the program that needs the additional path information ... [code=python]# if you want to import a custom module that is not # normally on the PYTHONPATH let's say it is in directory my_directory import sys # put this line before you start importing the module … | |
Re: [url]http://docs.python.org/modindex.html[/url] | |
Re: You need to make this a GUI program ... [code=python]# bind mouse clicks using the Tkinter GUI toolkit # (usually included in your Python installation) import Tkinter as tk def change_color(event): btn1.config(fg='red') root = tk.Tk() btn1 = tk.Button(root, text='Click me with the right mouse button ...') btn1.pack() btn1.bind('<Button-3>', change_color) # … | |
Re: Try this ... [code=python]# open a file for appending fap = open("file1.txt", "a") n = 0 # append numbers 1 to 9 to the file while n < 9: n = n + 1 # or n += 1 fap.write(str(n)) fap.close() [/code] | |
Re: [QUOTE=cscgal;594281]I don't know what paper is?[/QUOTE]Paper is the stuff you can make paper airplanes with. | |
The End.