4,305 Posted Topics

Member Avatar for harshchandra

Code doesn't seem to be very portable! What is your compiler and operating system?

Member Avatar for Nick Evan
-2
614
Member Avatar for Kippstah

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 …

Member Avatar for Kippstah
0
1K
Member Avatar for vegaseat

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.

Member Avatar for jimothy
0
236
Member Avatar for lisedaton

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

Member Avatar for Namibnat
0
92
Member Avatar for Judgment

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 …

Member Avatar for Namibnat
0
184
Member Avatar for andrewktmeikle

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]

Member Avatar for andrewktmeikle
0
2K
Member Avatar for Dan08

The answer is in your title, but you should give us your code to make things clear.

Member Avatar for Dan08
0
22K
Member Avatar for SoulMazer

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

Member Avatar for SoulMazer
0
144
Member Avatar for Workingwmyhands

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

Member Avatar for SoulMazer
0
163
Member Avatar for ptn001

Thanks masterofpuppets for a good memory. This might get you to the example faster ... [url]http://www.daniweb.com/forums/post1055261.html#post1055261[/url]

Member Avatar for vegaseat
0
106
Member Avatar for jimothy
Member Avatar for Devi
Member Avatar for Scuppery

My favorite ... 8. I would love to change the world, but they won’t give me the source code.

Member Avatar for Lardmeister
7
526
Member Avatar for mahela007

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 …

Member Avatar for vegaseat
0
1K
Member Avatar for Kruptein

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

Member Avatar for Kruptein
0
87
Member Avatar for kvard

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 …

Member Avatar for vegaseat
0
435
Member Avatar for Phil++

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 …

Member Avatar for diafol
0
203
Member Avatar for MRWIGGLES

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'.

Member Avatar for Lardmeister
1
152
Member Avatar for ithelp
Member Avatar for EvaDo

The line most likely ends with \n, so you have to strip the newline with line.rstrip() before can concatenate.

Member Avatar for vegaseat
0
100
Member Avatar for MRWIGGLES

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.

Member Avatar for woooee
0
142
Member Avatar for Elvedon

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.

Member Avatar for vegaseat
0
152
Member Avatar for hughv

There is too much dust on Mars. It would be more fun to create some rather large floating islands on Earth.

Member Avatar for GrimJack
2
593
Member Avatar for EvaDo

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

Member Avatar for Gribouillis
0
182
Member Avatar for vegaseat

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.

Member Avatar for Gribouillis
4
3K
Member Avatar for katharnakh

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

Member Avatar for snippsat
0
17K
Member Avatar for vnproduktionz

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.

Member Avatar for vegaseat
0
94
Member Avatar for Aiban

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(':/') …

Member Avatar for Stefano Mtangoo
0
299
Member Avatar for gangster88

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.

Member Avatar for sneekula
0
595
Member Avatar for Musafir

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

Member Avatar for sneekula
0
393
Member Avatar for sneekula

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 …

Member Avatar for Mathhax0r
0
1K
Member Avatar for Musafir
Re: Flip

Take a look at this recent thread: [url]http://www.daniweb.com/forums/thread241860.html[/url] were we discussed functions and parameter passing.

Member Avatar for vegaseat
0
141
Member Avatar for lewashby

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

Member Avatar for vegaseat
0
193
Member Avatar for ffs82defxp

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

Member Avatar for vegaseat
0
381
Member Avatar for ffs82defxp
Member Avatar for vegaseat
0
86
Member Avatar for vegaseat

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 …

Member Avatar for Brian Barker
0
239
Member Avatar for SoulMazer

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]

Member Avatar for SoulMazer
0
103
Member Avatar for vsagarmb
Member Avatar for maomaohui

I think there are a number of so called Reverse Polish Notation calculator examples on this forum.

Member Avatar for Ene Uran
-2
75
Member Avatar for sknake

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

Member Avatar for cwarn23
1
313
Member Avatar for mrnutty
Member Avatar for thesinik

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 …

Member Avatar for thesinik
0
4K
Member Avatar for ffs82defxp

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 …

Member Avatar for vegaseat
0
143
Member Avatar for LisaJane

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.

Member Avatar for xaveri
0
5K
Member Avatar for ShadyTyrant

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

Member Avatar for ShadyTyrant
2
262
Member Avatar for furblender

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 …

Member Avatar for furblender
0
3K
Member Avatar for persianprez
Member Avatar for vegaseat
-2
88
Member Avatar for Musafir

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

Member Avatar for vegaseat
-3
282
Member Avatar for Ene Uran
Member Avatar for Musafir

The End.