904 Posted Topics
Re: 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 + … | |
Re: 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 … | |
Re: According to the prohibitionists here, **bear** would be better than **beer**. | |
Re: 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. | |
Re: What concept of physics are you basing your program on? | |
Re: 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. | |
Re: The 64 bit Python version does not work with 32 bit third party modules. | |
Re: You need to check the effects of sample size. | |
Re: Standing in the middle of the road is very dangerous; you get knocked down by the traffic from both sides. | |
| |
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. | |
There seems to be many ways to create a dictionary, which one do you prefer? | |
Re: 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. | |
Re: 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 … | |
| |
Re: 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. | |
| |
Re: 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." | |
Re: I would say C++ gets the youngsters used to the rigors of programming. | |
Re: 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. | |
Re: 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] ''' | |
Re: 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. | |
Re: 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: … | |
Re: 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 ''' … | |
Re: Writing/showing/copying code seems to be made very difficult in the new DaniWeb format! | |
Re: 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)) | |
Re: Write a program that checks on a political candidates promisses and how many he/she keeps once elected. | |
Re: [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) … | |
Re: 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", … | |
Re: 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() # … | |
Re: 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. | |
Re: 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 … | |
Re: 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] ''' … | |
Re: I like Editra, works great for a number of programming languages. | |
Re: 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] | |
Re: 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 … | |
Re: 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 … | |
Re: [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'. | |
Re: 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. | |
Re: 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. | |
![]() | Re: [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! |
Re: When your girlfriend thinks you are one computer genius. | |
Re: 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] | |
| |
Re: 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 … |
The End.