4,305 Posted Topics

Member Avatar for esash

Another good numpy resource is: [url]http://www.scipy.org/Numpy_Example_List_With_Doc[/url]

Member Avatar for vegaseat
0
157
Member Avatar for etypaldo

I am not sure which version of Python you are using, but if you explore this code ... [code=python]rank = ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K") suit = ("c", "h", "s", "d") deck = [] for r in rank: for s in suit: …

Member Avatar for sneekula
0
165
Member Avatar for Friktion

As far as I know the Python25.DLL and the Python26.DLL use 2 different MS C compilers (2003 vs 2008 ?) for the Windows product. The two C versions are not compatible. I got the Python24 binary version to work on Python25 as explained here ... [code=python]# PyMedia wave play # …

Member Avatar for Friktion
0
256
Member Avatar for AutoPython

My advice, don't run it from the shell. The shell is only used to test very short code examples (1 to 3 lines).

Member Avatar for vegaseat
0
69
Member Avatar for AutoPython

As your code gets more complex and longer, a function could change the value of the global variable and make your code buggy. This kind of bug might be hard to figure out! Now your life has just been made a lot harder!

Member Avatar for AutoPython
0
331
Member Avatar for i are smart

Forget cTurtle and use the regular module turtle that comes with Python. Also, I think cTurtle is written with Python3 in mind and is not well tested.

Member Avatar for sneekula
0
252
Member Avatar for chico2009

[QUOTE=chico2009;990903]Hi Guys Thanks very much for your post. I understand now that I have to make Tf part of the function and how to do so. I dont understand your Tf=Tc_toTf () command, could you please explain how it works. Many thanks Graham[/QUOTE] It simply means that function Tc_toTf() [B]returns[/B] …

Member Avatar for chico2009
0
193
Member Avatar for Benderbrau
Member Avatar for optikali

[B]if choice == 'A' or 'C':[/B] is wrong, has to be [B]if choice == 'A' or choice == 'C':[/B] or simpler [B]if choice in 'AC':[/B] It looks like you are using tabs for indentations, stay away from those and use four spaces instead. Indentations are too important in Python to …

Member Avatar for sneekula
0
190
Member Avatar for serkan sendur
Member Avatar for Caleb2419

Moved this to Forum Thread: Please submit only finished/working code snippets. Questions like this should be submitted as a regular forum thread.

Member Avatar for Caleb2419
0
241
Member Avatar for lifeworks

Good luck with your studies, whatever language you pick! I have learned and applied a number of computer languages in my life, things like Asm, Fortran, Forth, Pascal, Basic, C, C++, C#, Object Pascal, HTML, Java Script, and finally Python. Of all of those I enjoy Python the most. It …

Member Avatar for sravan953
0
168
Member Avatar for edward_pedro

Using tabs does make for ugly looking code. Please use four spaces for indentations like every sane Python person. My programming editor balks at tabs in Python code, so I can't help.

Member Avatar for vegaseat
0
150
Member Avatar for chase32

[QUOTE=chase32;988067]This is what I ended up with, works great :) [code] def merge(lib1,lib2): for item in lib2.keys(): lib1[item].update(lib2[item]) return lib1 [/code][/QUOTE]Mild caveat, for this to work lib1 and lib2 have to be of type collections.defaultdict(dict) , and each value has to be a dictionary too. Here is a typical eaxmple …

Member Avatar for vegaseat
0
204
Member Avatar for KernMilestone

Bill Clinton, George W. Bush and George Washington are on a sinking ship. As the boat sinks, George Washington heroically shouts, "Save the women!" George W. Bush hysterically hollers, "Screw the women!" Bill Clinton's asks excitedly, "Do we have time?"

Member Avatar for quicktpgo
0
553
Member Avatar for rajivgupta1107

I found a copy of 'movable Python24' on one of my flash drives, and this works ... [code=python]# excute a code string s = 'print "Hello!" ' exec(s) """my result --> Hello! """ [/code]In answer to your question, Python24 has the function exec().

Member Avatar for vegaseat
0
234
Member Avatar for dissident85
Member Avatar for dissident85
0
89
Member Avatar for nunos

