4,305 Posted Topics

Member Avatar for vandalised

On the issue of code you can understand and is therefore Pythonic, your first code ... [code]def LeapYear(year): if year % 400 == 0: return True elif year % 100 == 0: return False elif year % 4 == 0: return True else: return False [/code]Follows the leap-year rule clearly …

Member Avatar for griswolf
1
2K
Member Avatar for Aeronobe

A dictionary consists of key:value pairs. The keys have to be unique. If you had for instance this dictionary: [code]d = {'abc': 1, 'Abc': 2, 'abC': 3}[/code] Now suddenly you set the key to all lower case, which associated value to you really want?

Member Avatar for Aeronobe
0
112
Member Avatar for vandalised

Yes, it still functions, but one will prompt [B]please enter number 1:[/B] [B]please enter number 2:[/B] ... and so on and the other just [B]please enter number:[/B] [B]please enter number:[/B] ... and so on

Member Avatar for HiHe
0
108
Member Avatar for root

[QUOTE=liquidroof;1218741]Thats really good to know, congrats and keep moving.[/QUOTE] Well, it gave this signature spammer a chance to peddle his/her leaky roof products!

Member Avatar for vegaseat
0
95
Member Avatar for vegaseat

The Python module 'tarfile' is more flexible then it's counterpart 'zipfile'. It allows you to simply archive files without compression, or use the gzip format of compression, or the super compression format bzip2. Here is code to show you the use of the module.

Member Avatar for vegaseat
3
2K
Member Avatar for Ene Uran

If you want to display and later retrieve results from a Tkinter GUI, it would be better to use the Text widget rather than the Label widget. The Text widget is a little more complex, but amongst the many things you can do with it, is the retrieval of the …

Member Avatar for vegaseat
0
3K
Member Avatar for afireinside

When you use [B]self.var = IntVar()[/B] you are really creating an instance of a class this class has [B]get()[/B] and [B]set()[/B] methods

Member Avatar for vegaseat
0
266
Member Avatar for Aeronobe

Here would be another approach ... [code]# change start and ending to test link = "mailto ---- pdf" # startswith conditions start = ('javascript','mailto') # endswith conditions end = ('pdf','ppt') if not all( (link.startswith(start), link.endswith(end)) ): # do something print("link = %s did not pass" % link) else: print("link = …

Member Avatar for vegaseat
1
169
Member Avatar for macca21

