904 Posted Topics

Member Avatar for jellyworms

Added few more hints to slate's code: import urllib2, re from bs4 import BeautifulSoup url = 'http://www.indexmundi.com/factbook/regions' response = urllib2.urlopen(url).read() soup = BeautifulSoup(response) row = soup.findAll('li') # create a dictionary of region:regionname pairs region_dict = {} for link in row: href = link.find('a')['href'] url = "http://www.indexmundi.com" countryurl = url + …

Member Avatar for bumsfeld
2
287
Member Avatar for nytman

Your individual lists have to line up properly to match name and data: name = ['Frank', 'Bill'] salary = [1234.0, 1535.0] remark = [3, 2] employee_list = zip(name, salary, remark) print(employee_list) ''' [('Frank', 1234.0, 3), ('Bill', 1535.0, 2)] ''' # sort by remark which is at tuple index 2 employee_list_sorted …

Member Avatar for nytman
0
1K
Member Avatar for rsewak

According to the prohibitionists here, **bear** would be better than **beer**.

Member Avatar for TonyG_cyprus
0
740
Member Avatar for roshu10

Another option is to use FMOD: http://www.fmod.org/fmod-downloads.html#FMODStudio Or check out: http://www.portaudio.com/ Generally, your GUI toolkits like QT have audio play functions.

Member Avatar for Moschops
0
374
Member Avatar for kay19
Member Avatar for Akshay nand
Member Avatar for otto531

Sets will be ordered by hash order, so you loose the relationship of word and frequency data. It could be easier to use collections.Counter() on each of your text files and go from there.

Member Avatar for bumsfeld
0
312
Member Avatar for robert99x
Member Avatar for vegaseat
0
313
Member Avatar for flebber
Member Avatar for The Dude

Standing in the middle of the road is very dangerous; you get knocked down by the traffic from both sides.

Member Avatar for Ene Uran
9
4K
Member Avatar for Octet
Member Avatar for bumsfeld

This shows the code for one simple crypt of text by swapping two adjoining characters each. You can make that more complex if you like. Can also be used for one nice riddle.

Member Avatar for bumsfeld
2
630
Member Avatar for bumsfeld
Member Avatar for Umar Suleman
3
410
Member Avatar for Lardmeister

I think we are missing the invasion by a outerspace intelligence that by poor choice lands in Washington DC, and consequently looks at us as just one pest to be exterminated.

Member Avatar for sneekula
2
2K
Member Avatar for chris99

Chris, this approach would avoid the repetition of the room description and make the code shorter. Here is a test code: [code]gold = 0 gotGold_reading = 0 def reading_room(): global gold print " Current Gold = ",gold print " You are in a large reading room ..." rea_desc() #prompt_rea() def …

Member Avatar for Jacklittle01
0
1K
Member Avatar for GrimJack
Member Avatar for pato

Richard Gruet has very good quick-reference of Python on his home page: [url]http://rgruet.free.fr/[/url] The reference can be downloaded as HTML, zipped HTML or PDF file. It is in English.

Member Avatar for PythonHelper
0
1K
Member Avatar for vegaseat
Member Avatar for WolfShield

These two strings walk into a bar and sit down. The bartender says, "So what'll it be?" The first string says, "I think I'll have a beer quag fulk boorg jdkCjfdLk jk3s d#f67howeU r89nvyowmc63Dz x.xvcu" "Please excuse my friend," the second string says, "He isn't null-terminated."

Member Avatar for itzarun
0
1K
Member Avatar for sneekula
Member Avatar for Sanchixx
0
482
Member Avatar for Ancient Dragon

I guess they call them robo calls. You just sit down for dinner and the phone rings with some recorded message from a political group that wants you to vote for their special interest candidate. I agree with AD, those things are taking over the phone and are nasty.

Member Avatar for Ene Uran
1
189
Member Avatar for webstart

