880 Posted Topics

Member Avatar for A_Dubbs

It`s not the best example of python class masterofpuppets. You put in lot effort to help wish is fine. [QUOTE]Hope this makes it a bit clearer....I haven't actually worked a lot with classes in Python but I guess it is not that much different to Java. So I am sorry …

Member Avatar for bumsfeld
1
230
Member Avatar for jaison2

[QUOTE]total price... is 8pounds or £8 and not just 8.. [/QUOTE] [CODE]order = input("Please enter the price of the order: ") x = 1.50 if order < 10: print "the total price including the delivery charge is %d pounds" % (order + x) else: print "The toal price including delivery …

Member Avatar for snippsat
0
224
Member Avatar for Garee

[CODE]>>> suits = ['diamonds', 'clubs', 'hearts', 'spades'] >>> rank = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King'] >>> # This is what we need to make a hole deck >>> # Now we loop trough (rank and suits) and append the result. >>> deck …

Member Avatar for vegaseat
0
346
Member Avatar for figved

BeautifulSoup stores everything as unicode strings. In order to convert BeautifulSoup's unicode strings to human readable strings, you have to encode() them; and when you encode() a unicode string, you have to specify a "codec". Some examples of codecs are "ascii" and "utf-8". Se if this help. [CODE]divs = soup.findAll("div", …

Member Avatar for pythopian
0
318
Member Avatar for Yeen

[CODE]>>> #Is rounds greater than player_point or cpu_point >>> #It will print Victory >>> #Test >>> rounds = 5 >>> player_point = 4 >>> cpu_point = 3 >>> while rounds > player_point or cpu_point: print 'Victory' break else: print 'Lose' Victory >>> #So if we change player_point to 8 >>> …

Member Avatar for vegaseat
0
306
Member Avatar for nevets04

A for loop is easier for this. [CODE] for i in range(4): for item in ['a,b,c,d']: item = raw_input("something: ") something: 7 something: 8 something: 9 something: 2 >>> item '2' >>> #If you whant to store all values put them into a list >>> l = [] for i …

Member Avatar for nevets04
0
184
Member Avatar for gangster88

Some error in your print line,look at this. [CODE]import math radius = input("please enter the radius of the cirle: ") area = float(math.pi*radius**2) circumference = float(2*math.pi*radius) print "With an input off %s area is %.2f\nand circumference is %.2f" % (radius, area, circumference) '''My output--> With an input off 4.78 area …

Member Avatar for snippsat
0
142
Member Avatar for Norua

You should try to post some code yourself. Can give you some tips. [CODE]>>> for i in range(0,7): a = random.randint(0,100) print a 79 21 69 60 28 68 0 >>> [/CODE] [CODE]>>> >>> 1 % 2 1 >>> 2 % 2 0 >>> 3 % 2 1 >>> 4 …

Member Avatar for snippsat
0
144
Member Avatar for kisan

[QUOTE]But how could we test if the given string is pallindrome or not. I need a syntax that returns true if the string is pallindrome otherwise false. [/QUOTE] [CODE]>>> def is_palindrome(s): ... return s.lower() == s[::-1].lower() ... >>> is_palindrome('test') False >>> is_palindrome('racecar') True >>> is_palindrome('RACECAR') True[/CODE]

Member Avatar for Gribouillis
-1
193
Member Avatar for pyprog

To make it short with python list comprehensions. Not that this make code better or more readable in many cases. But think this line is not so bad to understand. [CODE]>>> f = [line[0] for line in open('ab.txt')] >>> f ['a', 'c', 'e', 'g'] >>> [/CODE] Read every characters. So …

Member Avatar for snippsat
0
326
Member Avatar for Kezoor

[CODE]>>> import urllib.request, re >>> from html.parser import HTMLParser >>> main_page = urllib.request.urlopen("http://www.stats.gov.cn/english/").read(20000).decode('gb2312') Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> main_page = urllib.request.urlopen("http://www.stats.gov.cn/english/").read(20000).decode('gb2312') UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 1-2: illegal multibyte sequence[/CODE] It will return none because of error with decode('gb2312') So the …

Member Avatar for Kezoor
0
333
Member Avatar for sravan953

You can set size so the text get overwrite. And som color look better. [CODE] try: self.s.login(self.user,self.passw) wx.StaticText(self.panel,-1,"Logged in...",pos=(10,200),size = (150,20)).SetForegroundColour('blue') except: wx.StaticText(self.panel,-1,"Failed",pos=(10,200),size = (150,20)).SetForegroundColour('red') [/CODE] For me i have to have this put in this lines or it dont work for me. [CODE]self.s.ehlo() self.s.starttls() self.s.ehlo()[/CODE] And your design need …

Member Avatar for pythopian
0
619
Member Avatar for lewashby

[QUOTE]pygame and the livewires package but was unable to get the program to run[/QUOTE] Forget about livewires package,it is outdatet and not smart to use at all if you what to learn pygame. If you want to look pygame you have to do as everyone else. All tutorials on net …

Member Avatar for vegaseat
0
102
Member Avatar for npn_

Lets break it down. [CODE]IDLE 2.6.2 >>> a = ['Mary', 'had', 'a', 'little', 'lamb'] >>> for i in a: print i Mary had a little lamb >>> for item in a: print item Mary had a little lamb >>> #So it can be anything you whant(i,item,element.....) >>> #The for loop …

Member Avatar for npn_
0
88
Member Avatar for lewashby

Think maybe you are confused about calling a function and calling a method. [CODE]def my_func(name, greeting = 'Hello'): print '%s, %s' % (greeting, name) #Call a function my_func('tom') #output <Hello tom> #-----------------------------------# class myClass(object): # Inside a class this is called a method def my_method(self,name,greeting = 'Hello'): print '%s, %s' …

Member Avatar for masterofpuppets
0
161
Member Avatar for AutoPython

Look like cx-freeze has come out with a version for python 3. [url]http://cx-freeze.sourceforge.net/[/url] Or just use python 2.x and python 3., there is no point just to use python 3.x for now. I will not stay for python 2.x til most of the 3 party modules i use a lot …

Member Avatar for vegaseat
0
189
Member Avatar for P3run

Or if you stay with [B]raw_input[/B],you can convert to integer later in the function. [CODE]def add(a,b): print a, '+', b, '=', int(a) + int(b) #print '%s + %s = %d ' % (a, b, int(a)+int(b)) # Try this line to[/CODE] [ICODE]choice = menu()[/ICODE] So now choice take take the variable …

Member Avatar for snippsat
0
130
Member Avatar for python.noob

PyQt support python 3.x [url]http://www.riverbankcomputing.co.uk/software/pyqt/intro[/url] This post has many PyQt example. [url]http://www.daniweb.com/forums/thread191210.html[/url] There are also example of new function for Tkinter. Tkinter version that comes with the Python 3.1 installation includes expansion module ttk. Look at Vegaseat example in link over. Just as a notice there no problem to have …

Member Avatar for vegaseat
0
139
Member Avatar for nevets04

import shall not be inside a function(always first) an 8 space indent(in python we use 4 always),and long functions a. Sorry but i dont se the point in just post this code without any question. And this code dos not help beginners at all,maybe to show how python code not …

Member Avatar for nevets04
-2
311
Member Avatar for rush_ik52

I have made an alramclock with wxpython before with stopclock(countdown) as one of the function. So wxpython has this function build in "wxStopWatch" [url]http://www.tnir.org/~rae/wx/manuals/2.4.2/wx364.htm[/url]

Member Avatar for snippsat
0
824
Member Avatar for topcat712

I dont know why you marked it solved,but write some abought the problem you have. So think you got a assignment about Top-Down Design. You are on the right path. Top-Down Design u call main and you work your way down one function/problem at the time. Gone show how to …

Member Avatar for snippsat
0
1K
Member Avatar for mms6

And a shorter version that uses the reverse string metod in a smart way. [CODE]>>> def is_palindrome(s): ... return s.lower() == s[::-1].lower() ... >>> is_palindrome('test') False >>> is_palindrome('racecar') True >>> is_palindrome('RACECAR') True[/CODE]

Member Avatar for mms6
0
99
Member Avatar for twoshots

[CODE]>>> class Stuff: def __init__(self): self.a = 0.02 >>> x = Stuff >>> x <class __main__.Stuff at 0x012007E0> >>> # you are not instance the class >>> x = Stuff() >>> x <__main__.Stuff instance at 0x011FF0F8> >>> # Here you you instance the class >>> x.a 0.02 >>> y = …

Member Avatar for twoshots
0
122
Member Avatar for sravan953

Vegaseat gave you an answer in your own post last time. [url]http://www.daniweb.com/forums/showthread.php?t=224869&highlight=pymailer&page=5[/url] I have used py2exe and wxpython many times it`s works fine. Some more info if you need it. [url]http://wiki.wxpython.org/py2exe[/url] [url]http://stackoverflow.com/questions/323424/py2exe-fails-to-generate-an-executable[/url] [url]http://article.gmane.org/gmane.comp.python.wxpython/71929[/url]