You can expand on something simple like that ... [code]''' contents of data_file_1.txt --> Fred, Nurke, 16, 17, 22 Jack, Sprat, 12, 13, 19 George, Reynolds, 14, 11, 30 Harry, Smith, 19, 19, 37 Daniel, Robins, 10, 8, 22 Jacquiline, Stevens, 23, 18, 31 Erin, Collins, 24, 30, 35 William, …

Member Avatar for TrustyTony
0
195
Member Avatar for ShinyDean

Rewrite you code this way to make the import global ... [code]from PIL import Image def bw_negative(filename): """ This function creates a black and white negative of a bitmap image using the following parameters: filename is the name of the bitmap image """ # Create the handle and then create …

Member Avatar for vegaseat
0
2K
Member Avatar for snippsat

Nice program indeed! On Windows it was a little cumbersome to get the wxPython support. I had to go through the following sequence ... I had to first install wxFormBuilder_v3.0.57.exe and then extract wxAdditions_Plugin_v1.07.zip into that directory Then install this over the older version wxFormBuilder_v3.1.61-beta.exe (since that one had a …

Member Avatar for joetraff
2
923
Member Avatar for Geek-Master

Get involved with the speech engine built into Windows XP. It allows you to read text in several different voices. BTW, it is real fun to have the German or French guy read English text. I am trying to write a simple slide viewer that reads a description to each …

Member Avatar for mrnutty
0
178
Member Avatar for Dave Sinkula

You really have to wait till some of the bigger states like California, Texas or New York come into play. Now you are talking convention delegates. Sorry, but Iowa and New Hampshire have really insignificant populations.

Member Avatar for jephthah
0
6K
Member Avatar for gunbuster363

BeautifulSoup is a third party module for Python2 that allows you to access even badly coded HTML code. What do you want to do with it?

Member Avatar for amrutraj
0
6K
Member Avatar for HiHe

A program that leaves programming to the computer. This way we wouldn't have to put up with these self-important odd balls that spend hours arguing how many pointers it takes to move a text from from one function to another.

Member Avatar for Lardmeister
0
147
Member Avatar for apurva agarwal

[QUOTE=nbrmkumaresh]Please give me an idea of how to do program the huffman code in C[/QUOTE] Check the C code snippet right here on DaniWeb: [url]http://www.daniweb.com/code/snippet5.html[/url] Test it, improve it, learn from it!

Member Avatar for asim88
-1
420
Member Avatar for ktsangop

Try something like string formatting ... [code]myvalue = 16 # %02x creates a 2 digit hex byte padded with zero if needed command2 = r"\x03\xa2\x%02x" % myvalue print command2 # \x03\xa2\x10 [/code]

Member Avatar for ktsangop
0
268
Member Avatar for ArtemisFowl

Here is a Python module turtle example of how to draw two concentric circles ... [code]import turtle as tu # initial radius radius = 100 # distance between circles distance = 30 # pen up tu.up() # move pen to point x, y # keeps the center of the circle …

Member Avatar for ArtemisFowl
0
4K
Member Avatar for morteza_ipo

Python is an [B]interpreter[/B] and only compiles to it's internal byte code. Packagers like [B]py2exe[/B] are available that package the byte code and the interpreter (dll) into a self-extracting executable file.

Member Avatar for Ene Uran
0
103
Member Avatar for aint

Of course, you simply move the find() start position up as you search ... [code]# multiple searches of a string for a substring # using s.find(sub[ ,start[, end]]) text = 'MSKSASPKEPEQLRKLFIGGLSFETTDESLRSAHFESSSYGSAGRRF' search = 'SA' start = 0 while True: index = text.find(search, start) # if search string not found, find() …

Member Avatar for TrustyTony
0
601
Member Avatar for saba_newbie

Please show us your code. On line 33 you have "del lib", you are trying to delete an object called "lib" that is not there.

Member Avatar for TrustyTony
0
1K
Member Avatar for WaltP
Member Avatar for Ene Uran
1
164
Member Avatar for vmanes

Stereotype? Except for the pink Net-book all of our Computer Engineers look like that. :)

Member Avatar for Ene Uran
2
213
Member Avatar for anjaliua

Enlighten us a little ... What is protege? What is owl ontology? What does a short sample of the raw data look like?

Member Avatar for merchise
-1
420
Member Avatar for justaguy101

Interesting, you must have hit a gap in the algorithm. I tested it out and came up with these results ... [code]# numpy.random.hypergeometric(ngood, nbad, nsample, size=None) import numpy as np # these work fine print np.random.hypergeometric(10000, 10000, 10000) print np.random.hypergeometric(100000, 1000000, 100000) print np.random.hypergeometric(10000000, 1000000000, 1000000) # these freeze up …

Member Avatar for justaguy101
0
554
Member Avatar for ChargrO

You get the error because you are using submenu in line 16, but create it in line 25.

Member Avatar for TrustyTony
0
472
Member Avatar for jonb7

You can also check the Python module [B]difflib[/B] for line to line comparison of two different texts.

Member Avatar for TrustyTony
0
1K
Member Avatar for jonb7

Code snippets are for working code only! Place questions in the regular Python forum! It's taken care of already, thanks!

Member Avatar for jonb7
0
267
Member Avatar for pythonNerd159
Member Avatar for vegaseat
0
123
Member Avatar for cahram

This would be a simple search in a nested list, but this approach has certain caveats ... [code]mylist = [['dog', 'cat'], ['lizard', 'sheep', 'pig']] print( "'sheep'" in str(mylist) ) # True [/code]

Member Avatar for TrustyTony
0
202
Member Avatar for nsutton

There are some huge IDEs like Eclipse with pydev, or Netbeans for Python. They however are very sluggish and force you to create a project for even the smallest test file. Eric isn't quite as sluggish. I like the fast and nimble IDEs like PyScripter (Windows only), DrPython (only for …

Member Avatar for justaguy101
0
153
Member Avatar for linuxoidoz
Member Avatar for Kruptein

Here is one way to do this ... [code]# a simple sign using wx.richtext.RichTextCtrl() import wx import wx.richtext as rt class MyFrame(wx.Frame): def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, -1, mytitle, size=mysize) self.SetBackgroundColour("white") rich = rt.RichTextCtrl(self, -1, value="") # default is black text rich.BeginFontSize(26) rich.BeginBold() rich.WriteText(" You are in ") …

Member Avatar for Kruptein
0
392
Member Avatar for deedee2

Make the min_item the first item in the list. Then iterate through the list and compare. If the list item is less than the present min_item, make it the new min_item. Do a similar thing with max_item.

Member Avatar for deedee2
0
111
Member Avatar for pythonNerd159
Re: tk()

Here I used a basic Tkinter class template to test your method createEight(self) and gave the button a command ... [code]# Tkinter class template to test apps try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk class MyApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.title("Tkinter basic class") …

Member Avatar for pythonNerd159
0
170
Member Avatar for sneekula

You can use Python's regular expression module re, very powerful for text processing, but there is a somewhat steep learning curve ahead! [code=python]# exploring Python's regular expression module re import re # find all upper case letters in a text: text = "This text has Upper and Lower Case Letters" …

Member Avatar for twekberg
0
324
Member Avatar for naktos

The way a binary system like a computer represents a decimal or floating point number can create a tiny difference that makes it hard to compare floats directly. All computer languages have this problem, and beginners just love to stumble over it. To illustrate this ... [code]def fuzzy_compare(a, b, delta=0.000000001): …

Member Avatar for TrustyTony
0
115
Member Avatar for nonemsludo
Member Avatar for sabiut

If your string is just a single word like [B]"racecar"[/B], then you can simply compare the string with it's reverse spelled counterpart. If your string is a complete sentence like [B]"A man, a plan, a canal, Panama!"[/B], then you should turn all characters to lower case, remove the punctuation marks …

Member Avatar for sabiut
0
194
Member Avatar for karrotbear

Let's say your array of measured voltages would be a list (Python's version of an array) like this ... voltage_list = [105, 108, 111, 117, 109, 112] The size (number of voltages in the list) of the voltage list is ... size = len(voltage_list) Also let's say your action potential …

Member Avatar for vegaseat
0
113
Member Avatar for TrustyTony

Quit will quit the tcl interpreter of Tkinter! If IDLE is used, quit will freeze it, since IDLE uses Tkinter too! Replace quit with destroy, destroy is used to destroy a particular window in a multi-window program

Member Avatar for vegaseat
0
594
Member Avatar for vegaseat

A short look at creating lists of file names or full path names using the versatile Python module glob. Glob follows the standard wildcard protocol.

1
3K
Member Avatar for olofom

You can also use something like [B]time.sleep(10) root.update()[/B] instead of [B]root.mainloop(0)[/B]

Member Avatar for olofom
0
311
Member Avatar for DayneD89

Like IsharaComix pointed out, this is not very useful ... [code]# add a key/variable to the local dictionary vars() # can be done, but not very useful mylist = [0, 1, 2, 3, 4] n = 1 for item in mylist: # add variable names t1 to t5 vars()['t'+str(n)] = …

Member Avatar for vegaseat
0
156
Member Avatar for camigirl4k3

camigirl4k3, you got to learn to use the necessary indentations with your statement blocks.

Member Avatar for TrustyTony
0
131
Member Avatar for HiHe

Here is a function that will check for valid numeric input ... [code]# a simple input function to guarantee numeric input # tested with Python 3.1.2 def input_num(prompt="Enter a number: "): """ prompt the user for a numeric input prompt again if the input is not numeric return an integer …

Member Avatar for TrustyTony
0
4K
Member Avatar for freakn_style

You can really simplify and make your animation much smoother using canvas.move() rather then erase and redraw your canvas shapes. Here is a typical example ... [code]# Tkinter animate via canvas.move(obj, xAmount, yAmount) # tested with Python 3.1.2 import time import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, …

Member Avatar for freakn_style
0
1K
Member Avatar for Ntsoaki

Actually functions any() and all() where introduced with the advent of Python 2.5. Here is a little test ... [code]# Guido proposed boolean functions any() and all() for Python25 # and higher, tested with PortablePython 2.5.4 # combine with generator expressions like this ... seq = (11, 23, 45) # …

Member Avatar for TrustyTony
0
142
Member Avatar for Ntsoaki

Please be more descriptive with your thread's title. It gets a little confusing with two of the same titles.

Member Avatar for TrustyTony
0
296
Member Avatar for peppermints

The problem with the livewires wrapper is that it is rather old and updates are spotty. You would be much better off and learn more using PyGame directly.

Member Avatar for vegaseat
0
1K

The End.