904 Posted Topics
Re: You need to give more details of what you want to accomplish. At first look, there are quite a few errors in your code. Your indentations are a mess (they are not cosmetic, they actually form statement blocks in Python!), if needs == as comparison operator, for needs colon at … | |
Re: Indentations are the bread and butter of Python. Yours are all messed up! Did you mix tabs and spaces in your code? Avoid the mix! This is corrected code: [code]def get_colocations(filename): sentences = open(filename).read().split("\n") colocations = [] for sent in sentences: colocations.append(sent) return colocations def main(): colocations = get_colocations("colocations.txt") # … | |
Re: The module subprocess is new in Python24 and is much more reliable than os.system(). You may have to give the full path of file "ps2pdf" and file "file.ps" (eg. "/tmp/test/file.ps"). [code]import subprocess subprocess.call(["ps2pdf", "file.ps", "file.pdf"]) [/code] Note that subprocess.call() takes a list. | |
Re: All statement lines that belong to while loop get an indentation of 4 spaces (4 is traditional with Python code). I have removed main() as that is throwback to C. Also wrap your code in code tags,see: [url]http://www.daniweb.com/techtalkforums/announcement114-3.html[/url] [code]print "This program calculates how long it takes for an investment to … | |
Re: I don't have linux OS on my machine, but fail to understand why wxPython should bring up a gtk error? Also, is gdk and gtk a mix up? Please use code tags around your Python code to show proper indentations, take a look here: [url]http://www.daniweb.com/techtalkforums/announcement114-3.html[/url] | |
Re: Hi Ene, looks like you are working on Friday the 13th project. It took me a while, but I solved it. I can give you a hint, replace the line [code] print next_day [/code] with this expanded line [code] print next_day, "day of week =", next_day.weekday() [/code] The week starts … | |
Re: [QUOTE=Ene Uran]... Also, why are you using self.button1 = Button( ... ) and not just button1 = Button( ... )?[/QUOTE] The self. prefix makes the button global within the class, so it can be used by methods of the class. | |
Re: [QUOTE=Confucius]Im sort of new to python, and I have been looking at some tutorials, manuals, etc. and I saw how to find prime numbers, so I thought it would be a good place to start, so I added some stuff to hopefully allow for user input, and it doesnt work. … | |
Re: I can not quite figure out what you want to do. I wrote these little test files. Test1.py contains a variable I want to use in Testing1.py. Test1.py: [code]# test module, save as test1.py test_path = "test1234" [/code] Testing1.py: [code]# testing module test1.py import test1 print test1.test_path [/code] I am … | |
Re: Learn several languages. You may want to learn one language that runs on more than just Microsoft platform. | |
Re: Looks more like message from lint-filter, telling you to use self. Some of the commercial IDEs have filters built in. | |
Re: Try this short Tkinter code, only tested it on Windows XP: [code]from Tkinter import * root = Tk() sw = root.winfo_screenwidth() sh = root.winfo_screenheight() # test print "screen width =", sw print "screen height =", sh # set to full screen use this: root.geometry("%dx%d+0+0" % (sw, sh)) # more code … | |
Re: Use the while loop for indeterminate number of entries, for loop for fixed number. If you need to use main(), define main to call your calc_sum function. Let the user know how to stop the loop. [CODE]# while loop is used to sum an indeterminate number of integers entered, until … | |
Re: Very nice effort, just a a few corrections needed to make this work. [code]# class.py # tpm # A program to calculate the volume and surface area of a sphere from its # radius given as input. from math import * # for pi class Sphere: def __init__(self, radius): # … | |
Re: Found code in one of the books in the CS library: [code]# view and delete e-mail using the POP3 protocol import sys, getpass, poplib, re # change according to your needs POPHOST = "pop.domain.com" POPUSER = "joedoe" POPPASS = "" # the number of message body lines to retrieve MAXLINES … | |
Re: Once more, please put your code into code tags to show the right indentation, see: [url]http://www.daniweb.com/techtalkforums/announcement114-3.html[/url] Most people will not read any of your code unless you do that! Your first program worked just fine, why did you change it? This program will give you error, because you are giving … | |
Re: Python lambda can substitute, just harder to read: [code]tuple1 = ('\t', '\n') for k in range(100): a = (k % 10 == 9) b = 1 c = 0 # similar to C conditional expression a ? b : c # if a is true return b else c f … | |
Re: There is no module called graphics in normal Python distribution! Without this custom module will be hard to help! I suggest you print p1 and see what it looks like! If it is tuple like (30, 45), then most likely p1x = p1[0]. | |
Re: Since your discount is calculated from the total purchase, you do not need to ask for it. Discount calculations are done using conditional if statements. Do not use % as a variable name! All calculations are simple, no need for "from math import *" | |
Re: I and some of my friends left project ideas on [url]http://www.daniweb.com/techtalkforums/thread32007.html[/url] They can appply to any computer language! | |
I need to know how many times my function has been accessed in my program. Any suggestions other than global variable? | |
Re: G-Do, you and vegaseat seem to share fascination with midi music files. I have explored vegaseat's code snippet [url]http://www.daniweb.com/code/snippet431.html[/url] and it work well at least on Windows XP. Midi is great stuff! I am thinking that pythonmidi is the same package as PMIDI, at least the files/directories are the same. | |
Re: Please wrap you code in code tags, see: [url]http://www.daniweb.com/techtalkforums/announcement114-3.html[/url] This way the proper indentations are added. I would not pass function on as argument, so rewrite you code: [code]from math import * # to get pi def main(): # first get the area of the whole pizza area = area_of_pizza() … | |
Re: I am here to use the Linux OS on my computer. Was Linux really called Freax originally? | |
This small program is neat: [CODE]import calendar calendar.prmonth(2006, 3) """ March 2006 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 … | |
Re: I would learn C++ to get used to an oops language. Java is simple lame version of C++ anyway! | |
Re: I knew I was in trouble when doctor dentist took many pictures during surgery, so it would make it harder to sue him afterwards! I smile anyway, at least on Halloween! | |
Re: If you exclude number 2, and start you for loop with 3, you need to check only odd numbers, increment you for loop by 2. | |
Re: Sounds more like Ancient's wife has him broke in! Happy coding! | |
Re: Here is simplified approach, the number of new-line characters '\n' give number of lines, the number of spaces are approximately the number of words, and the number of characters is the length of the text string read from file. You simply use a for loop and and iterate each character … | |
Re: There is something like in a C code snippet here: [url]http://www.daniweb.com/code/snippet377.html[/url] | |
Re: You mean something like that: [code]import tkFileDialog # examples: def open_it(): filename = tkFileDialog.askopenfilename() print filename # test def save_it(): filename = tkFileDialog.askopenfilename() print filename # test def save_as(): filename = tkFileDialog.asksaveasfilename() print filename # test [/code] | |
I am making progress learning Python. and English. I understands tuples, lists and dictionaries, but sets don't make muchly sense. Why use a set? What is a set good for? | |
Re: You can write much more clean code if you start with Python over again. VB code is usually just to "helter skelter"! Look at your application and rewrite it in Python. | |
Re: There is also Glade IDE for Pygtk toolkit and something called PyCard. | |
Re: I hope you are talking about Tkinter as GUI. This code might help you. You have to use a if statements to get the right key value to go to the proper function then. [code]# bind and show a key event with Tkinter from Tkinter import * root = Tk() … | |
Re: Working with SQL I found this site. It may help! [url]http://www.mayukhbose.com/python/ado/index.php[/url] | |
Re: Something like this works fine: [code]try: case = int(raw_input("enter a number less then 3 or more than 4: ")) except: case = 0 while case <=2 or case >=5: # do something to get out of loop case += 1 print case if case > 10: break [/code] Notice that … | |
I am trying things with wxStaticText (a label). I can chnage background colour, but not the text colour: [code]import wx class MyPanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) str1 = "Camembert cheese is the best!" self.label1 = wx.StaticText(self, -1, str1 , wx.Point(15, 30)) self.label2 = wx.StaticText(self, -1, str1 , … | |
Re: A friend of me says that you can play mp3, mid and ogg files with Pygame but you need extra install modules for SDLs. | |
The Internet has many animated GIF files, they are funny to watch. Does Python have a way to play those? I am asking to much? | |
A somewhat strange find in the Pyton Code Snippets here on this site. Is the BOO language very much like Python? It seems nice that one can compile and interpret the same language. Will it be worth to translate Python code to BOO just to get a nice small exe … | |
I did find the Python code snippet on PMIDI module here. It works fine and I have made some interesting sounds with it. Is there way to save this as sound file? | |
Re: [QUOTE=jim mcnamara]factorials get BIG really fast and exceed the limits of 32-bit unsigned integer variables by 13!. If you want to play with them use a datatype that can handle huge numbers, or switch to an extended precision mathematics library like GMP.[/QUOTE] Or use Ruby or Python that do not … | |
Re: A good idea for a developing country which has lots of powerlines already but not much highspeed cables. Places like India, China, Russia, South Africa and such. Imagine all these poor people exposed to spyware and idiot popups! | |
Is there a function in wxPython or anything that can creat a variable frequency sounds? | |
Re: Nice project c_shaft05 you do much thinking here! |
The End.