You are creating a situation where the while loop exit condition is always True. Test this ... [code=python]overwrite = None while overwrite != 'y' or overwrite != 'n': overwrite = raw_input("Do you want to overwrite (Y/N)? ").lower() print overwrite != 'y' print overwrite != 'n' # overall condition print False …

Member Avatar for sravan953
0
1K
Member Avatar for Lingson

There will be a ton of these gotchas as people switch from Python2 to Python3, or like in Ene's case try to make code work in both versions. Here is a little test using the 2 versions ... [code=python]x = range(3) print(x, type(x)) """ my output (Python 2.5.4) --> ([0, …

Member Avatar for sneekula
0
4K
Member Avatar for sravan953

Most likely your while loop is the problem. You are telling while to loop as long as clock does not match the time, but inside the loop you have if with a condition to match clock and time.

Member Avatar for sravan953
0
139
Member Avatar for squallgoh

I think what you want is called a selection ... [code=python]def selections(items, n): if n == 0: yield [] else: for i in range(len(items)): # recursion for ss in selections(items, n - 1): yield [items[i]] + ss mylist = ['a','b','c'] # or list('abc') sample = len(mylist) # with Python3 you …

Member Avatar for squallgoh
0
141
Member Avatar for mahela007

To make life easier you could use a helper method ... [code=python]# creating a class instance within another class class Person: def __init__(self,name): self.name = name class ClubMember: def __init__(self,name): self.new_clubmember = Person(name) def expose(self): return self.new_clubmember.name bob = ClubMember('Bob Sponge') mary = ClubMember('Mary Keester') # access info this way …

Member Avatar for vegaseat
0
200
Member Avatar for febinameer
Member Avatar for patto78

[QUOTE=patto78;982909]Sneekula, thanks for the response. I like your way of doing it, particularly because you have dispensed with the rather messy beginning of my code, and I will be sure to make these changes. I remain curious however about why my code doesn't work, any suggestions about this?[/QUOTE]Because the while …

Member Avatar for patto78
0
142
Member Avatar for sravan953

Following the thinking of sneekula at: [url]http://www.daniweb.com/forums/post892908.html#post892908[/url] You can do some detective work and pull weather data from the [url]www.weather.com[/url] html code like my little example shows ... [code=python]# given the zip code, extract the weather conditions of the area # tested with Python25 import urllib2 import time def extract(text, …

Member Avatar for EAnder
0
407
Member Avatar for sravan953

Try to use 'res' as an argument passed between your functions ... [code=python]import urllib2 as url import subprocess import os webs=open("url.txt",'r') read_webs=webs.read() def get_html(): try: req=url.urlopen(read_webs) res=req.read() return res except: #print("<Error reading from the website>") return False def get_command(res): if True: for x in res: if(x!='<'): command+=x else: break determine() …

Member Avatar for sravan953
0
156
Member Avatar for jonte

Lists have a remove() function, so something like this should do it ... [code=python]text = ['Mary', 'went', 'out', 'at', '7pm', 'to','buy','some','candy'] keyPerson = ['Mary', 'Clark', 'Steven'] keyTime = ['7pm', '6am', '2pm'] keyThing =['candy','eggs','fruit'] # make a true copy of text list text2 = list(text) for current in text: for e …

Member Avatar for jonte
0
78
Member Avatar for catcit

If you use Python 3.1.1, then you can simply use the Tkinter module ttk that ships with it ... [code=python]# explore the ttk.Progressbar of the Tkinter module ttk # ttk is included with Python 3.1.1 import tkinter as tk from tkinter import ttk def click(event): # can be a float …

Member Avatar for vegaseat
0
564
Member Avatar for mahela007

[QUOTE=mahela007;978385]Hi.. I would like to know how to create a variable while the program is being executed. Here's what should happen. The program asks for an input from the user and then creates a variable who's name is the value of the input and then assign's a value to it. …

Member Avatar for The_Kernel
0
257
Member Avatar for vegaseat

Here is an example how to write a program to convert between units of distance, area, volume, weight, pressure, and energy. The wxPython GUI toolkit's wx.NoteBook() widget is used to make good use of the limited frame/window space available.

3
184
Member Avatar for vegaseat

