904 Posted Topics
Re: You are using the Python shell. [code]>>> f = open ('myflie.txt', 'w') >>> f.write ('12345') 5 [/code]The Python shell is for testing of short code ideas. Use the editor to write programs. | |
Re: range(n+1) by default goes from zero to n in steps of one | |
Re: Here is example code: [code]import base64 # pick sound file you have in working directory # or give full path sound_file = "original.mp3" # use mode = "rb" to read binary file fin = open(sound_file, "rb") binary_data = fin.read() fin.close() # encode binary to base64 string (printable) b64_data = base64.b64encode(binary_data) … | |
Re: [code]d1 = {'a': 1, 'bc': 2, 'def': 3, 'gh': 4, 'ijkl': 5} # make shallow copy of d and process the copy d2 = d1.copy() for key in d1.keys(): if len(key) < 3: del d2[key] print(d1) # {'a': 1, 'ijkl': 5, 'gh': 4, 'def': 3, 'bc': 2} print(d2) # {'ijkl': … | |
Re: Wow, I can't barely wait till [B]Python Coding Help Pt 3 [/B] cames around! | |
Re: If variables inside functions wouldn't be local, any code would be just loaded with hard to trace bugs! | |
Re: Very interesting homework problem. Note about your code: [B]input[/B] is Python function name and should not be used for variable name, also use open() rather then file(). Function file() has been removed in Python3. | |
Re: Sorry, module graphics.py does not work with module PIL! You can only use [B].gif[/B] image files. | |
[code]#Blast workbench using biopython from Bio.Blast import NCBIWWW ##result_handle = NCBIWWW.qblast("blastn", "nr", "8332116") fasta_string = "AATTCAGTGGCAAAAAAAAAACTCAAATTTTAGGGAAGGCCCTAATATTATCAAATAATTAGAGGGGGGG" result_handle = NCBIWWW.qblast("blastn", "nt", fasta_string) save_file = open("my_blast.xml", "w") save_file.write(result_handle.read()) save_file.close() result_handle.close() result_handle = open("my_blast.xml") from Bio.Blast import NCBIXML for record in NCBIXML.parse(open("my_blast.xml")) : #We want to ignore any queries with no search results: … | |
Re: One way to look at this problem: [code]class Test(object): def __init__(self, var1=123): self.var1 = var1 def show(self): print(self.var1) class Test2(Test): # create self def __init__(self): # make inherited class Test part of self Test.__init__(self) self.show() # 123 self.var1 = 777 self.show() # 777 t2 = Test2() [/code] | |
Re: The title has nothing to do with the homework, but it gets the attention and fools the teacher. Clever? | |
I am starting to play around with IronPython, but I can't figure out how to convert any code to executable file that will run on Windows. There has got to be some kind of batch file. | |
Re: Nobody will do your homework, you got show some effort and some ideas how you want to solve this. | |
Re: The rounding is done in your display function. Here is C example: [code]// percent calculation, wants 100 * 90/235 --> 38.3 % #include <stdio.h> double CalculatePercentage(double TotalComponent, double PartialComponent) { return 100*PartialComponent/TotalComponent; } int main() { printf("100 * 90/235 --> %0.1f%c", CalculatePercentage(235, 90), '%'); getchar(); // wait for key press … | |
Many new computers come with Windows7(64bit) OS. You will be tempted to install something like Python 3.1.1 64bit version. However, many packages like PyQT and PyGame don't offer 64bit versions yet and will not work! | |
Re: Really Pythonic (elegant) ... [code]mylist = [ '192.168.255.1 00:01:02', '172.14.0.1 00:0f:01', '172.14.0.2 00:0f:01', '172.14.0.3 00:0f:01' '172.14.0.4 01:ff:dd:34', '192.168.255.3 00:dd:01:ff' ] # your exclude substring exclude = '172.14' newlist = [item for item in mylist if not item.startswith(exclude)] print(newlist) """output --> ['192.168.255.1 00:01:02', '192.168.255.3 00:dd:01:ff'] """ [/code] | |
Re: I have Python 3.1 installed in my XP machine and use PyScripter (Windows executable written with Delphi) or the Geany IDE. For Python 2.5 I use Portable Python 2.5.4 that does not interfere with the installed Python 3.1 and that comes with the wonderful SPE IDE. SPE uses some great … | |
![]() | Re: Recursive function can replace the while loop, but while loop is more efficient and faster. |
Re: [code]# Python3 only tup = (1, 2, 3, 4) tup_bin = tuple(bin(n) for n in tup) print(tup_bin) """output --> ('0b1', '0b10', '0b11', '0b100') """ [/code] | |
Re: This would be example from one of the tutorials: [code]# Tkinter top-level menus from Tkinter import * from tkMessageBox import * # temporary function to call from menu def notdone(): showerror('Not yet', 'Work in progress!') def makemenu(win): top = Menu(win) win.config(menu=top) file = Menu(top) file.add_command(label='New...', command=notdone, underline=0) file.add_command(label='Open...',command=notdone, underline=0) file.add_command(label='Quit', … | |
Re: There's one big, big difference between 'VernonDozier' and 'jwenting.' | |
Re: [B]Lardmeister:[/B] One real rebel, too smart for his age, almost scary. The 'meister' of debating with little tolerance for ignorant folks, will cut the lard out! I really enjoy his wit. | |
Re: I started the year with a miserable cold. 'FFFFFuuuuuu!' is correct, but remember that if it isn't life threading, it isn't much to worry about. Let's just hope that all your other days are getting better this year. | |
Re: Just one nice French word (in the US it may be called Liberty word) translated as: lacking social grace, sensitivity, or acuteness; awkward; crude; tactless. Take your pick! I feel sorry for all the programmers that use [B]if condition==true[/B], as they are tactless and crude people lacking social grace! All … | |
Re: People like to be popular, why not their password? I use only popular words like [B]racecar[/B] and spell them in reverse. :) | |
Re: Note that kg and pound are weight units of measurement. Gallon and liter are volume units of measurement. Don't mix them! You can use this code: [code]kg = float(raw_input("Enter number of kg: ")) lb = kg * 2.205 print kg, "kg =", lb, "pounds" [/code] Or you can use this … | |
Re: And the error you are getting is? | |
Re: There is indentation error. Also, put in some test prints to see what you get. | |
Re: Well, this should give you some hints, look at this code: [url]http://www.daniweb.com/forums/post1111987.html#post1111987[/url] | |
Re: What's [B]key[/B]? Avoid using [B]sum[/B] since it is Python function, could get you into trouble later. | |
Re: Mawe sure knows how to keep it simple and elegant! Here is my contribution to mawe's original horizontal bar graph, I added one line of actual data value markers to the end, still simple: [code]data = [20, 15, 10, 7, 5, 4, 3, 2, 1, 1, 0] # pad each … | |
Re: You know you are complete computer geek when you like Google's new language [B]Go.[/B] | |
Re: [QUOTE=jbennet;1010987]It assume it to be written in a mix of C and Assemb ly code[/QUOTE]I think this is correct, because as my father explained to me, in those days C compilers had the inline assembly language option. This allowed access to the very low levels of the computer chips. | |
Re: What is your error message? | |
Re: Should be at least 1 kilometer in diameter before it's worth one Hollywood movie! | |
| |
Re: Don't use main the way it was written: [code] def main() : renamer(sys.argv[1]) main() [/code]It might call itself until the recursion limits are reached. Use it like this: [code] def main() : renamer(sys.argv[1]) main() [/code]Actually the best way to do this is as follows: [code=python] import os,shutil def renamer(target) : … | |
Re: Looking at your code you have quite a nightmare of errors in there and on top of that the all important indentations are all screwed up. !) use the customary 4 space indentations, avoid tabs!!!! 2) you set n = 0 before you use it in range() 3) you ask … | |
Re: Your area formula for regular polygons should be: [code] area = ((length**2) * numSides)/(4 * (math.tan(math.pi/numSides))) [/code]Your result will be square units of whatever units of measurement your sides are. You cannot get degrees for the area! | |
Re: Are you usng Python2 or Python3? Are your positive numbers integers or floats? | |
Re: Went to the Boo code snipet here on this site. Downloaded BOO from recomended site and a nice editor/IDE called Boodle (hehe). The snipet works well and seems fun. | |
Re: You can include coordinate z into your key tuple by simply expanding vegaseat's code: [code=python]# create a large number of spheres referencing them # with a (x, y, z):sphere_object dictionary pair import visual as vs spheres = {} for x in range (0, 100): for y in range (0, 100): … | |
Re: Vegaseat left this ttk code somewhere showing you the way module ttk should be imported and applied: [code]# exploring the Tkinter expansion module ttk notebook # tested with Python 3.1 and Tkinter 8.5 by vegaseat import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() # use width x … | |
Re: Be aware that Python25 and Python26 use different MS C compilers and so do the modules they use. The C code syntax has to match these compilers, as they are not compatible. | |
Re: Climb in the hot tub (green water or not) with one good glass of wine in the hand and some aromatic candles on the edge. Happy birthdays! | |
The End.