1,175 Posted Topics
Re: If there is no space in the rank or name you can do it this simple way: [code=python]mydata = """\ <Ranking: AA (John)> <Ranking: CA (Peter)> <Ranking: TA-A (Samantha)> """ rank_list = [] for line in mydata.split('\n'): print line, line.split() # testing if line: rank_list.append(line.split()[1]) print print rank_list """my result … | |
Re: The recommended coding style for Python is: Do your imports Define your functions and/or classes Do the main code The bare minimum: Define your functions before you use them in your main code | |
Re: Call for update() as shown below: [code]from tkinter import * class fb( Frame ): def fastbuttons( self ): b = Button(self) b.grid() self.update() print( b.winfo_ismapped() ) def __init__( self, master=None ): Frame.__init__( self, master ) self.grid( sticky='nsew' ) self.button = Button( self, text='Start', command=self.fastbuttons ) self.button.grid() if __name__ == '__main__': … | |
Re: See: [url]http://www.daniweb.com/forums/post1079895.html#post1079895[/url] | |
Re: The module[B] threading[/B] is the higher level module and actually uses module [B]thread[/B], since that one has the lower level tasks. So one can assume that [B]threading[/B] is somewhat slower in speed, but nicer in syntax. Python3 adds another module called multiprocessing that can take advantage of multiple processsor machines. | |
Re: Here would be one way to accomplish this: [code=python]mylist = [ ['A', 60], ['B', 40], ['C', 90], ['B', 150], ['C', 230], ['A', 220] ] # convert to dictionary, put collision values into a list mydict = {} for sub in mylist: print sub # testing mydict.setdefault(sub[0], []).append(sub[1]) print print mydict … | |
Re: Could a counselor substitute for a mentor? Counselors are plentyful, mentors are in very short supply. | |
Re: [QUOTE=William Hemsworth;1072644]Yep, I've been forced to do VB in college, I really don't like it. One of my favourite languages is Flash Actionscript 2.0, its syntax is very similar to C++/Java, and it's extremely flexible and easy to use.[/QUOTE]There are entire hospital management systems written in vb, and sold for … | |
Re: [QUOTE=python.noob;1072569]snippsat.. Everybody is here with a question to be answered.. Google gives result for everything.. Then why people are answering and wasting their time??? Just can give the link to [url]www.google.com[/url].. I think you might not(matured) know the concept of a forum even though you are a member:S.. It is … | |
Re: A Turk got sore at his harem And thought of a scheme to scare them He caught him a mouse And let it loose in the house The chaos was called a "harem-scarem" | |
Re: Well, in Python just about anything is an object not just the typical OOP stuff. I assume that your instructor forgot about that and actualy means creating a class Student where each instance is a particular student. | |
Re: If you search DaniWeb, you will find a whole lot of similar requests about queues, stacks and html tag names. Looks like this homework has been given in the last few weeks to a bunch of folks. The Python manual describes the use of queues in detail. Your problem will … | |
Re: You may also take a look at: [url]http://www.daniweb.com/forums/thread240778.html[/url] | |
Re: There is a very similar thread at: [url]http://www.daniweb.com/forums/thread241913.html[/url] | |
I was trying to create a 3x3 list of lists, and came up with this surprising behaviour: [code]# creating a 2D list with an overloaded * operator mlist3 = [[0]*3]*3 print mlist3 # [[0, 0, 0], [0, 0, 0], [0, 0, 0]] mlist3[0][0] = 1 print mlist3 # [[1, 0, … | |
Re: The title is somewhat misleading. You want to add 2. | |
Re: Get one of the many Python Learning Books they usually have plenty of exercises. | |
Re: You could do: [code=python]for c in "Hello World": print c , [/code]In Python2 the comma puts in a space and keeps it on the same line. | |
Re: It's always good to use a few test prints: [code]import operator OPERATORS = { '+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.div, } class Stack(object): "Creates a stack to enter numbers or operators into" def __init__(self): self.storage = [0,0,0,0] self.sptn = -1 def push(self, item): self.sptn = self.sptn + 1 … | |
Re: Yeah, I have heard enough of my fellow students brag about the amount of disk space on their brand new notebooks. I have never bought anything but a used notebook computer, so I have to be happy with disk space they gave you a few years ago. Actually more than … | |
Re: What do you mean with "WxGlade does not show value"? Is it WxGlade or your program you wrote using WxGlade? Just a note on the smart side of things. If you have a problem for others to look at and possible solve, it behooves you to supply as much needed … | |
Re: [QUOTE=GrimJack;1038840]But have you seen this l[URL="http://www.daniweb.com/forums/thread235892.html"]ink[/URL]?[/QUOTE]Wow, recursion in action! Very geeky too! | |
Re: Also the OP didn't want a zero in the digits part. :) | |
Re: Ah, the pros and cons on posting on an old thread. If you are interested in a regex solution, I would start a new thread and put regex in the title. | |
A mother and son were walking through a cemetery, and passed by a headstone inscribed "Here lies a good lawyer and an honest man." The little boy read the headstone, looked up at his mother, and asked "Mommy, why did they bury two men there?" | |
Re: Rugby could become a sport, if they ever show it on the tele in the US. | |
Re: In a number of cases the parents should be spanked for bringing their unruly kids to a nice restaurant, where you just sat down to enjoy a special meal. | |
![]() | Re: I found and played a pretty sophisticated Tic Tac Toe game written in Python at an earlier posting here: [URL]http://www.daniweb.com/techtalkforums/thread26658.html[/URL] |
I am still rather new to the Linux OS and need some detailed advice on the installation of Python3.1 on my Ubuntu machine. Python3.1 is not in the Ubuntu package repository yet. | |
Re: [QUOTE=Garrett85;1031820]How do you know when to use a function by wraping the content between parentheses "function(x) or through dot notation x.function() ? thanks.[/QUOTE]You are somewhat confused about functions. ![]() | |
Re: [QUOTE=CaptainMack;262238]Hi i am new to daniweb.com, i was looking around this website and i saw that i needed to register. I am 17 years old and im from Gibraltar, i am studying French Spanish and Computing. I am hoping that i could learn a lot from other members as at … | |
Re: [QUOTE=cplspls;1031571]Kindly go to the C++ forum.[/QUOTE]I went to the C++ forum, but nothing happened. :) | |
| |
Re: You are almost there: [code=python]def isCMD(msgstrlist): for word in msgstrlist: if word[0].upper() == 'C': print word else: print "Not CMD message" msgstrlist = ['Ox', 'Dog', 'Cow', 'mouse', 'cat'] isCMD(msgstrlist) """ my result --> Not CMD message Not CMD message Cow Not CMD message cat """ [/code]Note: Looks like you are … | |
Re: Computers are definitely female, here are the male reasons: 1) Most men who have one don't understand them. 2) Amongst themselves they talk in an incomprehensible language at high speed. 3) You need to tell them every trivial thing you want from them. 4) All of a sudden they refuse … | |
Re: With wxPython code you can give py2exe an XML based manifest to force it to adopt the Windows XP theme. | |
![]() | Re: Looks like one of the 638 web pages is not available. You should use a try/except trap for this case. |
Re: Something like that might do. I avoided the use of float() until the end to keep time-stamp and port info from turning into floats: [code=python]raw_data = """\ 501 0 0.932 0.933 0.931 0.931 0.929 0.933 0.93 0.928 501 1 0.974 0.98 0.978 0.976 0.974 0.974 501 2 0.953 0.949 0.944 … | |
Re: I made an attempt on user friendly data entry with just such a simple temperature converter program, see: [url]http://www.daniweb.com/forums/showthread.php?p=992595#post992595[/url] | |
Re: And don't forget to use self to turn those functions into methods for the instance, like def moveup(self): | |
Re: At first, I would adopt consistent indentations! Very important in Python. Most people use 4 spaces. | |
Re: As a beginner use for loops first, later on 'list comprehensions' become more natural. | |
Re: [QUOTE=Friktion;991252]well ok i can go back to pygame then , thanks but first i whant to try the thing above !! EDIT: Dude thanks i tried that and it worked =) i really appreciate your help thanks again, and no im not using all the features only the wav playing … | |
Re: To make more sense you should have written your class this way: [code=python]class Animal: def __init__(self, legs): self.legs = legs cow = Animal(4) chicken = Animal(2) octopus = Animal(8) # Bob is a pet chicken with 1 leg missing bob = Animal(1) print( octopus.legs ) # 8 print( chicken.legs ) … | |
Re: Gribouillis is right, global constants have their place, but like he mentioned, make them stick out. One time when all upper case is appropriate. | |
Re: Works fine on my Ubuntu machine. I copied the Python25/26 source from the webpage and saved it as cTurtle.py in my working directory. The module has a number of demos built in that look great and work well. I used the IDLE IDE, my normal IDE DrPython bitched about a … | |
Re: Like gerard4143 says, you have to make the print statement part of the function, since Tf is local to the function. The other option would be to return Tf to make it available outside the function: [code=python]#Convert C to F def Tc_to_Tf (): Tc = input ("What is the Celsius … | |
Re: Nice, looks like Python3 has bit your fancy. Sooner or later we all have to follow your example. | |
Re: Simply call the dispatch(choice) function with your choice as argument: [code=python]#!/usr/bin/python def dispatch(choice): if choice == 'A': functionA() elif choice == 'B': functionB() elif choice == 'C': functionC() else: print "An Invalid Choice" def functionA(): print "WRONG!" def functionB(): print "CORRECT!" def functionC(): print "WRONG!" choice = raw_input ("A, B, … |
The End.