4,305 Posted Topics
Re: Do not save any of your Pygame files wih the filename Pygame.py Python will look in your working folder first and confuse it with the the Pygame package, usually located at C:\Python27\Lib\site-packages\pygame | |
Re: Another option ... with open('PyTest.txt', 'w') as fout: for i in range(0, 105, 5): fout.write(str(i) + ' ') '''content of file PyTest.txt ... 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 ''' If you want to use … | |
Re: Just in case you have a bum sound file. Does this work ... '''pg_sound_wav.py play a wave sound file with pygame ''' import pygame pygame.mixer.init() sound = pygame.mixer.Sound('hey.wav') # play the actual sound sound.play() | |
Python experiment to get an image from a web page and save it to an image file. Updated code to work with both Python versions ... | |
Re: You mean something like this ... '''class_customlist1.py build your own custom list with a class inheriting Python's list object ''' class CList(list): '''inherits list object''' def __init__(self, alist=[]): self.alist = alist def append(self, item): return self.alist.append(item) def show(self): print(self.alist) clist = CList(['x', 'y']) # you can use clist.append('a') # or … | |
Re: I would go with jlm699 ... sys.path lists all the directories Python will check, so simply append it with the path of a directory you have created for all your modules. | |
Re: There is Blender that uses Python as a scripting language. See: http://wiki.blender.org/ Used to come along with Stani's Python Editor (SPE). I have played around with **VPython** and find it very powerful. Here is a typical VPython coded example ... # draw a green cylinder and a red sphere in … | |
Re: The Python's slicing operator can be used with any indexed sequence like strings, lists, ... syntax --> seq[begin : end : step] step is optional defaults are index begin=0, index end=len(seq)-1, step=1 step = -1 reverses sequence | |
Re: Here is another approach ... '''card_deck_5.py create a deck of cards, shuffle and draw a hand of five cards suit: club=C, diamond=D, heart=H spade=S rank: ace=A, 10=T, jack=J, queen=Q, king=K, numbers=2..9 ace of spade would be AS, 8 of heart would be 8H and so on ... ''' import random … | |
Re: Try this to avoid cyclical imports ... #!/usr/bin/python # save as menu.py def menu1(): from dictionary import dmenu1 print "Add into the list the result of a new participant." print "\ta to adds the score x for the last participant." print "\tb to inserts score x at position y in … | |
[B]Intro[/B] C is using structures to group data, mostly data that belongs together. Here we have some data that a campaign manager might keep for the volunteers. First we take a look at the C code: [code=c]#include <stdio.h> struct person { char *name; char *sex; char *slogan; }; int main(void) … | |
Re: Somewhere in the C compiler details it states that the code has to finish with a newline. Dev-Cpp's GNU compiler and some other compilers give a warning, not an error. Many IDEs put the new line in automatically. | |
Re: Wow, I don't think 'Visual Studio 6.0 at a slight angle' comes even close to 'human feces in a jar'. :) | |
Re: If you want to try Python, be aware that Python has switched versions from 2 to 3. A fair number of the old version 2 code samples will not work with version 3. The latest version of Python is 3.3.0 and you can get it as a Windows msi (use … | |
Re: This code sample might help ... http://www.daniweb.com/software-development/python/code/437525/tkinter-shape-mouse-click-position-python | |
This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape. | |
Re: In a nutshell ... command= accepts a function reference not a function call | |
There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ... | |
Re: Let's say you have this program saved as test.py in folder "C:/Python27/Mytests/" # save as test.py for x in range(10): print(x) Now you can do this in the Python shell and see the output... Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", … | |
Re: Or you can draw using a GUI toolkit ... # using the Zelle graphics module (derived from Tkinter) # http://mcsp.wartburg.edu/zelle/python/graphics.py # draw a stick figure from graphics import * def drawStickFigure(): win = GraphWin("Stick figure") # head Circle(Point(100, 60), 20).draw(win) # body Line(Point(100, 80), Point(100, 120)).draw(win) # arms with options … | |
Re: This might just help you ... # using the Zelle graphics module (derived from Tkinter) # http://mcsp.wartburg.edu/zelle/python/graphics.py # draw a blue circle at mouse click point from graphics import * def blueCircle(): w = 450 h = 450 win = GraphWin("Click in window", w, h) p = win.getMouse() x = … | |
Re: In a nutshell ... A dictionary is an unordered set of key:value pairs sometimes called associative arrays, mappings or hash tables. Dictionaries are indexed with unique keys instead of ordinal offset values. Numbers and strings can always be used as keys and can be mixed. Dictionaries grow or shrink on … | |
Re: Hint ... start = 7 # this will count r from start down to 0 for r in range(start, -1, -1): print(r) | |
Re: [QUOTE=jwenting]Define "best"... Also define your operating system... Microsoft has a good free compiler, but if you're working on unix or mac that will do you little good. Borland has a good free compiler as well. What do you want from your compiler. Some have better standards compliance, others may generate … | |
I am exploring some of the PySide (PyQT public) widgets like the combo box, and how colors are applied ... | |
This sequence has me scratch my head: 2 7 4 1 4 6 2 1 8 2 What is the next number? What are the rules for this sequence? ![]() | |
This Python code shows you how to get a current list of currency values (Canadian Dollar = 1.00) via the internet. | |
Re: You could use something like this ... '''pressure1.py use seconds since epoch to calculate the elapsed time ''' import time # test data is csv type ... # time,pressure,temperature data = """\ 08/08/2012 09:26:01,14.334,26.379 08/08/2012 09:26:02,14.329,26.376 08/08/2012 09:26:03,14.337,26.394 08/08/2012 09:26:04,14.324,26.421 """ fname = "apressure.csv" # write the test file with … | |
Re: Can you give us the full traceback message? | |
Re: Maybe something like this will work for you ... data = '''\ GCOORD 5.98400000E+03 1.19901791E+01 8.29785919E+00 -1.10000002E+00 GCOORD 5.98500000E+03 1.25401793E+01 8.84785938E+00 -6.59999990E+00 GCOORD 5.98600000E+03 1.30901794E+01 9.39785957E+00 -1.21000004E+01 BNBCD 3.66000000E+02 6.00000000E+00 4.00000000E+00 4.00000000E+00 4.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 BNBCD 4.17000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00 1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 BNBCD 5.16000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00 … | |
Re: Saving your file like Lucaci Andrew (Lucaci Andrei) suggested is the best/safest solution. You could even use a new line as a separator. If you absolutely need a long numeric string, then use slicing like snippsat showed. | |
Re: Try something like this ... for i in range(0,2): orange = open('original.txt', 'a') text = raw_input("Enter message:") orange.write(text + '\n') orange.close() | |
Re: In a nutshell, a class combines methods/functions that belong together. A typical class example ... '''Class_Animal1.py a look at a simple Python class a class combines methods/functions that belong together to keep methods private, prefix with a double underline only see also: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html tested with python27, python32, python33 ''' class … | |
Re: Take a look at: http://www.daniweb.com/software-development/python/code/435852/a-simple-pyside-digital-clock | |
Re: Try cmds.button(l="Connect to Selected",command='self.selCon') I wouldn't use l it looks to much like a number 1 | |
Re: If you really want 4.18 you can try ... p = 4.1895030939393 print(round(p-0.005, 2)) | |
Re: Forget about your doDivideZero function and replace some of your code with [code=cpp] case '/': cout << " Enter Number:"; cin >> newEntry; if (newEntry == 0) { cout << "Wrong Operation, Cannot Divide by Zero" << endl; newEntry = 1; } displayedVal = displayedVal / newEntry; break; [/code] This … | |
Re: Quite a number of third party modules are out already for Python33. Their Windows installers can be downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ Just to show a few: PySide-1.1.2qt483.win32-py3.3.exe matplotlib-1.2.0rc2.win32-py3.3.exe cx_Freeze-4.3.win32-py3.3.exe pyglet-1.2alpha1.win32-py3.3.exe numpy-MKL-1.6.2.win32-py3.3.exe pygame-1.9.2pre.win32-py3.3.exe PIL-fork-1.1.7.win32-py3.3.exe Note that a fair number of Python functions have seen improvements. Check the 'What's New' in the helpfile. … | |
Re: Are the Russians boozing so much to keep their blood from freezing? | |
![]() | Re: Take a look at this ... def main(): # getInputs() returns num1 an num2 num1, num2 = getInputs() # calculateWork(num1, num2) # needs num1 and num2 arguments # and returns answer answer = calculateWork(num1, num2) print (answer) def getInputs(): num1 = int(input("Please enter your first number: ")) num2 = int(input("Please … |
Re: Check the difflib and filecmp modules in the Python manual. | |
| |
Re: Oh my goodness, somebody still using Windows Vista. There could be a problem with access as an administrator when the dll wants to install in Windows/System32 You could also try Portable Python from: http://www.portablepython.com/wiki/PortablePython3.2.1.1 That one you can either use from your hard drive or a flash drive. Does not … | |
Re: Looks ike you are using Python3, so '/' will be floating point division and '//' an integer division. You can always test drive it ... Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> 2/3 0.6666666666666666 … | |
Re: You could use global variables this way, but I don't recommend it ... def texten(): global text filehandle=open ( 'savetonight.txt', 'r' ) text=filehandle.read() #return text def smabokstavertext(): global text texten() print text.lower() smabokstavertext() I assume you are experimenting with functions, so JasonHippy's approach is the way to go, since you … | |
Re: I would go with a named tuple for efficiency and elegance. | |
Re: I need some idea what you have done so far, so I can help! | |
Re: If your data is read from a text file, your lines are strings even though they look like lists. Lardmeister's advice is good. | |
Re: Your "Head First" book must be using code for Python3. It might be worthwhile to install that version of Python. |
The End.