4,305 Posted Topics

Member Avatar for twoshots

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!

Member Avatar for twoshots
0
122
Member Avatar for sravan953

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

Member Avatar for sravan953
0
1K
Member Avatar for AutoPython

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.

Member Avatar for AutoPython
0
216
Member Avatar for dads

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 …

Member Avatar for slate
0
113
Member Avatar for pyprog

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

Member Avatar for vegaseat
0
903
Member Avatar for bol0gna

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

Member Avatar for vegaseat
0
198
Member Avatar for lewashby

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 …

Member Avatar for vegaseat
0
199
Member Avatar for nevets04

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 …

Member Avatar for vegaseat
0
215
Member Avatar for SoulMazer
Member Avatar for simpatar

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.

Member Avatar for vegaseat
0
82
Member Avatar for gsingh2011

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 …

Member Avatar for snippsat
0
663
Member Avatar for rmsagar

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('" ', '"|') …

Member Avatar for rmsagar
0
119
Member Avatar for vegaseat

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 …

Member Avatar for ashley dane
0
1K
Member Avatar for kat12

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

Member Avatar for vegaseat
0
1K
Member Avatar for nicsmr
Member Avatar for vegaseat
0
129
Member Avatar for python.noob

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

Member Avatar for AutoPython
0
220
Member Avatar for simpatar

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 …

Member Avatar for The_Kernel
0
167
Member Avatar for AndreRet
Member Avatar for Ene Uran

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

Member Avatar for Gribouillis
0
2K
Member Avatar for saikeraku

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.

Member Avatar for marecute
-1
110
Member Avatar for AutoPython

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 …

Member Avatar for bumsfeld
0
171
Member Avatar for xaeubanks

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 …

Member Avatar for bumsfeld
0
136
Member Avatar for simpatar

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

Member Avatar for bumsfeld
0
270
Member Avatar for srk619

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 …

Member Avatar for vegaseat
0
85
Member Avatar for imon

Why even bother with cin >> s ... Is it April 1st? Or is this a submission to the Annals of Bad Programming?

Member Avatar for giegiey
0
455
Member Avatar for Kruptein

Let's assume you want something like this ... [code=python] x = 123.456 ipart, fpart = str(x).split('.') print ipart, fpart [/code]

Member Avatar for jlm699
0
262
Member Avatar for kenmeck03

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 …

Member Avatar for vegaseat
0
100
Member Avatar for lewashby

Do not post multiple threads! It is very bad manners! Your original thread is at: [url]http://www.daniweb.com/forums/thread231272.html[/url]

Member Avatar for vegaseat
0
120
Member Avatar for Kruptein

You mean something like this ... [code=python]def letval(x): print(x) a = 77 letval(a) # you can just use print(a) [/code]

Member Avatar for Kruptein
0
9K
Member Avatar for Judgment

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.

Member Avatar for vegaseat
-1
297
Member Avatar for akie2741

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

Member Avatar for vegaseat
0
177
Member Avatar for The Mad Hatter

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?

Member Avatar for Evenbit
-5
2K
Member Avatar for pygirl

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]

Member Avatar for pygirl
0
1K
Member Avatar for nerdagent

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

Member Avatar for vegaseat
0
127
Member Avatar for vegaseat

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 …

Member Avatar for Shantha.D
1
5K
Member Avatar for dmcadidas15

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

Member Avatar for woooee
0
101
Member Avatar for mahela007

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 …

Member Avatar for jice
0
332
Member Avatar for awa

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

Member Avatar for awa
0
116
Member Avatar for lewashby

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.

Member Avatar for lllllIllIlllI
0
121
Member Avatar for sravan953

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

Member Avatar for vegaseat
-1
3K
Member Avatar for wajih

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.

Member Avatar for vegaseat
0
541
Member Avatar for princessotes

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 …

Member Avatar for vegaseat
0
28K
Member Avatar for saikeraku

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

Member Avatar for vegaseat
0
158
Member Avatar for marshall31415
Member Avatar for marshall31415
0
3K
Member Avatar for qadsia
Member Avatar for sneaker

Looks like the same thing. Something has to keep MS thinking that there is actually competition out there!

Member Avatar for ayoungpretender
0
147
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for Gribouillis
0
181
Member Avatar for Mensa180

Just keep asking, we are all more than willing to help a sprouting Python talent.

Member Avatar for Mensa180
1
342
Member Avatar for pmennen

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 …

Member Avatar for vegaseat
0
2K
Member Avatar for The-IT

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

Member Avatar for jlm699
0
3K

The End.