4,305 Posted Topics
Re: 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 … | |
Re: [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] | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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] | |
Re: 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. | |
Re: You can also take a look at IronPython and SharpDevelop. It uses .NET or Mono and ties into the C# compiler. | |
Re: 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! | |
| |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 = … | |
Re: 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 … | |
Re: 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() | |
Re: 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 … | |
Re: 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() … | |
Re: 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" | |
Re: 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), … | |
| |
Re: 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 … | |
Re: 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. | |
Re: 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. | |
Re: 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. | |
Re: 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. | |
Re: 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 … | |
Re: 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. | |
Re: In the news: Citicorp Bank just bought a new corporate jet for $50 million with some of their bailout money. | |
Re: 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 … | |
Re: 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. | |
Re: 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] | |
Re: 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. | |
Re: [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, … | |
Re: This was moved from the Project for Beginners. Can anybody help? | |
Re: 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] | |
Re: 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 … | |
![]() | Re: 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 # # … ![]() |
Re: 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): … | |
Re: 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 … | |
Re: 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. | |
Re: 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] | |
Re: 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 = … | |
Re: [QUOTE=ahihihi...;819869]sorry I've posted on the wrong thread..[/QUOTE]Now that is proof of evolution! | |
Re: 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] | |
Re: 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 … | |
Re: You use if __name__=='__main__': only if you want to test your code as a standalone module. | |
Re: 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 … | |
Re: 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 … | |
Re: 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. |
The End.