4,305 Posted Topics

Member Avatar for gsingh2011

I got it to work simply giving the full path of the font file ... [code]font = pygame.font.Font("C:/Windows/Fonts/comic.TTF", 30) [/code]For py2exe and pygame I often use this modified script ... [code=python]# py2exe setup program for pygame # many options removed, no custom icon # tested with Python25 by vegaseat from …

Member Avatar for Arthurharr
0
247
Member Avatar for tomtetlaw

[code=python]mylist = [['map2', '2'], ['map1', '1'], ['map3', '3']] # by default sorts by item in index 0 of the sublists print(sorted(mylist)) """ my output --> [['map1', '1'], ['map2', '2'], ['map3', '3']] """ [/code]

Member Avatar for woooee
0
144
Member Avatar for ofranko

Actually Snee left this note somewhere: [QUOTE]I found a mildly more sensible solution to running simple Python files on NetBeans 6.5 --> Create a new project, save it in a recognizable location and run it. Now you can create individual Python files and save them in the new project source …

Member Avatar for vegaseat
0
110
Member Avatar for daviddoria

Sorry for being so slow! Here it goes, I hope you can follow me on Linux: Create a directory let's say 'MyModules' in a path that Python normally looks at. Then create a module and file it in the MyModules directory... [code=python]# save this as module1.py (file/module name is case …

Member Avatar for vegaseat
0
2K
Member Avatar for ithelp

I moved this post into its own thread from the "Projects for the Beginner" sticky because of this rule violation: [QUOTE]If you know a good project, please post it here. If you have questions, start your own thread and don't clutter the sticky. [/QUOTE] In my opinion, Jython was created …

Member Avatar for jlm699
0
110
Member Avatar for ning2009

You can download module scipy that has all sorts of highly speed optimized functions used in science. Take a short look at the tutorial for scipy at: [url]http://www.scipy.org/Wiki/Documentation?action=AttachFile&do=get&target=scipy_tutorial.pdf[/url] Scipy needs another module called numpy, The downloads are free from: [url]http://www.scipy.org/Download[/url]

Member Avatar for ning2009
0
218
Member Avatar for xsxcn

The Python module pygame is a wrapper for SDL which in turn is written in C++. So there is a good chance that pygame can handle the task without resorting to using C++ directly.

Member Avatar for targ
0
162
Member Avatar for ofranko

You can also take a look at IronPython and SharpDevelop. It uses .NET or Mono and ties into the C# compiler.

Member Avatar for vegaseat
0
123
Member Avatar for Kekalove

Moved this question from the "Starting Python" Read Me Sticky. Reasons are the sticky rules: The idea of this thread is to help the beginning Python programmer with hints and helpful code. Please feel free to contribute! If you have any questions start your own thread!

Member Avatar for slate
-2
103
Member Avatar for GrimJack
Member Avatar for GrimJack
0
88
Member Avatar for scheda

wxPython works fine with Python25 on my Vista machine. To me wxPython fits the bill, it's easy to install, it's many widgets are powerful, and programs are easy to distribute using py2exe. On Windows pyGTK is scattered (GTK, pyGTK, pyCairo, pyGobject) and difficult to install, and the programs you write …

Member Avatar for vegaseat
0
138
Member Avatar for sumithar

First let's add a console wait so you can see the result before the console closes ... [code=python]import datetime import calendar no_of_days = int(raw_input('enter to number of days you want to add: ')) print no_of_days today = datetime.date.today() datethen = today + datetime.timedelta(days=no_of_days) print 'the answer is: ' , datethen …

Member Avatar for vegaseat
0
639
Member Avatar for vmars

The closest thing would probably be Shed Skin that translates Python code to rather ugly C++ code. See: [url]http://en.wikipedia.org/wiki/Shed_Skin[/url] A number of students have attempted a Python to C translator but failed because of the dynamic typing.

Member Avatar for Nine Tails
0
12K
Member Avatar for StarZ

It would be something like this ... [code=python]... while True: name = raw_input("Enter your name (or break to exit): ") if name == 'break': break else: # build up the temp string and end the name with a space temp += name + ' ' # same as: temp = …

Member Avatar for vegaseat
0
196
Member Avatar for hunterm

Your module image is propriatory, so it is very hard to test any code. I used the PIL module and Snee's idea and came up with these observations ... [code=python]# hide a short message in an image file (has to be .bmp or .png format) # .jpg and .gif formats …

Member Avatar for sneekula
0
3K
Member Avatar for badplasmid

Actually quite simple. After readfile.read() seek points to end of the file. You can reset seek to the beginning of the file by inserting: readfile.seek(0) right ofter line: listdata = readfile.read()

Member Avatar for badplasmid
0
98
Member Avatar for kenji

