4,305 Posted Topics
Re: Looks like you have made nice progress with coding pygame. The pygame module has something called [B]sprites[/B] that, as far as I remember, are more suitable for what you have in mind. | |
Re: Thanks for letting the rest of us know! Most folks use protocol=-1 as the highest possible protocol. | |
Re: If [B]remove('an', 'banana') --> 'bana'[/B] then this should be [B]remove('iss', 'Mississippi') --> 'Missippi'[/B] So you can use ... [code]def remove(sub, s): # replace first sub with empty string return s.replace(sub, "", 1) # test print( remove('an', 'banana') ) # --> bana print( remove('iss', 'Mississippi') ) # --> Missippi [/code] If … | |
Re: In simple terms: Input Data --> Process Data --> Output Processed Data | |
Re: The culprit is screen.blit(background, (0,0)) I moved it out of the event loop, and rewrote your program just a little to reflect Python coding convention better ... [code=python]import pygame as pg def main(): # initialize pygame pg.init() screen = pg.display.set_mode((640, 480)) pg.display.set_caption('game') background = pg.Surface(screen.get_size()) background = background.convert() background.fill(pg.color.Color('yellow')) # … | |
Re: An entry in the Python26 manual: No one has made a Windows port of the curses module. On a Windows platform, try the Console module written by Fredrik Lundh. The Console module provides cursor-addressable text output, plus full support for mouse and keyboard input, and is available from [url]http://effbot.org/zone/console-index.htm[/url]. | |
Re: The Now Generation will blame his parents, so where did his parents go wrong? | |
Re: Simply posting the same question with another meaningless title again is in rather poor taste. People have given you advice, so apply it and go from there. We will not do homework for you, since you are the one that has to learn something! | |
Re: Gribouillis hit it right. Another observation, the C version of a module, method or function is built-into the compiled interpreter itself (or in the form of a [B]dll[/B] or [B]pyd[/B] file). Python language versions are in the [B]Lib[/B] directory. I can only speak for the Windows version of Python here. | |
Re: [B]from xml.sax.saxutils import XMLGenerator[/B] I have no experience with the XMLGenerator, but I know it is used to create xml files. | |
Re: I agree with snippsat, don't tie yourself down with an outdated book and outdated custom modules. Pygame has come out for Python3, and will be around for hopefully more than just a few years. If you learn pygame programming directly, you have learned something worthwhile. | |
Re: LiveWires is a pretty well dated Python course that uses a module called games as a wrapper for PyGame. It is supposed to make the use of PyGame easier for the beginner. Looking over the module games.py, there is no init() method, unless there is a much newer version out. | |
Re: Actually. your raw data file is tab delimited and easily converted into a list of lists. Once that is done you can simply access your specific data by index and looping through the list. The only special considerations are that the first line is a header and the last line … | |
Re: Any idea which GUI toolkit you want to use? | |
Re: It can be as simple as this ... [code=python]import os import time # pick a file you have in the working directory filename = "beachball.jpg" # show file creation time print( time.ctime(os.path.getctime(filename)) ) [/code] | |
![]() | Re: Nice game, but like mawe says, your (PVC) 'player wins' detector does not work! Something to work on. |
This shows how to create, load and access a ListBox. BCX was used to create the original code which was then modified to work with the Dev C++ (really GCC/G++) compiler, compile as a Windows Application. | |
Re: In line [B]print cipher.encrypt(lines)[/B] are you sure all the characters are printable? BTW, Python relies on indentations, please keep them constant. | |
Re: [QUOTE=pdxwebdev;1032220][CODE] def doKey(e): print(e.widget.get("1.0","end")) root= Tk() root.title('yada') txta = Text(root, width=40, height=10) txta.bind("<Key>", doKey) txta.pack(side=LEFT) root.mainloop() [/CODE] Pressing a key in this text area will always output the string prior to your pressing the key. Am I missing something?[/QUOTE]You could use [B]txta.bind("<KeyRelease>", doKey) [/B] | |
Re: The closest Python module that I can think of is visual Python (VPython), a free download from [url]http://vpython.org[/url]. Also take a look at some examples at: [url]http://wiki.aims.ac.za/mediawiki/index.php/Vpython:Getting_Started#Basics[/url] | |
![]() | Re: Take a look at: [url]http://www.daniweb.com/forums/showthread.php?p=1032475#post1032475[/url] ![]() |
Re: What do you think it should print? Here is a typical class example ... [code=python]class MyName: def __init__(self, name): self.name = name def print_name(self): print "Hi, I am", self.name def __str__(self): """overloads str() and hence print applied to instance""" return "My name is %s" % self.name name = 'bob' mm … | |
Re: In function(x) x is the outside argument passed to the function. In x.function() x is the namespace of the module or instance used. You better read up on functions! See ... [url]http://www.swaroopch.com/notes/Python_en:Functions[/url] ![]() | |
Re: All is relative! If you count the time since the [B]big bang[/B], then 3 years is almost nothing. | |
Re: I am glad the OP didn't ask for a particular hand.:) This thread is starting to get funny and belongs into the Geek's Lounge! Just in case ... [QUOTE]Directions 1 the act of directing; management; supervision 2 [usually pl.] instructions for doing, operating, using, preparing, etc. 3 an authoritative order … | |
Re: [QUOTE=AutoPython;1030006]I can't find a compiler to compile version 3 Python scripts to .exe. All the compilers I see are all for Python 2.[/QUOTE]Just a clarification: The software you are talking about does not compile, but forms a packet of your compiled byte code, all the needed modules, and the Python … | |
Re: Here is a simple example that just erases and redraws the shape ... [code=python]# exploring module pygame # draw a white circle on a black screen and move it # by erasing and redrawing the circle within a set time delay import pygame as pg # (r, g, b) tuple … | |
Re: Let's hope that the code you are showing is not exactly like in the tutorial. There are some major mistakes in your code. Also, please do not use tabs for indentations! In most editors tabs come out as 8 spaces and make the code look rather messy. I don't even … | |
Re: Please make your title a bit more specific the next time around.:) If you are a beginner with GUI programming, stick with Tkinter to get used to the basics of how to set up a GUI, and then move to something with fancier widget as you need them. A lot … | |
| |
Re: Schmidt's statement that a Netbook running with Google OS expected by 2010 is another eyebrow raiser. | |
Re: The other option is ... [code=python]import random list1 = ["1", "2", "3"] string1 = random.choice(list1) string2 = """\ Random Number is %s""" % string1 print(string2) [/code]... this makes the output more visual in your code. | |
Re: Can you give us a simplified example what strA and strB would look like? Also, have you checked this: [url]http://biopython.org/wiki/Main_Page[/url] | |
Re: You can use this little function ... [code=python]def extract(text, sub1, sub2): """ extract a substring from text between first occurances of substrings sub1 and sub2 """ return text.split(sub1, 1)[-1].split(sub2, 1)[0] str1 = "<a href='http://www.google.com'>more stuff here</a>" str2 = extract(str1, "='", "'>") print( str1 ) print( str2 ) # http://www.google.com [/code] | |
Re: The best way to learn any computer language is to experiment with the concepts of the language, and if you are stuck, search the manuals and ask question on a language forum like this. | |
Re: [QUOTE=pspwxp fan;1028792]Heheh, i could say i'm good at Python even though this is the first time i'm seeing its code! :D[/QUOTE]I keep telling folks that C++ and Python have much in common, by design the Python syntax is much easier on the eye. If you just want to toggle between … | |
Re: Can be as simple as this ... [code=python]strA = 'B' print(strA in 'ABCD') [/code] | |
Re: These two lines: ______________ = _______________("Enter the filename : ") file = ________(filename, __________) should be: filename = raw_input("Enter the filename : ") file = open(filename, "r") Picking [B]file[/B] as a variable name is a little unfortunate, since [B]file[/B] is a function name in Python2. | |
Re: Good effort, but super-long variable names and tab indentations make this code hard to fathom. Please avoid tab indentations as they translate into 8 spaces here in the DaniWeb code field. The standard that most folks are accustomed to is 4 space indentations for Python. Again, the general coding guide … | |
Re: To run the stopwatch in the background, you need to check out the Python module threading. | |
![]() | Re: You need to add these 2 lines to the beginning of your program code ... [code=python]import sys sys.path.append('/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages') [/code] |
Re: I am a little lost. Would this be a correct statement? [QUOTE]str1 and str2 should contain one of [B]A T G C[/B] and form a combination of [B]AT[/B] or [B]TA[/B] and [B]CG[/B] or [B]GC[/B][/QUOTE] If that's the case then this should do ... [code=python]def is_base_pair(str1, str2): s = str1 + … | |
Re: Just a note: dictionaries keep their keys in a hash order to speed up searches. If you want to keep the entry order you can just use a list of (key, value) tuples which you can also sort if need be. | |
Re: Can you give us a [B]short[/B] example what your data file looks like and what you want to extract? | |
| |
Re: Here is a simple introduction: [url]http://en.wikipedia.org/wiki/Python_programming_language[/url] Swaroop C.H. has rewritten his excellent beginning Python tutorial/book for Python3: [url]http://www.swaroopch.com/notes/Python_en:Table_of_Contents[/url] More advanced: "Dive Into Python" Mark Pilgrim's free online book, novice to pro, updated constantly. [url]http://www.diveintopython.org[/url] rewritten for Python3 (check appendix A for 2to3 differences) [url]http://diveintopython3.org/[/url] Also "Think like a Python Programmer" … |
The End.