4,305 Posted Topics

Member Avatar for yogesh.sdot

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

Member Avatar for vegaseat
0
223
Member Avatar for Wire.Crisis

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 …

Member Avatar for Lardmeister
0
408
Member Avatar for sgeep

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()

Member Avatar for vegaseat
0
326
Member Avatar for vegaseat

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

Member Avatar for snippsat
5
2K
Member Avatar for Inshu

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 …

Member Avatar for Schol-R-LEA
0
207
Member Avatar for jworld2

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.

Member Avatar for vegaseat
0
5K
Member Avatar for elbarto

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 …

Member Avatar for TrustyTony
0
2K
Member Avatar for shanenin

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

Member Avatar for shanenin
0
1K
Member Avatar for dtripath

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 …

Member Avatar for vegaseat
0
129
Member Avatar for pauldespre

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 …

Member Avatar for TrustyTony
0
147
Member Avatar for vegaseat

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

Member Avatar for georgooty
0
767
Member Avatar for abd2

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.

Member Avatar for kimchong
2
2K
Member Avatar for Ancient Dragon

Wow, I don't think 'Visual Studio 6.0 at a slight angle' comes even close to 'human feces in a jar'. :)

Member Avatar for BigPaw
0
110
Member Avatar for BigPaw

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 …

Member Avatar for BigPaw
0
505
Member Avatar for MissAuditore

This code sample might help ... http://www.daniweb.com/software-development/python/code/437525/tkinter-shape-mouse-click-position-python

Member Avatar for vegaseat
-1
102
Member Avatar for vegaseat

This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape.

2
4K
Member Avatar for sgeep
Member Avatar for TrustyTony
0
837
Member Avatar for vegaseat

There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ...

Member Avatar for rubik-pypol
3
396
Member Avatar for syeda amna

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

Member Avatar for syeda amna
1
585
Member Avatar for james5050

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 …

Member Avatar for vegaseat
0
843
Member Avatar for ashley9210

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

Member Avatar for vegaseat
0
113
Member Avatar for mickeyVeliki

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 …

Member Avatar for vegaseat
0
280
Member Avatar for nUmbdA

Hint ... start = 7 # this will count r from start down to 0 for r in range(start, -1, -1): print(r)

Member Avatar for snippsat
0
118
Member Avatar for gtsreddy

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

Member Avatar for vijayan121
0
718
Member Avatar for vegaseat

I am exploring some of the PySide (PyQT public) widgets like the combo box, and how colors are applied ...

2
2K
Member Avatar for vegaseat

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?

Member Avatar for LastMitch
0
120
Member Avatar for vegaseat

This Python code shows you how to get a current list of currency values (Canadian Dollar = 1.00) via the internet.

Member Avatar for TrustyTony
0
493
Member Avatar for MissAuditore

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 …

Member Avatar for vegaseat
0
860
Member Avatar for cruze098
Member Avatar for bintony.ma

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 …

Member Avatar for bintony.ma_1
0
466
Member Avatar for techyworld

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.

Member Avatar for vegaseat
0
278
Member Avatar for techyworld

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()

Member Avatar for TrustyTony
0
168
Member Avatar for krystosan

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 …

Member Avatar for krystosan
0
192
Member Avatar for chao.lee.927

Take a look at: http://www.daniweb.com/software-development/python/code/435852/a-simple-pyside-digital-clock

Member Avatar for chao.lee.927
0
394
Member Avatar for krystosan

Try cmds.button(l="Connect to Selected",command='self.selCon') I wouldn't use l it looks to much like a number 1

Member Avatar for vegaseat
0
285
Member Avatar for hotblink

If you really want 4.18 you can try ... p = 4.1895030939393 print(round(p-0.005, 2))

Member Avatar for TrustyTony
0
201
Member Avatar for kisseric

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 …

Member Avatar for manujkathuria
-4
1K
Member Avatar for GrimJack
Member Avatar for TrustyTony

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

Member Avatar for vegaseat
0
252
Member Avatar for Xantipius
Member Avatar for Xantipius
0
187
Member Avatar for Patrick.Barklem

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 …

Member Avatar for vegaseat
0
161
Member Avatar for sainitin
Member Avatar for hotblink
Member Avatar for ejohnson

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 …

Member Avatar for vegaseat
0
503
Member Avatar for littleEuler

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 …

Member Avatar for hughesadam_87
0
110
Member Avatar for jim.lindberg1

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 …

Member Avatar for hughesadam_87
0
138
Member Avatar for lewashby
Member Avatar for ~s.o.s~
0
146
Member Avatar for TheSkunkMan
Member Avatar for alexpinho98
0
3K
Member Avatar for toyotajon93

If your data is read from a text file, your lines are strings even though they look like lists. Lardmeister's advice is good.

Member Avatar for vegaseat
0
196
Member Avatar for lewashby

Your "Head First" book must be using code for Python3. It might be worthwhile to install that version of Python.

Member Avatar for lewashby
0
202

The End.