Proper Python code tags are ... [noparse][code=python][/noparse] your Python code here [noparse][/code][/noparse] A function within a function is very useful in functional programming and is commonly called a closure. When you define a function inside of another function, then any undefined local variable in the inner function will take the …

Member Avatar for vegaseat
0
136
Member Avatar for nflem

An often overlooked feature of Python is that you can format print directly from a dictionary ... [code=python]# using the local dictionary vars() to print variables name = "Harry" name2 = "Verderchi" for i in range(8): # %d for integers and %s for strings print "#%(i)d: %(name)s %(name2)s" % vars() …

Member Avatar for vegaseat
0
91
Member Avatar for serkan sendur

If you experienced the clumsiness of Windows Vista, Unix or Linux is a breath of fresh air! We need a book titled: "The Vista Haters' Handbook"

Member Avatar for serkan sendur
-1
418
Member Avatar for breatheasier

One nice way to create multidimensional arrays is to use the dictionary container, where the keys are the index tuples of the array ... [code=python]# create a 2D-array using a dictionary with index tuples as keys # initialize values to zero cols = 3 rows = 4 d = dict([((x,y), …

Member Avatar for vegaseat
0
269
Member Avatar for Joe Hart
Member Avatar for daviddoria

If you want to use module Numeric, replace it with the newer module numpy ... [code=python]# create an array of tuples using module numpy # module numpy historically evolved this way: # numeric --> numarray --> numpy import numpy as np rows = 3 cols = 5 # create a …

Member Avatar for vegaseat
0
103
Member Avatar for dinilkarun

Take a look at: [url]http://www.daniweb.com/forums/post666940-59.html[/url] Particular the line: self.SetColLabelValue(ix, title) where ix is the column number and title is the string you want for the header I think it will similar for the Row.

Member Avatar for vegaseat
0
107
Member Avatar for lorayyne

Did you save one of your own files named 'random.py' in the directory your coinflip test file is in? Python will look first in the working directory, and a common mistake for beginners is to give their files the name of Python modules.

Member Avatar for targ
0
214
Member Avatar for Undermine

I assume you are using the new Python3 version. The input() function replaces the old raw_input() function and returns a string. So follow vidaj's advice.

Member Avatar for Undermine
0
79
Member Avatar for Vihaio2012

Hot diggity dog! Another tab artist, must be the teacher! 'vidaj' gave you the answer with his repeat() function, use it. All you need to do is to rewrite the test print to match the older version of Python.

Member Avatar for vegaseat
0
112
Member Avatar for lorayyne

For heaven sake do us a favor and don't use tabs for your Python indentations. It makes code look ungainly! Use the standard 4 spaces as recommended in the Python style guide. I would love to highlight and copy your code to paste it into my editor for a quick …

Member Avatar for lorayyne
0
151
Member Avatar for nonang

In your code line: if l[index] < l[index + 1]: use: if l[index] [B][COLOR="Red"]>[/COLOR][/B] l[index + 1]: for ascending sort order. BTW, programmers avoid using the letter l for a variable name, since it looks so much like 1.

Member Avatar for vegaseat
0
163
Member Avatar for sneekula

In the news: Citicorp Bank just bought a new corporate jet for $50 million with some of their bailout money.

Member Avatar for vegaseat
0
255
Member Avatar for 136456

QT is a GUI (Graphics User Interface) toolkit and PyQT is the wrapper to make it work with the Python language. PyQT is not used much because of QT's inherent license problems. This might be the reason why there is little information on the internet. If you are new to …

Member Avatar for Ibn Saeed
0
269
Member Avatar for gbrokaw

Not sure if I get you correctly. IDLE is an IDE (editor) and not the Python interpreter. On Windows simply create a shortcut of your .pyw file and drag it onto the desktop.

Member Avatar for gbrokaw
0
137
Member Avatar for hunterm

I don't want to spoil your fun, but PIL has a flip method to create a mirror image ... [code=python]from PIL import Image img = Image.open("image.jpg") # flip the image around a vertical axis # for horizontal axis use: Image.FLIP_TOP_BOTTOM img_flipped = img.transpose(Image.FLIP_LEFT_RIGHT) img_flipped.show() [/code]

Member Avatar for hunterm
0
640
Member Avatar for sneekula

Hmm, partially employed and therefore partially unemployed, interesting! I think the US government's U-6 number is probably more realistic. Nevada's high local unemployment number of 11% has hit illegal aliens pretty hard. They are not part of that number.

Member Avatar for GrimJack
0
478
Member Avatar for jmil2

