904 Posted Topics

Member Avatar for n.utiu

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.

Member Avatar for n.utiu
0
83
Member Avatar for kjock002
Member Avatar for X-Boy

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) …

Member Avatar for bumsfeld
0
5K
Member Avatar for gunbuster363

[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': …

Member Avatar for gunbuster363
0
83
Member Avatar for the_mia_team
Member Avatar for the_mia_team
0
128
Member Avatar for deckchairboy

[B][COLOR="Green"]I fought the lawn and the lawn won[/COLOR][/B]

Member Avatar for bumsfeld
1
372
Member Avatar for Ronnicus

If variables inside functions wouldn't be local, any code would be just loaded with hard to trace bugs!

Member Avatar for bumsfeld
0
87
Member Avatar for Escom

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.

Member Avatar for dilbert_here00
0
172
Member Avatar for shusshoku

Sorry, module graphics.py does not work with module PIL! You can only use [B].gif[/B] image files.

Member Avatar for bumsfeld
0
74
Member Avatar for bumsfeld

[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: …

0
333
Member Avatar for ultimatebuster

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]

Member Avatar for bumsfeld
0
100
Member Avatar for qwertyui

The title has nothing to do with the homework, but it gets the attention and fools the teacher. Clever?

Member Avatar for woooee
0
175
Member Avatar for bumsfeld

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.

Member Avatar for jcao219
0
187
Member Avatar for prashanth s j

Nobody will do your homework, you got show some effort and some ideas how you want to solve this.

Member Avatar for bumsfeld
0
98
Member Avatar for vbcielle

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 …

Member Avatar for WaltP
0
211
Member Avatar for bumsfeld

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!

Member Avatar for Alq Veers
1
487
Member Avatar for ab_too

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]

Member Avatar for ab_too
0
717
Member Avatar for Clueless86

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 …

Member Avatar for Stefano Mtangoo
0
323
Member Avatar for soUPERMan

Recursive function can replace the while loop, but while loop is more efficient and faster.

Member Avatar for willygstyle
0
1K
Member Avatar for Whoever90

[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]

Member Avatar for bumsfeld
0
79
Member Avatar for katharnakh

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', …

Member Avatar for skydiverman05
0
4K
Member Avatar for lrh9
Member Avatar for Narue

[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.

Member Avatar for jonsca
2
514
Member Avatar for Nick Evan

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.

Member Avatar for apegram
0
295
Member Avatar for ~s.o.s~
Member Avatar for vmanes

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 …

Member Avatar for ddanbe
1
334
Member Avatar for Salem

People like to be popular, why not their password? I use only popular words like [B]racecar[/B] and spell them in reverse. :)

Member Avatar for PedroStephano
0
707
Member Avatar for sindhujavenkat
Member Avatar for htrantk

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 …

Member Avatar for htrantk
0
3K
Member Avatar for cascade3891
Member Avatar for evilweasel_47

There is indentation error. Also, put in some test prints to see what you get.

Member Avatar for woooee
0
109
Member Avatar for BirdaoGwra

Well, this should give you some hints, look at this code: [url]http://www.daniweb.com/forums/post1111987.html#post1111987[/url]

Member Avatar for BirdaoGwra
0
2K
Member Avatar for calccrypto

What's [B]key[/B]? Avoid using [B]sum[/B] since it is Python function, could get you into trouble later.

Member Avatar for calccrypto
0
108
Member Avatar for sneekula

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 …

Member Avatar for Stefano Mtangoo
0
562
Member Avatar for mrnutty

You know you are complete computer geek when you like Google's new language [B]Go.[/B]

Member Avatar for mrnutty
1
329
Member Avatar for sneekula

[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.

Member Avatar for gelgin2k
3
593
Member Avatar for Cornholio
Member Avatar for ithelp

Should be at least 1 kilometer in diameter before it's worth one Hollywood movie!

Member Avatar for vegaseat
0
137
Member Avatar for The Dude
Member Avatar for Ancient Dragon
Member Avatar for vegaseat
1
426
Member Avatar for k1w1dad

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) : …

Member Avatar for Gribouillis
0
206
Member Avatar for kleigh

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 …

Member Avatar for kleigh
0
3K
Member Avatar for scrace89

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!

Member Avatar for vegaseat
0
121
Member Avatar for sanchitgarg
Member Avatar for sanchitgarg
0
86
Member Avatar for Dark_Omen

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.

Member Avatar for pkc
0
426
Member Avatar for Vector_Joe

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): …

Member Avatar for bumsfeld
0
854
Member Avatar for mahela007

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 …

Member Avatar for bumsfeld
0
144
Member Avatar for Tech B

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.

Member Avatar for bumsfeld
0
541
Member Avatar for Dani

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!

Member Avatar for AndreRet
1
431
Member Avatar for lllllIllIlllI

The End.