880 Posted Topics

Member Avatar for sravi.pearl

It tok my 5sek to display result in notepad ctrl-c and ctrl-v. So to the question why to you need to display source code in notepad? Just to show you one normal to take out som info from a website. [CODE]from BeautifulSoup import BeautifulSoup import urllib url = urllib.urlopen('http://beans.itcarlow.ie/prices.html') soup …

Member Avatar for richieking
0
2K
Member Avatar for evertron

[QUOTE]The array module is kind of one of those things that you probably don't have a need for if you don't know why you would use it (and take note that I'm not trying to say that in a condescending manner!). Most of the time, the array module is used …

Member Avatar for TrustyTony
0
114
Member Avatar for kuchi

Cgi script is limited and if we compare something like jboss,to same in python it will be one of the many [URL="http://wiki.python.org/moin/WebFrameworks"]Webframework[/URL] for python. Django is the most known. Some sites that run on django. [url]http://www.djangosites.org/[/url] web2py is also very simpel to setup,and is has a lot power. [url]http://www.youtube.com/watch?v=53DF4pkeriU[/url]

Member Avatar for snippsat
0
132
Member Avatar for flebber

Like this no need to use time or decimal module. Set upp notepad++ correct or use a good ide editor for python like pyscripter or pydev/SPE IDE [url]http://code.google.com/p/pyscripter/[/url] [url]http://pythonide.blogspot.com/[/url] [url]http://pydev.org/[/url] [CODE]hours = float(raw_input("Enter Hours Worked: ")) gross = hours * 12 netpay = gross - (gross * 0.15) print "Your …

Member Avatar for snippsat
0
2K
Member Avatar for justaguy101

You can call file/help or other standar name in a menu,whatever you want. Here the standar way. [CODE]menubar = wx.MenuBar(wx.MB_DOCKABLE) file = wx.Menu() help = wx.Menu() menubar.Append(file, '&File') menubar.Append(help, '&Help')[/CODE] So say that you want other name. [CODE]menubar = wx.MenuBar(wx.MB_DOCKABLE) open_file = wx.Menu() super_help = wx.Menu() menubar.Append(open_file, '&open_File') menubar.Append(super_help, '&super_Help')[/CODE]

Member Avatar for richieking
0
267
Member Avatar for tammy12w

Like this for python 3,there has been big changes in urllib for python 3(urllib + urllib2 joined together) But i guess you havent used python 2,so the changes dosen`t matter for you. [QUOTE]or is there a way to convert a .html file into a .txt file?[/QUOTE] The code under you …

Member Avatar for richieking
0
8K
Member Avatar for dragonstear

[QUOTE]now i can't figure out what does find+1 means..[/QUOTE] A clue most programming start indexing/counting at 0. [CODE]def find_genes(gene,sequence): my_list= [] #Dont use list as a varible name,it`s a python keyword count = sequence.count(gene) find = sequence.find(gene) my_list.append(find) while find > -1: find = sequence.find(gene,find+1) my_list.append(find) return count,my_list #Move to …

Member Avatar for dragonstear
0
165
Member Avatar for 15uck

Like this it can be done,did some changes in your code that generate a infinity loop. Read stiky post about GUI in top on this forum. [url]http://zetcode.com/[/url] [CODE]import wx class MyFrame(wx.Frame): '''info about class | doc_string''' def __init__(self, parent, mytitle, mysize): wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize) #---|Window color|---# self.SetBackgroundColour('light blue') …

Member Avatar for 15uck
0
365
Member Avatar for HoneyBadger

[CODE]''' #part.txt This is a test. I want to take out this part,of the text ''' f = open('part.txt') #readlines() return a list,so string slice wont work [start:end] print f.readlines() #--> ['This is a test.\n', 'I want to take out this part,of the text'] f = open('part.txt') #read() return a …

Member Avatar for TrustyTony
0
110
Member Avatar for HoneyBadger

Some advice,and no [B]None[/B] as d5ed poinet out. [CODE] import string def read_book(file_in=None): ''' Read in file,strips whitespace-punctuation Returns them in lowercase ''' f = open(file_in) #r is default for l in f: #Dont need readlines book_line = l.strip().translate(None, string.punctuation) for w in book_line.split(" "): if w != "": print …

Member Avatar for HoneyBadger
0
101
Member Avatar for z00t

This should help,and try to post some code next time. [CODE]>>> from __future__ import division >>> my_list = [1,2,3,4] >>> avg = sum(my_list)/len(my_list) >>> avg 2.5 >>> [/CODE]

Member Avatar for richieking
0
120
Member Avatar for gunbuster363

[QUOTE]python.org tell people to forget about python 2 and head into python 3.[/QUOTE] No they do not. [QUOTE]For example, python 3 only ship with a tkinter gui module which does not have great reputation. If I am to use python 3, I have no choice but to use tkinter.[/QUOTE] No,you …

Member Avatar for richieking
0
223
Member Avatar for king_koder

Just have both installed as most of us have. Wxpyhon is a excellent GUI toolkit use python 2.x if you need to use that. This topic has been upp several times,python is python dont get hang up in python 2.x or 3.x. If you are learning python 3.,you are learing …

Member Avatar for ultimatebuster
0
675
Member Avatar for s0ur

You have to some reading about dictionary. Some stuff you can look at. [CODE]>>> z = {'a': 1, 'a': 2, 'a': 3, 'b': 4, 'c': 5} >>> z {'a': 3, 'b': 4, 'c': 5} >>> #Keys are unique within a dictionary while values may not be >>> #That`s why only …

Member Avatar for s0ur
0
190
Member Avatar for testie

A rule that can be good to remember. Never delete something from or add something to the list you are iterating over. The solution is: Iterate over your original list, and put everything which passes your test into another list. Some way of doing this. Using List comprehensions. [CODE]>>> l …

Member Avatar for Gribouillis
0
145
Member Avatar for evertron

[QUOTE]Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans. Do not write getters and setters. This is what the ‘property’ built-in is for. And do not take that to mean that you should write getters and setters, and then wrap them in ‘property’. [/QUOTE] …

Member Avatar for evertron
0
92
Member Avatar for WolfShield

An example i make some code that calulate average. [CODE] #average.py #saved in python dir from __future__ import division def average(average_list): if isinstance(average_list, (list, tuple)): return sum(average_list)/len(average_list) else: return 'Input can only be list or tuple'[/CODE] So import it and test it out. Save it in python sys.path or same …

Member Avatar for TrustyTony
0
1K
Member Avatar for Bluerain

Use parser BeautifulSoup is good. [CODE]from BeautifulSoup import BeautifulSoup html = '''\ <a href="http://www.gumtree.sg/?ChangeLocation=Y" rel="nofollow">Singapore</a>, <a href="http://www.gumtree.com.au/?ChangeLocation=Y" rel="nofollow">Australia</a>, <a href="http://www.gumtree.co.nz/?ChangeLocation=Y" rel="nofollow">New Zealand</a>, <a href="http://www.gumtree.com" rel="nofollow">England</a>, <a href="http://edinburgh.gumtree.com" rel="nofollow">Scotland</a>, <a href="http://cardiff.gumtree.com" rel="nofollow">Wales</a>, <a href="http://www.gumtree.ie" rel="nofollow">Ireland</a>, <a> ''' soup = BeautifulSoup(html) links = soup.findAll('a', href=True) # find <a> with a defined href …

Member Avatar for aml25
0
169
Member Avatar for Asset

Use code tags. A shorter way to average. [CODE]from __future__ import division def getAverage(numList): return sum(numList)/len(numList) print getAverage([1,2,3,4])[/CODE]

Member Avatar for Asset
0
713
Member Avatar for bambi231991

Some pratice you can try out in IDLE. [CODE]>>> name = raw_input("Enter Name: ") Enter Name: joe >>> name 'joe' >>> list(name) ['j', 'o', 'e'] >>> #This is called list comprehension >>> [i for i in name] ['j', 'o', 'e'] >>> #Written as an ordenarry loop >>> my_list = [] …

Member Avatar for TrustyTony
0
127
Member Avatar for yeticannotski

[QUOTE]ran it and I was so happy with it, but then... why on Earth does it tell me that "5" is higher than "24"? Or why does it tell me that "5" is higher than "45"?? Or why "5" is higher than "13"?[/QUOTE] Because you are comparing string and not …

Member Avatar for yeticannotski
0
84
Member Avatar for pixelss

Something you can look that may help you. [CODE]>>> s = '13, 15, 19' >>> s = s.split(',') >>> s ['13', ' 15', ' 19'] >>> [float(item) for item in s] [13.0, 15.0, 19.0] >>> sum([float(item) for item in s]) 47.0 >>>[/CODE]

Member Avatar for TrustyTony
0
110
Member Avatar for sahil1991

[QUOTE]also i wud like to know about the differences between java and python[/QUOTE] Python vs java. [url]http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/[/url] [QUOTE] Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower …

Member Avatar for sahil1991
0
110
Member Avatar for knan

[CODE]>>> Z = [] >>> X=['a'] >>> Y=['b','c','d','e','f'] >>> for i in Y: ... Z.append(X[0] + i) ... >>> Z ['ab', 'ac', 'ad', 'ae', 'af'] >>> [/CODE]

Member Avatar for Gribouillis
0
115
Member Avatar for sss33
Re: loop

Try to some code something yourself next time,not just ask for a soultion. [CODE]b = 0 a = 5 while b < a: b = b + 1 print b #----------- for i in range(1,6): print i [/CODE]

Member Avatar for snippsat
0
46
Member Avatar for patrickm129

[URL="http://www.daniweb.com/forums/thread20774.html"]This site[/URL] [url="http://www.swaroopch.com/notes/Python"]Byte og python[/url] [url="http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python"]Non-Programmer's Tutorial for Python 2.6[/url] [url="http://www.tutorialspoint.com/python/index.htm"]Python tutorial[/url] Youtube. [url="http://www.youtube.com/watch?v=4Mf0h3HphEA&feature=channel"]Python basic[/url] [url="http://www.youtube.com/watch?v=RHvhfjVpSdE"]Wxpython[/url] [url="http://www.youtube.com/watch?v=0xgn-HKzZes"]Pygame[/url] [url="http://showmedo.com/"]Show me do[/url]

Member Avatar for cghtkh
0
248
Member Avatar for gishi

When it comes to parseing xml/html regular expression is not the right tool. Use a parser python has several in standar libary or very good 3 party parser like beautifulsoup and lxml. [url]http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags[/url]

Member Avatar for Gribouillis
0
291
Member Avatar for Enders_Game

[QUOTE]I have to compare 5 words so writing a seperate for each combination would take too long[/QUOTE] I don see why you should use for loop like that for comparing 5 words. Give an example of the words,and how you think the comparing output should look.

Member Avatar for Gribouillis
0
90
Member Avatar for roboguy

Another way that i think is ok to read. [CODE]import os filenames = os.listdir(os.curdir) for filename in filenames: for ext in ['txt', 'htm', 'html']: if filename.lower().endswith(ext): print filename [/CODE]

Member Avatar for TrustyTony
0
259
Member Avatar for KrazyKitsune

I did write about exception handling(try,except)in this post you an look at. [url]http://www.daniweb.com/forums/thread245633.html[/url]

Member Avatar for snippsat
0
109
Member Avatar for Ultralisk

Can you post score.dat or a sample of the file. Show what data from the file you will take out,and how the list should look.

Member Avatar for TrustyTony
0
128
Member Avatar for gatehrdy

From looking at your code i have shorten it down. You have to many repating statement,that is not so good in programming. Have not read all rule off game,that you have to work on. [CODE]from random import randint def rollDice(): return [randint(1, 6) for r in range(6)] def user_input(): while …

Member Avatar for griswolf
0
966
Member Avatar for sravi.pearl

Python has 2 very good 3 party parser BeautifulSoup and lxml. This parser can handle html that is no good,this can be important. An example with BeautifulSoup. We want the price of beans from this site. [url]http://beans.itcarlow.ie/prices.html[/url] [CODE]from BeautifulSoup import BeautifulSoup import urllib2 #Read in website url = urllib2.urlopen('http://beans.itcarlow.ie/prices.html') soup …

Member Avatar for griswolf
0
250
Member Avatar for Roelof Wobben

Your class look strange,dont see a point with __len__ and __str__ in that class. test = zoeken() #calling find method. print test.find(****) #Takes 4 ****arguments or 0 because of default arguments. Maybe is better you explain what you want to do? [B]print test(test2)[/B] You only return test2 in __str__ so …

Member Avatar for snippsat
0
122
Member Avatar for Toikkala

Dont use list as a variable name,it`s a python keyword [CODE]>>> list <type 'list'> >>> a = 'abc' >>> list(a) ['a', 'b', 'c'] [/CODE] Loop over the len() of my_sting,stop at 10 and use slice. [CODE]my_string = 'abcdefghijklmnopqrstuvxyzo' for i in range(len(my_string)): if i == 10: print my_string[:i] #--> abcdefghij …

Member Avatar for TrustyTony
0
230
Member Avatar for sebcbien

Here something you can look at. [CODE]class testClass(object): def __init__(self): self.my_dict = {} def uppdate(self,key, value): self.my_dict[key] = value def remove(self,del_key): del self.my_dict[del_key] def show_data(self): print self.my_dict if __name__ == '__main__': test = testClass() test.uppdate('a', 1) test.uppdate('b', 2) test.uppdate('c', 3) test.remove('c') test.show_data() #{'a': 1, 'b': 2}[/CODE] Something to think off …

Member Avatar for snippsat
0
175
Member Avatar for doffing81

One way to make a deck,that is ok to understand. @askrabal remember that import statement shall never be inside a class or function. Import statement shall alway be on top. [CODE]rank = 'A23456789TJQK' suit = 'CDHS' deck = [] for r in list(rank): for s in list(suit): card = r …

Member Avatar for doffing81
0
1K
Member Avatar for Archenemie

Make it an integer with int() [CODE]>>> paid_value = '55' >>> type(paid_value) <type 'str'> >>> paid_value = int(paid_value) >>> type(paid_value) <type 'int'> >>> paid_value ** 5 3025[/CODE]

Member Avatar for Archenemie
0
100
Member Avatar for marcom10

Drop all eval,where have you learn this very ugly way to convert string to integer? [CODE]>>> loan_str = raw_input ("Amount of loan:") Amount of loan:20000 >>> #make integer >>> loan = int(loan_str) >>> loan 20000 >>> type(loan) <type 'int'> >>> #Or make input return an integer >>> loan_str = int(raw_input …

Member Avatar for woooee
0
116
Member Avatar for lewashby

[QUOTE]In program 1 they are returned by an extra argument calles cls put in program to they are returned directly with the class name. Could someone please help me understand?[/QUOTE] Yes that what a class method do,did you read my link in the other post. [B]Vector2.from_points(A, C)[/B] here you call …

Member Avatar for snippsat
0
97
Member Avatar for lewashby

[CODE] @classmethod def from_points(cls, P1, P2): return Vector2(P2[0] - P1[0], P2[1] - P1[1]) [/CODE] [url]http://docs.python.org/library/functions.html?highlight=classmethod#classmethod[/url] [QUOTE]could someone please explain the __add__ constructor to me? Thanks.[/QUOTE] [CODE] >>> x = 5 >>> y = 6 >>> x + y 11 >>> dir(x) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', …

Member Avatar for lewashby
0
114
Member Avatar for emorjon2

Key in a dictionary can not use list. If you turn it around is ok,and set list as an value. [CODE]>>> codes = {} >>> inpt = raw_input("<<<").split() <<<my car >>> inpt ['my', 'car'] >>> inpt2 = raw_input("?...") ?...black >>> inpt2 'black' >>> codes[inpt] = inpt2 Traceback (most recent call …

Member Avatar for griswolf
0
136
Member Avatar for aspro648

You dont define x,so then it will of course not have an value. [CODE]>>> x Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> x NameError: name 'x' is not defined >>> def file2Function(): x = 5 print x file2Function() #5 [/CODE] [CODE]#file1.py def file2Function(): x = 5 …

Member Avatar for woooee
0
186
Member Avatar for Sky Choi

[QUOTE]Can't I just access the specific line without loading the file to memory?[/QUOTE] Yes use linecache from standard library. [CODE]'''--> l.txt line 1. line 2. line 3. ''' from linecache import getline #Notice linecache count from 1 print getline('l.txt', 2).strip() #--> line 2.[/CODE]

Member Avatar for TrustyTony
0
632
Member Avatar for cbowen12345

[CODE]>>> xdate = 5 >>> print 'value of xdate is %d' % xdata value of xdate is 5[/CODE] String formatting operations has been in python since day one. [url]http://docs.python.org/library/stdtypes.html#string-formatting-operations[/url] A new and more powerful string formatting operations,from python 2.6--> [url]http://docs.python.org/library/string.html#format-examples[/url] [url]http://www.daniweb.com/code/snippet232375.html[/url]

Member Avatar for snippsat
0
110
Member Avatar for cleve23

With [URL="http://ironpython.net/"]ironpython[/URL] you can write in python with full acess to the .NET Framework. For a python programmers this is very fine,dont have to learn a more verbose and static types language as C#. You have [URL="http://boo.codehaus.org/"]BOO[/URL] that use a python like way to write code. But are statically typed …

Member Avatar for snippsat
0
495
Member Avatar for doffing81

Some hint You will not get finish code or so much help if you dont show some effort. [CODE]>>> a = 3 >>> if a <=5 and a >= 1: ... print 'Number are between 1 and 5' ... Number are between 1 and 5 >>> a = 7 >>> …

Member Avatar for snippsat
0
101
Member Avatar for dustbunny000

Write takes string as argument,if x is a string is shall be ok. If not [B]''.join() [/B]as tony used be an option. Remeber to [B]close()[/B] the file,if not it will not write anything. [B]with open()[/B] close the file auto,as tony use over. [CODE]if x[0:4]=="ATOM": print type(x) #Check the type >>> …

Member Avatar for Beat_Slayer
0
148
Member Avatar for mjs051

Look into dictionary. Example Banana is the [B]key[/B] and price is the [B]value[/B]. So if you call key you get price. Here is a code example you can look. This code will run in a loop given bye argument number given to function. And save result to a dictionary,that you …

Member Avatar for TrustyTony
0
9K
Member Avatar for -ordi-

For log in use mechanize. for parsing are beautifulSoup or lxml good choice. [CODE]import mechanize browser = mechanize.Browser() browser.open(your_url) browser.select_form(nr=0) #Check form name nr=0 work for many browser['username'] = "xxxxx" browser['password'] = "xxxxx" response = browser.submit() html = response.read() print html[/CODE]

Member Avatar for -ordi-
0
533

The End.