A variation of the previous bouncing ball code. This time the upper left corner of the image rectangle simply follows the position of each mouse click. Use an image you have, in my case I used a small red ball in a black background. A simple code to experiment with.

3
3K
Member Avatar for vegaseat

Text to speech can be implemented in its simplest form using Microsoft's Component Object Model (COM) connecting to the Speech API (SAPI). The attached Python code shows you how to do this.

0
4K
Member Avatar for vegaseat

This short Python snippet shows you how to read mouse wheel events with the Tkinter GUI toolkit. Windows and Linux have different bindings and read different events, but can be included in the same program code for use with either operating system.

0
21K
Member Avatar for vegaseat

This well commented Python snippet uses wxPython's plotting widget to graph the projectile motion of two different firing angles on the same plotting canvas.

1
276
Member Avatar for vegaseat

Sometimes you want to accomplish something with a minimum ammount of code. Here is an example of using modern Python concepts of lambda, list comprehension and all() to create an anonymous function that returns a prime list from 2 to n.

1
167
Member Avatar for xbretzel
Member Avatar for vegaseat

A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget.

0
602
Member Avatar for vegaseat

Just bouncing a red ball within the frame of a window, the twist here is that the image is stored within the code as a base64 encoded string of the gif image. This way you only have to distribute one file. The Python code is heavily commented, so you can …

Member Avatar for Arkapravo
2
372
Member Avatar for vegaseat

Using count() from Python's itertools module and the Tkinter GUI toolkit's after() function, you can create a simple counter that counts up the seconds until the Stop button is pressed.

1
3K
Member Avatar for avgprogramerjoe

Removed [ code][ inlinecode] ... [ /inlinecode][ /code] tags. Note, you could use letters = string.ascii_letters + string.punctuation + string.digits

Member Avatar for ShawnCplus
0
143
Member Avatar for vegaseat

The wxPython wx.lib.fancytext widget allows you to display super and subscripts in texts, and allows you to change fonts and colours too. All this is done with XML coded strings. XML documentation code is tag based and not that difficult to understand. It looks rather similar to the older HTML …

0
416
Member Avatar for vegaseat

The wxPython GUI toolkit has a number of calendar widgets, but the one that is most customizable is the wx.lib.calendar widget. Here we expanded it to colour the weekends and the holidays supplied by a dictionary of 'month: list of holiday dates in month' pairs. Since some holiday dates can …

0
2K
Member Avatar for aj.wh.ca

Glad you discovered Python. For a more general discussion on sets see: [URL]http://www.daniweb.com/code/snippet219.html[/URL]

Member Avatar for vegaseat
0
115
Member Avatar for vegaseat

Just a little mathematical exercise in geography, namely the use of longitude and latitiude coordinates to calculate the distance between two given cities. You can obtain the coordinates for just about any earthly city from [URL="http://www.ASTRO.COM"]WWW.ASTRO.COM[/URL]. The coordinates are in a format like 35n13 (35 degrees, 13 minutes north). The …

3
2K
Member Avatar for vegaseat

There are times when you have to layout widgets on a window area fairly well spaced apart. To do this with pack() or grid() will be more than frustrating, for these occasions place() with its absolute coordinates comes to the rescue. Here is some Python/Tkinter GUI code showing you how …

1
619
Member Avatar for vegaseat

A short C# code snippet to get the US Naval Observatory Master Clock Time from: [URL]http://tycho.usno.navy.mil/cgi-bin/timer.pl[/URL] The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone.

Member Avatar for Mustafa Laith
0
683
Member Avatar for vegaseat

The normal XOR crypting is used with a small base64 twist to produce printable crypted text.

2
348
Member Avatar for vegaseat
Member Avatar for vegaseat

C# has two types of strings, one is immutable and the other, the class StringBuilder, is mutable (dynamic). I just wanted to hang a short code snippet out there to show you some of the typical operations.

Member Avatar for varagpraveen
0
190
Member Avatar for vegaseat

I followed Lardmeister's smart hints about creating templates with VC# 2003 and using SnippetCompiler.exe to write and test the rest of the program. It also allows you to build the executable (only 7k in size). The algorithm is from one of my Python snippets I wrote a long time ago. …

Member Avatar for Ene Uran
0
1K

The End.