4,305 Posted Topics
Re: Another good numpy resource is: [url]http://www.scipy.org/Numpy_Example_List_With_Doc[/url] | |
Re: 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: … | |
Re: 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 # … | |
Re: My advice, don't run it from the shell. The shell is only used to test very short code examples (1 to 3 lines). | |
Re: 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! | |
Re: 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. | |
Re: [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] … | |
| |
Re: [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 … | |
Re: Google is running on overload and only picks up important stuff? | |
Re: Moved this to Forum Thread: Please submit only finished/working code snippets. Questions like this should be submitted as a regular forum thread. | |
Re: 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 … ![]() | |
Re: 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. | |
Re: [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 … | |
Re: 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?" | |
Re: 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(). | |
Re: match() is for the beginning of a string search() looks through the entire string | |
Re: 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 … ![]() | |
Re: 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, … | |
![]() | Re: 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. ![]() |
Re: 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 … | |
Re: 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 … | |
Re: You need to give us more info about the scope. | |
Re: [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 … | |
![]() | Re: 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, … |
![]() | Re: 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() … ![]() |
Re: 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 … | |
Re: 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 … | |
Re: [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. … | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget. | |
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 … | |
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. | |
Re: Removed [ code][ inlinecode] ... [ /inlinecode][ /code] tags. Note, you could use letters = string.ascii_letters + string.punctuation + string.digits | |
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 … | |
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 … | |
Re: Glad you discovered Python. For a more general discussion on sets see: [URL]http://www.daniweb.com/code/snippet219.html[/URL] | |
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 … | |
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 … | |
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. | |
The normal XOR crypting is used with a small base64 twist to produce printable crypted text. | |
Just a quick look at the way C# writes and reads text files. | |
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. | |
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. … |
The End.