1,175 Posted Topics
There used to be a Python module called pyglet that allowed graphics and sound. I can't find it anywhere. | |
Re: Couldn't you simply do this: digits = '234' size = len(digits) sum_odd = 0 for ix in range(1, size, 2): sum_odd += int(digits[ix]) prod_even = 1 for ix in range(0, size, 2): prod_even *= int(digits[ix]) print("sum of odd indexed integers = {}". format(sum_odd)) print("product of even indexed integers = {}". … | |
I would like to break up a list into sublists of 3 elements each. I have this code, but it will give an index error when the length of the list is not divisible by 3. mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] … | |
Re: I think you highlightthe code and press the Code button on the grey bar on top. | |
Re: Here is a typical example: def funk(arg1, arg2, arg3): pass arg1 = 77 # call function with only one argument funk(arg1) ''' error --> Traceback (most recent call last): File "<module1>", line 5, in <module> TypeError: funk() takes exactly 3 arguments (1 given) ''' | |
Re: The newer Portable Python 2.7.6.1 package contains the following applications/libraries: PyScripter v2.5.3 PyCharm Community Edition 3.1.2 (Thanks to cebik) NymPy 1.8.1 SciPy 0.13.3 Matplotlib 1.3.1 PyWin32 218 Django 1.6.2 PIL 1.1.7 Py2Exe 0.6.9 wxPython 3.0.0.0 NetworkX 1.7 Lxml 3.3.4 PySerial 2.7 PyODBC 3.0.7 PyGame 1.9.1 PyGTK 2.24.2 PyQt 4.10.4 IPython … | |
I asked that in another thread, but it got lost: [QUOTE]When do you use root.quit() and when do you use root.destroy() to exit a Tkinter program?[/QUOTE] Also, can you intercept an exit when you use the little x in the title bar, just to affirm that you really want to … | |
Re: You can use this approach to get an input dialog without the Tkinter window: [code=python]# use Tkinter's dialogs to ask for input # dialogs are askfloat, askinteger, and askstring import Tkinter as tk from tkSimpleDialog import askstring root = tk.Tk() # show askstring dialog without the Tkinter window root.withdraw() name … | |
Re: To take care of the ever present binary roundoff error that is associated with floating point numbers (most any computer language) do this: [code=python] # compensate for the binary roundoff error while change >= (m - 0.001): [/code]In the matter of fact you can streamline your code to this: [code=python]# … | |
Re: Please use code tags for your code. You are getting close, but you need to find if the score is a new minimum or maximum each time through the loop. Something like this: [code=python]infile = open("test_scores.dat", "r") mylist = infile.readlines() infile.close() # remove the header, first item in the list … | |
Re: Old folks are just a drag on society. Putting up with them with about 25 years after retirement is generous enough. Making this 925 years would be insane. They are a major source of income for the medical profession now. | |
![]() | Re: Santa has no religious meaning. He is a jolly soul that represents gift giving, flying sleds and obesity. Let's name the whole thing Santaday. |
Re: I would use this approach, use whatever .gif file you have, sorry this is from my iPad and it does not work well with DaniWeb commands: ,,, display an image using Tkinter for Python2 ''' import Tkinter as tk root = tk.Tk() image_file = "Vacation2013.gif" photo = tk.PhotoImage(file=image_file) root.title(image_file) label … | |
Re: Majid, please do not hijack a thread with an unrelated question! | |
Re: The way it is coded it should work with Python2 or Python3. | |
Re: You might have set host initially to something that makes sense. | |
Re: [QUOTE=ZielonySBS;806195]I have a company scanner but very often people forget to remove scanned (confidencial documents) I want to create a script which will once day check a "/home/scanner" folder and if there are any files it moves them to my /home/Administrator folder. I dont really dont know how to start. … | |
Re: Looks like you managed to put 2 spaces ahead of of line 6. Python does not like that! | |
Re: Note that in Python3 the / division gives a float value, use integer division // | |
Re: If you have a PC, take the mouse and double click in the code. This will highlight the code. Now right click on the highlighted code and use copy from the pop up menu. If you have a touch pad like the iPad, you are plain out of luck! | |
Re: This code snippet is pretty stupid. If I could down vote it from my iPad, I would! | |
Re: [QUOTE=evstevemd;769472]Yeah, I understand! I wanted us to keep each other updated in case any module comes for python 3[/QUOTE]Nice idea! Will keep checking it for the next year or so. | |
Re: As an exercise you could create all those buttons in a loop. | |
Re: I wonder which beach you went to? | |
Re: You may want to help the user in case of an invalid integer entry. | |
Re: See: http://www.daniweb.com/software-development/python/threads/191210/python-gui-programming/6#post1246492 | |
Re: There are a number of functions that need integer arguments. | |
Re: Hint: # assume this is your data file (CSV type) # each line has last name, first name, grade data = '''\ Miller,Jean,75 Paulson,Peter,47 Tanner,Abraham,88 Norton,Sheila,33 ''' filename = "grades123.txt" # write a test file with open(filename, "w") as fout: fout.write(data) # now read your test file back in and … | |
Re: Wow, Grim is pretty good at answering tough questions. | |
Re: Here is an example how to use lambda to pass arguments in Tkinter's button command: [code=python]import Tkinter as tk def getCond(par): firstCond = par #conditions.remove(firstCond) print firstCond #print conditions root = tk.Tk() firstCond = '' condNames = ['1', '2', '3', '4', '5', '6'] for item in condNames: # use lambda … | |
Re: I though it was odd, but that 'bug' has been in there ever since Python26. | |
Re: Looks like Pillow is not available for Python3 | |
Re: You need to change your first data file format to something like this, where for instance the ';' character is the separator: A233;Apple;FOOD;5.00 A345;Blanck CD 10;DATA;2.50 B453;Pasta;FOOD;12.00 T545;USB-Memory 16GB;DATA;25 | |
Re: This might give you some hints: ''' file gemstone.csv looks like this: valid gemstone owing mark channels code No Diamond 26.06 20 218 (KJQ:10E)2 Yes Diamond 15.43 25 36 (DRX:25H)7 No Sapphire 11.44 51 141 (XKL:31L)4 No Zircon 79.68 23 60 (BYA:26Ix8 No Moonstone 79.41 11 67 (BWC:79L)4 Yes Garnet … | |
Re: One way to do this: def make_userid(user): first, last = user.split() user_id = first[0] + last return user_id user = "John Doe" user_id = make_userid(user) print(user_id) # JDoe | |
Re: You can use something like this: myvar.set("Current Folder Selected is: {}".format(dirname)) | |
Re: The factorial function is part of the math module in later versions of Python: ''' math_factorial.py tested with Python 2.7.3 ''' from math import factorial for k in range(1, 101): print("factorial of {} = {}".format(k, factorial(k))) print(type(factorial(10))) # <type 'int'> print(type(factorial(100))) # <type 'long'> print(len(str(factorial(100)))) # 158 print(len(str(factorial(69)))) # 99 | |
| |
Re: [QUOTE=Ene Uran;1060514]Sorry, I am using Python 3.1.1 and graphics.py does not work with Python3.[/QUOTE]This little module has been updated to work with Python2 and Python3 recently, look at the new beta version at: [url]http://mcsp.wartburg.edu/zelle/python/[/url] | |
Re: Dear Grandson Snee: I have become a little older since I saw you last, and a few changes have come into my life since then. Frankly, I have become a frivolous old gal. I am seeing five gentlemen everyday. As soon as I wake up, Will Power helps me get … | |
Re: Another option is to make a DailyExpenses.pth text file that contains the directory name where you can find the DailyExpenses.py file. You can save the path file in Python's "site-packages" directory. | |
Re: Are we talking about the earth? I have always looked at "world" as something larger than "earth". | |
Re: Mutation to a real chicken would happen in the egg, so the egg comes first. | |
Re: Portable Python (aka. Flashcard Python or Python on a stick) comes with PyScripter and that IDE is a pleasure to code with. Python is a great language to solve scientific problems. | |
Re: Note that wxPython is the Python wrapper for the C/C++ based wxWindows. |
The End.