75 Posted Topics
Re: what that -0 means ;-) | |
Re: and another way as PyTony mentioned: color = raw_input ( "Input a color component character: ") if color.strip().lower() in "rgb": print "You have input a color component" else: print "You have not input a color component" | |
Re: a simple table: subjects = [ 'maths' , 'fyzics' , 'history' ] header = "<h4>Study Subjects</h4><table>" footer = "</table>" def write(): f = open( 'vysvedcenie_test.html' , 'w' ) f.write(header) for subject in subjects: body = "<tr><td>%s</td></tr>"%subject f.write(body) f.write(footer) f.close() | |
Re: @crazy99: have you ever tried to read documentation or any tutorials? just vizit the links woooee gave you, then review the answers in this thread, and you'll find out how to solve your problem. | |
Hi I found this script from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189858 it uses getopt module for managing cmd arguments, but I need it to work on mobile phones. I want to make a Mobile app using this script but I cant figure out how to change the comand Args to simple raw_inputs. can somebody … | |
Re: for printing all even numbers bellow 412 you can do this: ~~~for i in range(0,412): if i%2==0: print i~~~ and for a specific list of numbers: ~~~for num in num_list: if (num<412) and (num%2==0): print num~~~ | |
Re: these tricks might work for a Desktop, but not for a mobile user. I use my phone for coding, making threads and posting in the forum and unfortunately these new changes in daniweb, makes it a hard job. there is no ctrl+a then indent or any other shortcuts on my … | |
Re: [CODE]def middle(name): names = name.split(' ') if not (len(names) <=2): middle_names = names[1:-1] return ' '.join(middle_names) else: return 'There is no middle name in %s'%name print middle("Michael smith Jordan Jones") print middle("Michael Jordan Jones") print middle("Michael Jordan") print middle(raw_input("Enter a name")) [/CODE] Note: it is assumed that the "name" entered … | |
Re: here is what comes to my mind, but you need to add some codes to take the inputs and check their correctness: [code]import random def distance(minlen, maxlen, steps): total_distance = 0 step_count = 0 while step_count < steps: step_length = random.randint(minlen, maxlen) total_distance += step_length step_count += 1 return total_distance … | |
Re: for writing into file, I suggest codecs: [CODE=python]import codecs out_file = codecs.open("some_file.txt", 'w', 'utf8') out_file.write('español') [/CODE] | |
I tried many times but no luck. I want to parse a text file with a vcard format (from my phone contacts). the text file looks like this: BEGIN:VCARD VERSION:2.1 REV:20110913T095232Z UID:aac119d5fe3bc9dc-00e17913379d6cc8-3 N;X-EPOCCNTMODELLABEL1=First name:;[B]Maj[/B];;; TEL;VOICE:[B]09120000000[/B] X-CLASS:private END:VCARD BEGIN:VCARD VERSION:2.1 REV:20110228T083215Z UID:aac119d5fe3bc9dc-00e17b0693898c98-4 N;X-EPOCCNTMODELLABEL1=First name:;[B]Ali jahan[/B];;; TEL;VOICE:[B]09120000001[/B] X-CLASS:private END:VCARD BEGIN:VCARD VERSION:2.1 REV:20110228T083510Z … | |
Re: [CODE] def generateNumber(num): result = [] for i in range(num+1): result.append(i) return result [/CODE] | |
Re: you can write scripts or develop apps in python for android; but they need the sl4a and py4a to run. it is necessary to have them installed in order to run python apps. | |
Re: [QUOTE=;][/QUOTE] there are some ports of python for cellphones: PyS60 for Symbian phones(you can find many many apps written in python for this OS) Python for MeeGo. python for Maemo Python for Android a.k.a Py4A based on SL4A project | |
Re: in python 2.x: [CODE]test = [] for i in raw_input("Enter numbers separated by a coma(,):").split(','): test.append(int(i)) neg_sum(test)[/CODE] EDIT: sorry Moders, while I was posting, it got solved. | |
Re: it could be much shorter: [CODE]#User and Pass files: userN = open('username.txt', 'r').read() pasN = open('password.txt', 'r').read() # First make your Functions and Then Use Them the way you want: def username(): pin = raw_input ("Please insert your username: ") while True: if pin == userN: print 'You Did It!' … | |
Re: My Beginners' Solution: [CODE]def main(): print "This program calculates a numeric value for a name.\n" first, last = raw_input("Enter your first and last name (with a space): ").lower().split() print "\n","-"*10 totalFirst = 0 totalLast = 0 for ch in first: totalFirst += ord(ch)-96 print ch,"=",ord(ch)-96 for ch in last: totalLast … | |
Re: [QUOTE=;][/QUOTE] A hint: (Im a newbie too:D) [CODE]message = raw_input('Enter Message:') newMessage = '' for char in message: crypted = ord(char) newMessage += str(crypted) outfile = open('CryptedMessage.txt', 'w') outfile.write(newMessage) outfile.close()[/CODE] | |
Re: for the other part of your question: [CODE=python]word = raw_input('word: ') word.split() print '*'.join(word)+'*' #>>> H*E*L*L*O*[/CODE] | |
Hi All How can I select some random names from a list, so that in next time, those previously selected names become omitted from the list? for example, say we have 100 names in test.txt file, and we want to select 3 names randomly. then by recalling the selection function, … | |
Re: maybe something like this: [CODE=python]porttype = "Gi" print "sh int counters errors | i %s.*/1 " % porttype >>> sh int counters errors | i Gi.*/1[/CODE] | |
Re: Is "d" here stands for "digit"? this bellow code does the same but instead of 0's it prints empty spaces" [code=python]print('%0*s' % (3, 7))[/code] what about "s" here? does it mean "string"? | |
Hi All When trying to open a URL with bellow code, it Gives "TypeError: not all arguments converted during string formatting" [CODE=python]import urllib City="%D9%85%D9%87%D8%B1%D8%A7%D9%86" Province="%D8%A7%DB%8C%D9%84%D8%A7%D9%85" myurl = 'http://www.owghat.com/owghat.png.aspx?Province='+'%s'+'&City='+'%s'%(Province, City) #the real address is:http://www.owghat.com/owghat.png.aspx?Province=%D8%A7%DB%8C%D9%84%D8%A7%D9%85&City=%D9%85%D9%87%D8%B1%D8%A7%D9%86 a="e:\\img.png" urllib.urlretrieve(myurl,a)[/CODE] So, what I'm doing wrong? AND Another question: How to encode a utf-8 string(example: مهران) … | |
Hi All Please some one Help me find out why this code doesn't work: [code=python]codes=['zlib', 'zip', 'base64', 'hex', 'utf-8'] def encoder(str, i): return str.encode(codes[i]) def decoder(str, i): return str.decode(codes[i]) en = encoder('Some string here', 2) print en[/code] | |
Hello All This is my first post in this forum, despite my long visiting hours as a guest:D I don't have any background in programming and I'm a newbie in python too. But Learning python for S60(Python distro for Symbian Phones. anyway, I have a problem with printing from two … |
The End.