Member Avatar for sravan953
0
1K
Member Avatar for AutoPython

This code had been better without a class,and this is not the OOP way of thinking. One function for Addition/Division....... can be shorten by eval() [CODE]>>> a = eval('5+8886/45*4554545') >>> a 899370824.3333334[/CODE] Here an example with class. [CODE]import math class Calculator(object): '''Doc_string info about class''' def calculate(self, expression): self.value = …

Member Avatar for AutoPython
0
216
Member Avatar for lrh9
Member Avatar for gsingh2011

I call your code mail.py Testet with python 2.5.4 and 2.6 run exe with no error. If it send mail i dont know because of email2.php i guess only works for you. [CODE]from distutils.core import setup import py2exe import sys if len(sys.argv) == 1: sys.argv.append("py2exe") setup( options = {"py2exe": {"compressed": …

Member Avatar for snippsat
0
663
Member Avatar for simpatar

Think input(python 3) can not take 2 values. You can do it this way. [CODE]>>> score1 = int(input('Enter first number: ')) Enter first number: 5 >>> score2 = int(input('Enter second number: ')) Enter second number: 8 >>> average = (score1 + score2) / 2.0 >>> average 6.5 >>> [/CODE]

Member Avatar for The_Kernel
0
167
Member Avatar for srk619

[QUOTE]dint work anyway what code should i write to open the pygame window is it import pygame?[/QUOTE] No "import pygame" you only make pygame libary available This code to get a pygame window open. Seek google for pygame tutorials. [CODE] #! /usr/bin/env python import pygame screen = pygame.display.set_mode((640, 400)) while …

Member Avatar for snippsat
0
96
Member Avatar for rociel

[CODE]IDLE 2.6.2 >>> start = 14 >>> end = 2 >>> if start <= 21 and end <= 21: # if start before and end before 9pm. payment =(end - start)*5 >>> print "The payment is: ",payment, "dollars" The payment is: -60 dollars >>> if start <= 21 and end …

Member Avatar for snippsat
0
507
Member Avatar for xaeubanks
Member Avatar for bumsfeld
0
136
Member Avatar for saikeraku

One short way for second code. [CODE]>>> s = raw_input("Enter a string: ") Enter a string: car >>> print 'The reverse is %s' % (s[::-1]) The reverse is rac[/CODE]

Member Avatar for cornflakes
0
347
Member Avatar for Judgment

You should try to put some code together. Look at this,and you should figure how to set opp your variables. [CODE]IDLE 2.6.2 >>> for i in range(1, 20, 3): print i #print (i) for python 3 1 4 7 10 13 16 19 ###### #User input for python 2.x >>> …

Member Avatar for vegaseat
-1
297
Member Avatar for plzhelp

[CODE]NW, SE, NE, SW = 0, 0, 0, 0 def checkLights( buttonNum ): global NW, SE, NE, SW if buttonNum == "button 1":[/CODE] The use of global is`s not a god thing at all. Try to avoid at all cost. This do the same. [CODE]def checkLights( buttonNum ): NW, SE, …

Member Avatar for snippsat
0
88
Member Avatar for nerdagent

[CODE]IDLE 2.6.2 >>> first = [ "robert", "jim", "jack" ] >>> last = [ "smith", "white", "black" ] >>> peeps = [ first, last ] >>> peeps [['robert', 'jim', 'jack'], ['smith', 'white', 'black']] >>> prefix = ['mr', 'ms', 'mrs', 'sir'] >>> peeps.append(prefix) >>> peeps [['robert', 'jim', 'jack'], ['smith', 'white', 'black'], …

Member Avatar for vegaseat
0
127
Member Avatar for sravan953

Change to this. [CODE]items.Append(201,"Quit") self.Bind(wx.EVT_MENU,self.Quit,id=201)[/CODE]

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

[QUOTE]This is just on the fly, but I tested it and it works. [/QUOTE]Yes it work ,but this part It`s making ting a little harder and dont make much sense [CODE]for i in range(len(lucky)): if lucky[i] == "7":[/CODE] . [CODE]>>> lucky = raw_input("Please enter an integer: ") Please enter an …

Member Avatar for vegaseat
0
158
Member Avatar for paulo3k

This is one way. [CODE]import os def on_button(event): '''event handling on push button open notepad''' os.startfile('notepad') #or path to your exe[/CODE]

Member Avatar for masterofpuppets
0
89
Member Avatar for Mensa180

You need event handling. Put this function at top after import like this. [CODE]import tkinter as tk def on_move(value=0): f = scale.get() label['text'] = f[/CODE] Now you see that your down slider is working. So now just figure out the calulate stuff,and you have a nice program.

Member Avatar for Mensa180
0
117
Member Avatar for DEATHMASTER

[QUOTE]For determining whether the number is odd or even I have this:[/QUOTE] Just som traning in idle is good to do. [CODE]>>> 2 % 2 0 >>> 3 % 2 1 >>> 4 % 2 0 >>> 5 % 2 1 >>> 6 % 2 0 >>> # now you …

Member Avatar for snippsat
0
123
Member Avatar for Mensa180

[CODE]>>> from random import randint >>> a = randint (1,10,) >>> a 2 >>> b = randint (1,10,) >>> b 5 >>> z = a + b >>> z 7 >>> print (a, "+", b, "=") 2 + 5 = >>> y = input('What is the answer? ') What is …

Member Avatar for Mensa180
1
342
Member Avatar for sravan953

Like winmic says you need to use GetValue() in a method. You have also "event.GetKeyCode()". That can record live from keyboard. But most normal is to have av button that collect data from user_input and do stuff. Here a function(or method as is called when in a class) This function …

Member Avatar for snippsat
0
683
Member Avatar for Dragazarth

There are several big mistake yes. And that use of global is not good at all. Dont use global at all it`s ugly. Test yout code in idle. This is wrong. [CODE]Fraction('x \t\n')[/CODE] Could be. [CODE]Fraction = ('x \t\n')[/CODE] But it does not do what you want. And this will …

Member Avatar for Dragazarth
0
91
Member Avatar for saikeraku

Vegaseat has written a number to word converter. [url]http://www.daniweb.com/code/snippet216839.html[/url] But at dont see why you should need this. [CODE]#Let look at dictionary for som simple number to word stuff. >>> d {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: …

Member Avatar for snippsat
0
82
Member Avatar for StarZ

[QUOTE]DaniWeb Community > Software Development > Python [/QUOTE] So why are you posting java code here?

Member Avatar for StarZ
0
263
Member Avatar for goboman

Please use code tag so indents work. Always read sticky post in top off a forum.

Member Avatar for jice
0
90
Member Avatar for persianprez

There are several problem here. Python 3.x only use input(raw_input only work for 2.x) [ICODE]=[/ICODE]assign variable(can not use in [ICODE]=[/ICODE] in a [B]if[/B] statement. [ICODE]==[/ICODE] Compares if the objects are equal To get a integer to return you can do it like this. [CODE]number_of_courses = int(input ('Please enter...'))[/CODE] This will …

Member Avatar for d5e5
-1
135
Member Avatar for Frenzic

Hint. [CODE]for i in range(2, 1000): print i >>> 2 % 2 == 0 True >>> 3 % 2 == 0 False >>> 4 % 2 == 0 True >>> 5 % 2 == 0 False >>> [/CODE]

Member Avatar for pysup
-1
98
Member Avatar for DEATHMASTER

What are you trying to do? [CODE]>>> first = 'stringisfun' >>> second = 'iamsecond' >>> app = first[0:8] >>> app 'stringis' >>> app1 = second[0:8] >>> app1 'iamsecon' >>> app + app1 'stringisiamsecon' >>> [/CODE] "and or" are used for decision control(Boolean logic) So if you want both first and …

Member Avatar for vegaseat
-1
219
Member Avatar for lewashby

Print is good to use. IDLE is good to use,to se what going on. Just a little test [CODE]>>> import random >>> WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone") >>> word = random.choice(WORDS) >>> word 'python' >>> # So now we have a random word from tuple list # …

Member Avatar for snippsat
-1
169

The End.