4,305 Posted Topics
Re: Code doesn't seem to be very portable! What is your compiler and operating system? | |
Re: Just a note, there is related Python snippet at: [url]http://www.daniweb.com/code/snippet216539.html[/url] Also Python has a few built-in functions to offer ... [code]# with Python2 you can convert a # binary (base 2) string to a denary (base 10) integer print( int('11111111', 2) ) # --> 255 # Python3 adds the function … | |
Here we apply the module difflib to compare two texts line by line and show the lines of the first text that are different from the second text. | |
Re: Hint, another approach would be to use the function split() ... [code]text1 = "80,45,34" if "," in text1: # split at comma mylist1 = text1.split(",") print( mylist1 ) # ['80', '45', '34'] text2 = "2 bananas and 3 oranges" if " " in text2: # split at space mylist2 = … | |
Re: You need to read your text file line by line. If the line has trailing spaces, it will most likely still end with a newline character. You can use [B]line = line.rstrip() [/B] to strip all trailing white spaces including the newline character. Now if you want to write the … | |
Re: In code line [B]if stemming_word[-1] == leaf_words:[/B] you are trying to compare a character with a tuple. [code]# this will form a tuple leaf_words = "s","es","ed","er","ly","ing" print( leaf_words ) # ('s', 'es', 'ed', 'er', 'ly', 'ing') [/code] | |
Re: The answer is in your title, but you should give us your code to make things clear. | |
Re: Our fellow Pythonian nezachem is correct. You could also have used the usual [B]if __name__ == '__main__':[/B] to test your module code ... [code]#!/usr/bin/python # ChildScript.py import tkSimpleDialog from Tkinter import * class VariableDialog(tkSimpleDialog.Dialog): def body(self, master): self.status = IntVar() cb = Checkbutton(master, text="Variable", variable=self.status) cb.grid(row=1) def apply(self): buttonstatus = … | |
Re: Logic statements can be confusing at times. A slight change and it will work [code]a = raw_input("Enter your first name:") b = raw_input("Enter your last name:") c = raw_input("Enter your phone number:") print a print b print c d = (a and b and c) print d if not d: … | |
Re: Thanks masterofpuppets for a good memory. This might get you to the example faster ... [url]http://www.daniweb.com/forums/post1055261.html#post1055261[/url] | |
Re: What version of Python does your game recommend? | |
Re: My favorite ... 8. I would love to change the world, but they won’t give me the source code. | |
Re: Don't overlook the fact that the Python installer you use is specific for the Operating System. If you install Python on a Windows OS, the GUI toolkits will use the Windows GUI. A similar thing goes for Linux or the Mac OSX. Python source code is largely cross platform, but … | |
Re: [B]str(i).split()[/B] will give you a list and you cannot use strip("'") on a list object. If your list contains strings, pick one item and then strip it. | |
Re: A selection sort of a list of numbers is pretty simple. You start with two lists, let's call the original unsorted list the start_list and you have another list call it the end_list which is empty at the start. If you want to sort ascending (lowest value first) you get … | |
Re: The reason Microsoft was more successful than Apple had a lot to do with hardware. Apple used a Motorola CPU for many years and Microsoft wrote their OS for an Intel CPU. Intel simply out-designed and out-manufactured Motorola. Steven Jobs' NEXT computer was severely hampered by the fact that Motorola … ![]() | |
Re: The initial letter of your class name should be in upper case. In your class constructor you may want to add args for turtle symbol and speed. Let location default to center of screen, direction to up, speed to 'slow' and symbol to 'triangle'. | |
| |
Re: The line most likely ends with \n, so you have to strip the newline with line.rstrip() before can concatenate. | |
Re: I am not sure which version of graphics.py you are using. The version I have (Version 4.0 08/2009) does not show any colors, it simply uses the color names supplied by Tkinter. | |
Re: I assume that pyimage2 is an image object in your module. Without knowing your code, all I can tell you is that Tkinter will garbage collect any image object assigned to a function scope variable. Maybe it will also do that to a module scope variable. | |
Re: There is too much dust on Mars. It would be more fun to create some rather large floating islands on Earth. | |
Re: The basic framework would look something like this ... [code]# find selected files in working folder using module glob # glob takes care of upper/lower case # glob works with Windows and Unix import os import glob # pick a directory/folder where your .dat data files are folder = "C:/temp" … | |
This program uses the Python win32 extension module to get information on disk or flash drives for Windows machines. Specify the drive with its letter. If no drive letter is specified, the current drive is applied. | |
Re: [QUOTE=katharnakh]im confused with [I]__call__() [/I] method defined within the class. [I]__init__() [/I] is used as constructor, and is called when we create an instance of the object. when does [I]__call__() [/I] method get called even though we not specify it explicitly... please help..........[/QUOTE] There are several internal functions like __init__() … | |
Re: The module ecs10graphics.py is simply another wrapper for Tkinter: [url]http://www.cs.ucdavis.edu/~amenta/f09/ecs10graphics.py[/url] If you have a lot of idle time on your hand, you can download it and study how it ought to work. These obscure wrappers are increasingly used by instructors to keep their students somewhat honest. | |
Re: If you have Windows you can use this ... [code]# get disk information on Windows # using the win32 extension module from: # http://sourceforge.net/projects/pywin32/files/ # tested on Windows XP with Python25 and Python31 import win32file def get_drivestats(drive): ''' drive for instance 'C' returns total_space, free_space, used_space ''' drive = drive.rstrip(':\').rstrip(':/') … | |
Re: The function main() can be simplified ... [code]def main(): while True: fahrenheit2celsius() cont = raw_input('Continue converting? (yes/no): ') if 'n' in cont.lower(): break [/code][B]while True[/B] forms an endless loop and the [B]n[/B] in [B]no[/B] or [B]NO[/B] will break out of the loop. | |
Re: [QUOTE=Musafir;1057442]thanks man, so my main problem is indentation.[/QUOTE]Python relies on indentations for it's code blocks. Other computer languages use braces, begin, end and so on. So yes, if you want to code in Python, then poorly done indentations can be a real problem! Remember, a code block usually starts after … | |
Re: The id() test sheds some more light on this ... [php]mlist3 = [[0]*3]*3 print mlist3 # [[0, 0, 0], [0, 0, 0], [0, 0, 0]] # give it the id() test ... # all three sublists objects show the same address, 10317016 on my machine # so they are alias … | |
Re: Take a look at this recent thread: [url]http://www.daniweb.com/forums/thread241860.html[/url] were we discussed functions and parameter passing. | |
Re: [code] def status(): print "\nThe total number of critters is", Critter.total status = staticmethod(status) [/code] This allows class function status() to be called with the class name rather than the instance name ( an instance name wouldn't work because status() is a function, not a method like status(self) ). [B]Critter.total … | |
Re: Here is a rather simple example of a number of functions working together from: [url]http://www.daniweb.com/forums/showthread.php?p=104853#post104853[/url] [code]def get_name(): """this function only returns arguments""" first = "Fred" last = "Ferkel" return first, last def show_name(name): """this function only receives an argument""" print( name ) def process_name(first, last): """this function reveives 2 arguments, … | |
Re: And another page ... [url]http://en.wikibooks.org/wiki/Python_Programming/Email[/url] | |
The World is due another attempt at a universal language. So what are your ideas? My proposal: Easy to learn (simple grammar). Use a simple alphabet (no umlauts please). Make the most common words the shortest words. The words should be unique in sound and somewhat melodic. Pronunciation should make … | |
Re: Something like this ... [code] from Tkinter import * def exit(): # do cleanup code here pass root = Tk() # respond to window title bar x click root.protocol("WM_DELETE_WINDOW", exit) root.mainloop() [/code] | |
Re: use [B]temp = self.set_greyLevel(grayScale)[/B] | |
Re: I think there are a number of so called Reverse Polish Notation calculator examples on this forum. | |
Re: [QUOTE=cwarn23;1040547]Is that a question or statement? If it's a question then my answer is that I could only guess the enormous effort for preventing spam and keeping things in order. So us members know very little of what happens behind the scenes and can only guess the great efforts the … | |
Re: To approximate for instance the sine of x (x in radians) you can use the Taylor series expansion: x - x**3/3! + x**5/5! - x**7/7! + ... However, to get even a remotely accurate number the cutoff for the convergence is large. Your factorials will be huge very quickly too … | |
Re: Ouch!!!!!!! A couple of hints ... you still have to start with one function call from main you need to pass your arguments to and from your functions variable, function and class names are case sensitive in Python firstPair and FirstPair are not the same don't use capitalized names for … | |
Re: I am not quite sure what your part.txt file looks like, but you have to tell your for loop when the file ends, or it will just keep going 40 times. | |
Re: [QUOTE=Gribouillis;1058972]I prefer design 1. We don't know anything about the algorithms that you have in mind, so there is no obvious benefit for introducing the classes Search and Edit. With design 1, the Library object appears as a facade behind which you can implement arbitrary complex and flexible algorithms. Also … | |
Re: If you have a dictionary in your program and want to save and later reload it as a dictionary object, you have to use module pickle. Here is an example ... [code]# use module pickle to save/dump and load a dictionary object # or just about any other intact object … | |
Re: You can write a small Python utility program to do that for you! | |
Re: [QUOTE=Musafir;1059368]I prefer graphic.py at the moment, because I am still a noob[/QUOTE]For old stuff like that I recommend a careful study of the source of graphics.py you can get it from: [url]http://mcsp.wartburg.edu/zelle/python/graphics.py[/url] Also study the elaborate documentation from: [url]http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf[/url] | |
| |
The End.