[QUOTE=adam1122;849790]A None value 3x3 matrix: [code=python][[None]*3]*3[/code] [code=python]def mlist(size): return [0] * size def mmatrix(rows,cols): return [mlist(cols)]*rows[/code][/QUOTE]This will give you a nasty surprise since you are forming a matrix of alias lists: [code=python]mx = [[None]*3]*3 print(mx) mx[1][1] = 7 print(mx) """ my output --> looks okay [[None, None, None], [None, None, …

Member Avatar for adam1122
0
8K
Member Avatar for ssn
Member Avatar for vegaseat
0
111
Member Avatar for max.yevs

Try this ... [code=python]import random n = 5 # list with unique elements print(random.sample(range(1, 11), n)) print('-'*20) # list with non-unique elements print([random.randint(1, 10)for k in range(n)]) """ my random output --> [1, 6, 3, 5, 10] -------------------- [5, 2, 6, 5, 9] """ [/code]

Member Avatar for max.yevs
0
128
Member Avatar for jworld2

Give this a try to include image files and all into one exe file ... [code=python]""" Py2ExeWinSetup.py Py2Exe (version 6.6 and higher) setup file for windows/GUI programs. Creates a single .exe file. Simply add this file into the same folder with the source file. Change your source filename at the …

Member Avatar for jworld2
0
133
Member Avatar for leegeorg07
Re: 2to3

I simply wrote a small Python program to run with Python30 to convert some of my Python25 files ... [code=python]# run_2to3_convert.py # # convert a Python25 code file to a Python30 code file # generates a backup file and overwrites the original # file with the converted file # # …

Member Avatar for leegeorg07
0
197
Member Avatar for txwooley

Python makes that easy ... [code=python]def cat_n_times(s, n): """print string s n times""" print s * n s = 'hello ' n = 3 cat_n_times(s, n) """ my result --> hello hello hello """ [/code]Somewhat more traditional ... [code=python]def cat_n_times(s, n): """print string s n times""" for count in range(n): …

Member Avatar for txwooley
0
105
Member Avatar for harrykokil

Here is one example ... [code=python]# explore Tkinter's Scale (slider) widget response import Tkinter as tk def show_position(value): """show slider position in the window title""" # you can use scale.get() or value s = "position = %s" % value root.title(s) root = tk.Tk() # use width x height + x_offset …

Member Avatar for vegaseat
0
108
Member Avatar for ithelp

Well. you could be doing an IT job in Iraq or Afghanistan. There the flying hamburger would be replaced by lead, shrapnel and sometimes body parts.

Member Avatar for debasisdas
1
151
Member Avatar for alicem

A jpeg file needs a header with all sorts of infomation in it. Also the image array itself is processed with a compression algorithm to make it as small as possible. You should be better off to go with a bitmap file. They are somewhat simpler. See: [url]http://en.wikipedia.org/wiki/BMP_file_format[/url]

Member Avatar for vegaseat
0
172
Member Avatar for harrykokil

Using a GUI would allow you to use buttons to start and stop your stopwatch. Here is a very basic Tkinter GUI example ... [code=python]# a very simple stopwatch using Tkinter # with Python30 replace Tkinter with tkinter import Tkinter as tk import time def start(): global count_flag count_flag = …

Member Avatar for harrykokil
0
1K
Member Avatar for Ancient Dragon

[QUOTE=ahihihi...;819869]sorry I've posted on the wrong thread..[/QUOTE]Now that is proof of evolution!

Member Avatar for GrimJack
0
1K
Member Avatar for skhan23

Get yourself familiar with True and False, and how they apply to AND, OR and NOT (Boolean Algebra). See: [url]http://www.play-hookey.com/digital/boolean_algebra.html[/url]

Member Avatar for adam1122
0
102
Member Avatar for Rick3414

Here is one way to do this sort of thing ... [code=python]# name, address, phone data processing data = """\ Carl Arm, 123 Malt Rd Carlson MO, 712-123-4567 Frank Fern, 21 S. West St Blippo CA, 901-321-7654 Mimi Mink, 13 Arbor St Draft NY, 204-777-9631""" filename = 'MyAddBook.txt' # create …

Member Avatar for vegaseat
0
118
Member Avatar for mangotango

You use if __name__=='__main__': only if you want to test your code as a standalone module.

Member Avatar for sneekula
0
857
Member Avatar for thehivetyrant

Hint: Recursive functions call themselves, basically form a loop Your function definition should look like: def summer(n, mysum=0): You are summing from the top down. Each recursion you add n to mysum and decrease n by 1. So your recursive call becomes return summer(n-1, mysum+n) You loop until n drops …

Member Avatar for thehivetyrant
0
127
Member Avatar for gotm

A matter of coding style: Please use 4 spaces rather than tabs for your indentations. It's pretty much the standard. Using tabs will get you into real problems sooner or later. For me its very tough to check your code since my editor is set for the customary spaces. One …

Member Avatar for woooee
0
96
Member Avatar for JeyC

Run an external program from within Python code with subprocess.call(["program-name", "arg1", "arg2"]) rather than os.system("program-name arg1 arg2"), since os.system() does not allow the Python program to run in the background, whereas subprocess does.

Member Avatar for woooee
0
119

The End.