880 Posted Topics
Re: startswitch/endswith you can use tuple. [CODE]if not link.startswith(('javascript','mailto')) and not link.endswith(('pdf','ppt')): #do something [/CODE] Depends on how input text is,but a regex can bee used. Just an untestet regex for this could look something like this. [ICODE]^javascript|^mailto|pdf$|ppt$[/ICODE]. Or make variables with tuple as jca0219 suggest. | |
Many of us like wxpython,so is always fun with a new tool.:) [url]http://wxformbuilder.org/[/url] | |
Re: Use lowercase for your string formatting expression. [CODE]>>> print 'Hi this is a %s' % 'test' Hi this is a test >>> print 'Hi this is a %S' % 'test' Traceback (most recent call last): File "<interactive input>", line 1, in <module> ValueError: unsupported format character 'S' (0x53) at index … | |
Re: Sneekula code will work fine for CSV string. Just make and other version,that do just the same. Maybe better looking,not that it matter so much at all. [CODE]def question(): my_question =\ ['What is your name? ', 'What organization do you work for? ', 'What is your title at this organization? … | |
Re: Dont use global statement,it`s a ugly. A function should keep code local and not send variabels out in global space. Pass in argument and return in out when you need it. Do this become to difficult move over to use a class. [CODE]def start(my_list=[]): inventory = my_list return inventory def … | |
Re: Can you give us "unique_ips.txt". You can make to new file only smaller,with somthing like 100 ip adresses. Then it is easier to test out a solution. And please use 4 space for indentations [URL="http://www.python.org/dev/peps/pep-0008/"]PEP-8[/URL] | |
Re: If it is a new line character that make this,you can try this quick fix. [CODE]operatorless = [item.rstrip() for item in operatorless] return operatorless[/CODE] Use print statement for troubleshoothing i think many forget in wxpython. It will show result in stdout window. Then you can see if as example if … | |
Re: Hint. [CODE]lst_1 = ['b','a','c','2','1','3'] lst_2 = ['a','b','3''1','2'] diff_list = sorted([item for item in lst_1 if not item in lst_2])[/CODE] | |
Re: [QUOTE]Thanks. I see what I was missing. When can I use Raw input ?[/QUOTE] In python 2.x is best to always use raw_input. input() is i mix off eval() and raw_input() in python 2.x that return an integer. Python 3.x has only input() work the same way as raw_input in … | |
Re: You can look at this,did some changes to the regex. Shoud find valid proxy ok now. [CODE]import re '''-->proxy.txt 202.9945.29.27:80 221.11.27.110:8080 11111.45454.4454.444 114.30.47.10:80 116.52.155.237:80 204.73.37.11255:80 220.227.90.154:8080455 ''' proxy_file = 'c:/test/proxy.txt' proxy_pattern = r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5}\D' my_compile = re.compile(proxy_pattern) file2_read = open(proxy_file, 'r') new_proxy = open('c:/test/new_proxy.txt', 'w') for currentline in file2_read: match_obj = … | |
Re: [QUOTE]the first item in the index is 0, so the last item should there fore be 2 [/QUOTE] You missing the point he is showing how an [B]IndexOutOfRange exception[/B] happends. [ICODE]print(abc[2])[/ICODE] is off course correct,but that not the point here. | |
Re: [URL="http://www.ibiblio.org/swaroopch/byteofpython/read/problem-solving.html"]byte of python[/URL] chapter 10 can help you out. The zip solution there works best on linux, if you what to compress backup look into [URL="http://effbot.org/librarybook/zipfile.htm"]zipfile[/URL] or some 3 party module rar/7zip/lmza. | |
Re: Somthing like this? [CODE]def click(self, val): s = "Button %s was clicked" % val label = tk.Label(text = s, width = 15) label.grid(row = 0, column = 0) s = "Button " + val + " clicked" # show result in title self.title(s)[/CODE] | |
Re: [url]http://wiki.python.org/moin/IntegratedDevelopmentEnvironments[/url] [url]http://stackoverflow.com/questions/81584[/url] Pyscripter as postet over is good,but work only for windows. Spe is good editor,work linux,mac osx. Pydev for Eclipse are the many that like. I use komodo ide and pyscripter windows. Komodo ide and spe linux. I fast way to test out editor is portablepython comes with pyscripter … | |
Re: What contry do you what valid phone nummers for? Or give an example of match and not match. match- (+44)(0)20-12341234 02012341234 Not match. (44+)020-12341234 1-555-5555 | |
Re: [CODE]IDLE 2.6.4 >>> word = raw_input("Please enter a string:") Please enter a string:racecar >>> # raw_input is returing a string so dont use "str" >>> input_word = "word" >>> input_word 'word' >>> #Do you see the error now. >>> word_rev = word[::-1] >>> word_rev 'racecar' >>> if input_word == word_rev: … | |
Re: Your code it`s not nice and well formated. Thing that is clear now,can be difficult to understand when you look at code the 6 months time in the future. And a bad formatet code with no documenting make things a lot worse. So a well formated code can help yourself … | |
Re: For python 2.x eval() has a lot of power and can be safety issue in wrong hands. a = "__import__('os').remove('important_file')" print eval(a) [CODE] IDLE 2.6.4 >>> from __future__ import division >>> 1 / 3 0.33333333333333331 >>> [/CODE] | |
Re: Buy him this book can be smart. [url]http://www.amazon.com/Hello-World-Computer-Programming-Beginners/dp/1933988495[/url] Has some [URL="http://www.pygame.org/news.html"]pygame[/URL] lesson. Invent Your Own Computer Games with Python [url]http://inventwithpython.com/[/url] For more basic i think byte og python i good start,and a smart 12 y/o shold cope with it pretty well. [url]http://www.swaroopch.com/notes/Python[/url] Non-Programmer's Tutorial for Python 2.6 [url]http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6[/url] And kids … | |
Re: Dont use classes if you dont understand how it work yet. Use 4 space for indentations,no it look ugly. Just to test you code. [CODE]currnt_quest = "Chef's Helper" def taver_n(): if currnt_quest == "Chef's Helper": done = raw_input("Bar Broski: You finish the quest yet? [yes/no] ") if done == "yes": … | |
Re: If it`s a number python will output as 0.something You can remove 0 by make it a string. [CODE]>>> n = 0.7893948 >>> print n 0.7893948 >>> n = str(n) >>> n '0.7893948' >>> n = n.replace('0', '') >>> n '.7893948' >>> #if we make it an integer(float) again,it will … | |
Re: How about this. [CODE] #Python 3 try: input_num = float(input('test: ')) except ValueError: print ('Not an integer') print (input_num)[/CODE] | |
Re: When it come to web pages([X]HTML) Then regular expression may not be the right tool to use. Read bobince famous answer at stackoverflow. [url]http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags[/url] For small steady web pages regular expression can work ok. Python has some really good tool for this like BeautifulSoup,lxml. For a small wiki pages the … | |
Re: This will match,0.00 can be any decimal number. [CODE]'Failed \d.{3,3}/\d.{3,3}.\d.{0,0}'[/CODE] [CODE]import re txt = "Failed 9.45/100.00" if re.match(r'Failed \d.{3,3}/\d.{3,3}.\d.{0,0}', txt): print 'Match' else: print 'Match attempt failed'[/CODE] [CODE]import re text = '''\ A fast and friendly dog. '14257'//745545*+*-/`' mytest@online.no My car is "red." "Failed 9.99/100.00" "Hei, this is a \"string\" … | |
Re: [QUOTE]I encourage a two-spaced indent.[/QUOTE] No and no no. Python programmers should read [URL="http://www.python.org/dev/peps/pep-0008/"]Pep 8[/URL] and try to follow advice that is given there. [B]Use 4 spaces per indentation level.[/B] | |
Re: Not needed to write long if/elif/else lopp,for something simple as this. [CODE]Question = raw_input("Do you wish to play the Guess a Number Game? [Y/n]: ") if Question.lower() not in ['y', 'n']: print "Not a valid option" else: print 'Do something'[/CODE] | |
Re: You can use what ide editor you want, whish gui toolkit you use dos have little impact. Pyscipter is good. [url]http://code.google.com/p/pyscripter/[/url] I use komodo ide,and pyscripter for python 3.x [url]http://www.activestate.com/komodo/[/url] Pydev plugin should work fine,have not testet it. | |
Re: You can look at a code here for wx.StyledTextCtrl [url]http://wiki.wxpython.org/StyledTextCtrl%20Log%20Window%20Demo?action=AttachFile&do=view&target=colourlog.py[/url] | |
Re: You can use cgi module,work in way same as php. The other way is as postet over use to use web framework. To test cgi you have to run a webserver like xampp. To set up xampp look here. [url]http://jerryoem.spaces.live.com/Blog/cns!4032172F84519E20!342.entry[/url] Then you can run python script in browser. This will … | |
Re: Input in python 3 return datatype string(same as raw_input in python 2.x) Change to datatype you need when you calculate. [CODE]print(add1, "+", add2, "=", int(add1) + int(add2)) print(div1, "/", div2, "=", float(div1) / float(div2))[/CODE] | |
Re: One more way. [CODE]while True: try: wd = int(input('How wide would you like your letter to be? (5-20)' + ': ')) if wd <=20 and wd >= 5: print ('You have answered: %s' % wd) break else: print('please enter a value between(5-20)') except (ValueError,NameError,SyntaxError): print ("Oops! That was no valid … | |
Re: Use code tag. [CODE]msg=box.content(id[0]) # <-- how will i be able to copy this sms file to a string print type(msg) #Show what datatype msg is print msg #Try to print the message[/CODE] Post the outcome of this | |
Re: ip = str(DEVICE_IP)[ICODE].spilt('.')[/ICODE]. Spelling error. ip = str(DEVICE_IP).split('.') Alternative print line. [CODE]print '%s-%s-%s-%s' % (ip[0],ip[1],ip[2],ip[3])[/CODE] | |
Re: Use code tag next time,not quote tags. Look at this code ande try to write the rest(if-else) [CODE]pairs =\ {"Jeremy": "Jerome", "Jason": "Fred", "Joe" : "Fred", "Alayna" : "Tom", "Jay" : "Jerome", "April" : "Tom"} def find_father(): print "\n This is your current list \n\n", pairs.keys() #We print only sons … | |
Re: [QUOTE]Is python web programming anything like php?[/QUOTE] Yes you have python CGI programming. A commen task in php is getting data from a HTML form. Here is an example in python. [url]http://webpython.codepoint.net/cgi_unique_field_names[/url] CGI is run from server side,so you can say it`s a sever side like php but you write … | |
Re: [CODE] File "C:\Users[/CODE] Use "File "C:\\Users" or C:/Users | |
Re: A little verbose but see if it can help you. [CODE]import re txt = '2008/03/25 log:true lcp: 78888 -> 100 lck=0 to=900 un=5840 l=0 BMN' re1 = '.*?' # Non-greedy match on filler re2 = '(lcp)' # Word 1 re3 = '(:)' # Any Single Character 1 re4 = '(\\s+)' … | |
Re: Somthing like this,i make a mark_check() function. Use exception handling to catch wrong input. Not much wrong with you code just test the if-elif-else condition to get the result you want. [CODE]def calcFinal(): while True: try: asg1Mark = int(raw_input("Enter Asg1 mark: ")) asg2Mark = int(raw_input("Enter Asg2 mark: ")) examMark = … | |
Re: Tkinter has an native an rather ugly look on windows. Use another tool kit like wxpython(my favorite) or PyQt. They look good on windows and have more lot option for creating good looking GUI. | |
Re: Yes i have to wait for 3 party libraries to be ported to python 3.x. Like wxpython very much so have to wait for that to by portet to python 3.x Have off course python 3.x installed to look at changes. Twistet i think will not be ported to python … | |
Re: For this regular expression can be to help. This funtion will only return correct date format in | yyyy-mm-dd | or | yyyy/mm/dd | [CODE]import re def foo(): while True: print 'use format | yyyy-mm-dd |' date_input = raw_input("Enter date: ") if re.match(r"(?:(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))\Z", date_input): print 'Match' return date_input … | |
Re: [QUOTE]if i want to delete red data of only key '172.14' all in from array[/QUOTE] You can use vega code for this. [CODE]mylist = newlist print(mylist)[/CODE] So now mylist has removed item you want(garbage collection)old mylist do not exits. Or an another soultion. [CODE]mylist = [ '192.168.255.1 00:01:02', '172.14.0.1 00:0f:01', … | |
Re: I been using komodo ide for some years now. Been happy with it,works fine for wxpython/pygame not that you need own ide for that. [url]http://www.activestate.com/komodo/[/url] Two very good free editors is. [url]http://code.google.com/p/pyscripter/[/url] [url]http://code.google.com/p/ulipad/[/url] | |
Re: Just a note. [ICODE]"C:\Documents[/ICODE]. For windows use. [ICODE]"C:\\Documents or "C:/Documents[/ICODE] | |
Re: Here is a solution with reglular expression you can look at. [CODE]import re def valid_mil_time(mtime): if re.match(r"(?:([01]\d|2[0-3]):?[0-5]\d)\Z",mtime,re.IGNORECASE): print ("true") else: print ("false") '''Out--> valid_mil_time('0059') true valid_mil_time('0060') false valid_mil_time('2359') true valid_mil_time('2459') false ''' [/CODE] | |
Re: Install Pywin32. [url]http://starship.python.net/~skippy/[/url] | |
Re: [QUOTE]Though there are advantages to using full IDEs such as netbeans[/QUOTE] Vega is not talking about big editors like netbean that support many languages. Pyscripter,SPE are small python editors that work out the box,just paste in code an run it. And will give a god error message and where in … | |
![]() | Re: [CODE]def common_letter(): #word1 = raw_input("Enter word1: ") #word2 = raw_input("Enter word2: ") word1 = 'This is my car' word2 = 'My car is fine' li1 = [] li2 = [] for letter1 in word1: li1.append(letter1) #This is better for letter2 in word2: li2 += letter2 print li1 #Now you have … ![]() |
Re: redyugi you code dos the same as set() [CODE]print len(set(["bread","cookies","cake","chocolate","bread"])) 4[/CODE] That only remove duplicate in a list. For count with set() this is a solution. [CODE]wordlist = ["bread", "cookies", "cake", "chocolate", "bread"] for item in set(wordlist): print '%s %s' % (item,wordlist.count(item)) '''Out--> cake 1 cookies 1 chocolate 1 bread … | |
Re: That is making it more difficult than it need to be Tech B. [CODE]n = raw_input('enter a number: ') first_n = int(n[0]) print first_n [/CODE] |
The End.