Just more complex since you also have tuples in your list. This may work: alist = [[], [(u'0.77',)], [(u'0.34',)], [(u'0.12',)], [(u'0',)], [(u'0.0',)], [(u'0',)]] value_list = [float(x[0][0]) for x in alist if x] print(value_list) ''' [0.77, 0.34, 0.12, 0.0, 0.0, 0.0] '''

Member Avatar for vegaseat
0
6K
Member Avatar for utkarshsahu

In most cases you can simply use the print() function, then it will work in both newer Python versions. Print rightfully should be a function and not a statement, this was corrected in the newer versions.

Member Avatar for utkarshsahu
0
175
Member Avatar for aquaben

In Python2 input() is for numbers and raw_input() is for strings. It is best to use raw_input() and then convert to a number using int() or float() since input() uses eval() internally and that can also excute commands. Some evil genius might whipe out your diskdrive this way. Short example: …

Member Avatar for woooee
0
106
Member Avatar for SpartanIE

Avoid using names like **list** and **sum** since they are internal to Python. Something like this will work: mylist = [] prompt = "%d) enter an integer (-99 to stop): " for k in range(1000): x = int(raw_input(prompt % (k+1))) if x == -99: break mylist.append(x) print(mylist) # test ''' …

Member Avatar for TrustyTony
0
2K
Member Avatar for gge18

Writing/showing/copying code seems to be made very difficult in the new DaniWeb format!

Member Avatar for vegaseat
0
147
Member Avatar for midnightparade

When you post, highlight your code and click on the code tab above, something like this: def add(x, y): return x+y print(add(2, 3))

Member Avatar for bumsfeld
0
227
Member Avatar for Sean Raina

Write a program that checks on a political candidates promisses and how many he/she keeps once elected.

Member Avatar for bumsfeld
0
60
Member Avatar for Ancient Dragon
Member Avatar for 909kidd

