4,305 Posted Topics
Re: In case all those '>>>' look messy and confuse you ... [code=python]class Stuff: def __init__(self): self.a = 0.02 x = Stuff print(x) # __main__.Stuff print(Stuff) # __main__.Stuff y = Stuff() print(y) # <__main__.Stuff instance at 0x009FAE40> print(Stuff()) # <__main__.Stuff instance at 0x009FAE40> [/code]A little test print is an amazing tool! | |
![]() | Re: [QUOTE=sravan953;1027297]I tried py2exe, but it didn't work for wxPython[/QUOTE]News to me! I have used py2exe successfully with wxPython programs, many times! ![]() |
Re: You have used a class to group functions together. This is the most simple form of class encapsulation. They are all functions that belong together, so it makes sense. BTW, nice code that uses some features of Python3. | |
Re: This little test code works fine ... [code=python]shops = [ 'Windermere', 'York', 'Chester' ] for i, s in enumerate(shops): print(i, s) print('[InternetShortcut]\nURL=http://192.65.%s.95/BackO' % (i+1)) """my result --> (0, 'Windermere') [InternetShortcut] URL=http://192.65.1.95/BackO (1, 'York') [InternetShortcut] URL=http://192.65.2.95/BackO (2, 'Chester') [InternetShortcut] URL=http://192.65.3.95/BackO """ [/code]... and so does your code (removed first line since … | |
Re: Your problem stems from the fact that you never give index an updated value in the while loop. I would use the while loop this way ... [code=python]def get_odd_palindrome_at(word, index): num = 1 new_word = "" while True: if index + num > len(word) - 1: break if word[index - … | |
Re: Try this ... [code=python]import os maleDataSets = 0 femaleDataSets = 0 females = [] males = [] filePath = "Dataset/parameter feature vectors" for fname in os.listdir(filePath): data_str = open(fname).read() # returns index of first "female" find # returns -1 if not found index = data_str.find("female") if index != -1: females.append(index) … | |
Re: To say it in simple terms, the line [B]def __init__(self, master):[/B] is the class constructor and allows you to pass external variables like master (root) to the class. Remember, you used [B]Application(root)[/B] Since you inherited frame in line: [B]class Application(Frame):[/B] you use [B]Frame.__init__(self, master)[/B] which in turn makes the frame … | |
Re: There are very good open source C++ compilers and IDEs available. Start taking some of your simple Python code and try to make it work with C++. You will find that these two languages complement each other very well. I doubt that your high school goes much beyond very simple … | |
Re: I assume you are using Python3? When you are splitting the input string you still get strings, so each coefficients (a,b,c) has to be converted to a float before you apply it to your formula. | |
Re: Your py2exe code does not work on my computer (XP, Python254) ... [code=python]# Script to make exe from distutils.core import setup import py2exe setup( options = {'py2exe': {'bundle_files': 1}}, console = ['email.py'], zipfile = None, ) [/code] ... but this works ... [code=python]# Script to make exe from distutils.core import … | |
Re: If you only have one line than you can simply do this ... [code=python]line = '<Log LogID="633198520" LogLevel="Normal" Date="10/01/09 19:18" Type="Error" Source="Mentor" Text="Failed to process the request." />' # slice off first 5 and last 3 characters line = line[5:-3] # testing ... print line line = line.replace('" ', '"|') … | |
A small Windows Application to show you how to play a wave (.wav) sound file. I am using the C# IDE from SharpDevelop and the runtime dotnetfx 1.1 from Microsoft, both free downloads. This forms a small and fast student system to write and debug C# programs. From there you … | |
Re: Put the parts you want to move into a list and do this ... [code=python] parts = [top, middle, bottom, hat, tophat, eye, eye2, nose, mouth, mouth2, mouth3, mouth4, mouth5, button, button2, button3, leftarm, rightarm] for i in range(6): p = win.getMouse() c = top.getCenter() dx = p.getX() - c.getX() … | |
Re: More unicode info: [url]http://www.python.org/peps/pep-0263.html[/url] | |
Re: Since Employee is inherited by Calc it also inherits method get_details(). So use this method with the instance of Calc. You need to keep track of the instance with 'self' ... [code=python]class Employee(object): name = ' ' def get_details(self): self.name = input('Enter the employee name ') print("In super class-->", self.name) … | |
Re: Or you can process the input string ... [code=python]def main(): print('This is a program to average two exam scores') # Python3 returns a string s = input('Enter two scores separated by a comma: ') score1, score2 = s.split(',') average = (float(score1) + float(score2)) / 2.0 print('The average of the scores … | |
Re: Take a break and finish a can of tuna fish, it's brain food. | |
Re: You have to select one of the lists as reference, if they are not of the same length, use the longer list. Here is an example using the standard for loop and the simpler list comprehension ... [code=python]# check two lists for the difference list1 = [1, 2, 3, 4, … | |
Re: Hint, you may want to use string concatenation to form the solid line of asterisks. Once the string is formed you can use it for top and bottom. | |
Re: Clearing the display screen in console mode depends on the Operating System, that and the limited usefulness is why many multiplatform computer languages do not include it. Here is a Python version using module os ... [code=python]import os # works on windows nt (also xp and vista) or linux os.system(['clear','cls'][os.name … | |
Re: Just some obvious stuff: Lines 124 to 140 have lost their indentations as a code block. They belong to function computer_move(). [B]pieces[/B] is misspelled in line 172 You also need to do something about your globals (check case). squares should be square in line 76 You will also discover some … | |
Re: The function input() in Python3 replaces the old Python2 function raw_input() and returns a string,so you have to use int() to convert the string to an integer value ... [code=python]def main(): celsius = int( input("What is the temperature in celsius? ") ) fahrenheit = (9.0 / 5.0) * celsius + … | |
Re: Let's assume you have something like this ... [code=python]class Turn: def __init__(self, angle=10, position=0): self.angle = angle self.position = position def left(self): self.position += self.angle return (self.position) # creat an instance of the class turn = Turn() # now use the left() class method print turn.left() # 10 # again … | |
Re: Why even bother with cin >> s ... Is it April 1st? Or is this a submission to the Annals of Bad Programming? | |
Re: Let's assume you want something like this ... [code=python] x = 123.456 ipart, fpart = str(x).split('.') print ipart, fpart [/code] | |
Re: Well, for whatever it's worth, here is a hint ... [code=python]# exploring module cImage (a Tkinter wrapper) # from: # http://www.cs.luther.edu/~pythonworks/PythonContext/cImage.py import cImage # this actually creates a canvas ready for drawing win = cImage.ImageWin("My Canvas", 500, 400) # let's draw a red line on the canvas object # from … | |
Re: Do not post multiple threads! It is very bad manners! Your original thread is at: [url]http://www.daniweb.com/forums/thread231272.html[/url] | |
Re: You mean something like this ... [code=python]def letval(x): print(x) a = 77 letval(a) # you can just use print(a) [/code] | |
Re: Hint, I would go with a for loop since it can iterate over the function range(start, end, step). Our friend snippsat gave you a pretty good example. | |
Re: [QUOTE=akie2741;1018415]thx...how about beatifulsoup,how to install it?[/QUOTE] [url]http://www.crummy.com/software/BeautifulSoup/[/url] Somewhat simple minded, but you could try this and go from there ... [code=python]# retrieve the html code of a given website # and check for potential image sources # tested with Python 2.5.4 import urllib2 def extract(text, sub1, sub2): """ extract a … | |
Re: I wait till Google comes out with their OS. Does anyone have experience with [B]vLite[/B] that is supposed to remove the bloat from Vista and make it snappier? | |
Re: Take a look at something like this ... [code=python]# create a frame with a left side border # using overlapping frames import Tkinter as tk root = tk.Tk() root.title("left side border") frame1 = tk.Frame(root, bg='brown', width=400, height=200) #frame1.grid_propagate(0) frame1.grid() frame2 = tk.Frame(root, bg='yellow', width=390, height=200) frame2.place(x=10, y=0) root.mainloop() [/code] | |
Re: [QUOTE=nerdagent;1015019]I'm trying to put in some code that will delete a list from a list. For example if the user decides to delete the first names he would type in 'first' (w/out quotes). however after they input the name nothing prints out. Any suggestions? [CODE] person = ' ' first … | |
Python has some powerful functions, like the math expression evaluator eval(). You can embed this function and others in your Development C++ code. All you need to do, is to download and install the free Python Development Pak and feed the Python code in the form of a string to … | |
Re: To test if all buttons are 'on' you can simplify to this ... [code=python]b1 = 'on' b2 = 'on' b3 = 'on' b4 = 'on' if b1 == b2 == b3 == b4 == 'on': print 'all buttons on' [/code]Conversely you can do the same thing for 'off'. Functions any() … | |
Re: Just a reminder, for nested lists a plain copy like [B]a = mylist[:][/B] or [B]a = list(mylist)[/B] won't work ... [code=python]mylist = [1,2,[3,4]] a = mylist[:] a[2][0] = 'nest' print mylist # [1, 2, ['nest', 4]] ouch!!! print a # [1, 2, ['nest', 4]] [/code]Here you have to apply module … | |
Re: [B]import string[/B] and things like [B]new_line = string.split(line)[:2][/B] have been deprecated a few Python versions ago, as jlm699 pointed out, you now simply use: [B]new_line = line.split()[:2][/B] | |
Re: A common mistake for beginners, the __init__() constructor has two leading and two trailing __ In Python there is no need to use OOP classes, but you learn the benefits quickly as you write larger programs. | |
![]() | Re: [code=python]msg="To: "+to+"\nSubject: "+subject+"\n"+message [/code]There a are variable names [B]to[/B] and [B]subject[/B] that need some kind of string value. Those things do not come out of thin air! |
Re: Jackson William is correct, module pickle is used to save the object value and type. Another way to do it is to save the code as a module, then use the module namespace to retrieve the variable. | |
Re: Since your numeric data comes from a file you will have strings, so you might as well use concatenation ... [code=python]# the test data data = """\ 123 44 72 27""" fname = "numdata.txt" # write the test file fout = open(fname, "w") fout.write(data) fout.close() # read the test file … | |
Re: These little projects are fun. You can make minor adjustments to the OP's original code and make it work ... [code=python] lucky = raw_input("Enter an integer: ") for c in lucky: if c == "7": print lucky + " is lucky!" break else: print lucky + " is not lucky." … | |
Re: Take a look at: [url]http://www.daniweb.com/forums/showthread.php?p=1014588#post1014588[/url] | |
Re: Call the function this way: build_html('sports') | |
Re: Looks like the same thing. Something has to keep MS thinking that there is actually competition out there! | |
Re: The dictionary container is highly optimized (for search speed and memory usage) in Python, and is used internally by the interpreter. You can create an 'english_word: french_word' dictionary and easily swap it to a 'french_word: english_word' dictionary for speedy lookups in either language. However you have to make sure that … | |
Re: Just keep asking, we are all more than willing to help a sprouting Python talent. | |
Re: The installer would usually install the pyqt package in C:\Python25\Lib\site-packages\PyQt4 This is the directory where one would put the optional graphics dll. BTW, where did you find Qwt5.dll? I haven't had much luck downloading it. Notice that the package name is PyQt4, so this is the spelling you need to … | |
Re: I see you are using deamon threading, but be advised that the standard CPython uses GIL (Global Interpreter Lock) allowing only one thread of code to execute at any given time. That could slow things down depending what's in the endless loop. Try/except pairs are notoriously slow. Python3 (also Python26) … |
The End.