[code]from visual import* wallA = box(pos=vector(0,6,0), size=vector(12.1,0.2,12.1), color=color.red) wallB = box(pos=vector(0,-6,0), size=vector(12.1,0.2,12.1), color=color.green) wallC = box(pos=vector(6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow) wallD = box(pos=vector(-6,0,0), size=vector(0.2,12.1,12.1), color=color.yellow) wallE = box(pos=vector(0,0,-6), size=vector(12.1,12.1,0.2), color=color.yellow) ball=sphere(pos=vector(0,0,0), radius=0.20, color=color.white) ball.vel=vector(1.5,-.9,-1.9) vscale=3.0 dt=0.01 velarrow=arrow(pos=ball.pos, axis=ball.vel, color=color.blue) ball.trail=curve(pos=[ball.pos], color=color.white) t=0 scene.autoscale=false while t<10: rate(1/dt) t=t+dt if ((ball.pos.y-ball.radius+ball.vel.y*dt)<wallB.pos.y+0.5*wallB.height): ddt=(wallB.pos.y+0.5*wallB.height-ball.pos.y+ball.radius)/ball.vel.y ball.pos=ball.pos+ball.vel*ddt ball.trail.append(ball.pos) …

Member Avatar for HiHe
0
178
Member Avatar for Vkitor

You can also use a dictionary approach as this example shows: [code]# create multiple Tkinter buttons using a dictionary: import Tkinter as tk def text_update(animal): text.delete(0, tk.END) text.insert(0, animal) root = tk.Tk() text = tk.Entry(root, width=35, bg='yellow') text.grid(row=0, column=0, columnspan=5) btn_dict = {} col = 0 words = ["Dog", "Cat", …

Member Avatar for Gribouillis
0
23K
Member Avatar for Lucaci Andrew

Using the Tkinter GUI toolkit that comes with Python you can use the password option this way: [code]# Tkinter, explore the entry field for passwords! from Tkinter import * def showme(): # clear the label label2.config(text='') # get the enter1 text and display in label label2.config(text=enter1.get()) root = Tk() # …

Member Avatar for Lucaci Andrew
0
180
Member Avatar for rajendrakrp

It is never a good idea to change the same object you are iterating over in the loop. Simply create a new object and do the changes on that object.

Member Avatar for bumsfeld
0
102
Member Avatar for Dann0

You have to use the player instance and not the class name, also make player global since you create it in main(): [code]import pygame pygame.init() class Player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("evin.png") self.image = self.image.convert() tranColor = self.image.get_at((1, 1)) self.image.set_colorkey(tranColor) self.rect = self.image.get_rect() self.x = 300 self.y = 300 …

Member Avatar for Dann0
0
2K
Member Avatar for unigrad101

Before enumerate() came around, you would have incremented the index this way: [code]def count_data_types(a_list): answer = [0,0,0] for x in a_list: ind = 0 for t in (int, float, str): if t == type(x): answer[ind] += 1 ind += 1 return answer print(count_data_types(['v', 3.0,1, 'etc'])) ''' [1, 1, 2] ''' …

Member Avatar for bumsfeld
0
137
Member Avatar for sergent
Member Avatar for hystaspes
0
331
Member Avatar for Stefano Mtangoo

There is usually info in the MS-HTML-Help file wx.chm if wxPython does not have one particular feature. Also look at: [url]http://wiki.wxpython.org/index.cgi/FrontPage[/url] This is the API ref, very extensive: [url]http://prdownloads.sourceforge.net/wxpython/wxPython-newdocs-2.8.8.1.tar.bz2[/url]

Member Avatar for joryrferrell
0
124
Member Avatar for moroccanplaya

Here is example ... [code]# one look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to paste, and ctrl+/ to select all # text area can be scrolled with mouse wheel import Tkinter as tk root = tk.Tk() # create the …

Member Avatar for bumsfeld
0
226
Member Avatar for Lingson

One rude awakening with Python3 will be the frequent use of bytearrays instead of strings. It does this to handle international unicode better. Here is how you deal with this: [code=python]# get code of given URL as html text string # Python3 uses urllib.request.urlopen() # instead of Python2's urllib.urlopen() or …

Member Avatar for Rocketdlib
0
2K
Member Avatar for Azmah

[QUOTE=Ene Uran;1571839]6+2x10 is easy but I oftened wondered what 7+2x10 could be[/QUOTE]Very funny for someone from LA! We could make that into one good movie to beat 'Dumb and Dimmer'.

Member Avatar for BDove
0
2K
Member Avatar for MarkWalker84

Python has full set of binary operators, but I don't think there is one way to send bitstring to USB chip. Ultimately that is how data would travel in the serial wire.

Member Avatar for mr_snarf
0
2K
Member Avatar for vegaseat
Member Avatar for rysin

However, pyHook and pythoncom work only on Windows systems. Not too bad, since most computers in this world are using Windows. Tkinter is more cross-platform for the few odd folks that user other OS.

Member Avatar for TrustyTony
0
548
Member Avatar for thunderstorm98

[QUOTE=Ancient Dragon;467265]The description sounds like its a very nice celebration, but I'm a little werry about the above statement. There's a lot of people in this world that are just plain evil to the bone.[/QUOTE]Let the evil people have their own holiday and celebration! I like Diwali a lot better!

Member Avatar for ~s.o.s~
0
240
Member Avatar for Shanti C
Member Avatar for sneekula
Member Avatar for Netcode
0
674
Member Avatar for pseudorandom21
Member Avatar for sneekula

If you have a PC with Windows, you can use wxPython to read PDF files, check: [url]http://www.daniweb.com/code/snippet618.html[/url]

Member Avatar for rogerluz
0
282
Member Avatar for ithelp
Member Avatar for the1last

Vegaseat left this example of the difflib module somewhere in the code snippets: [code=python]# find the difference between two texts # tested with Python24 vegaseat 6/2/2005 import difflib text1 = """The World's Shortest Books: Human Rights Advances in China "My Plan to Find the Real Killers" by OJ Simpson "Strom …

Member Avatar for radk
0
16K

The End.