939 Posted Topics
Re: Don't know about the pausing, but: [code=python] print tuple("Foo bar".split(" ")) #Output: ("Foo", "bar",) [/code] That's an easy way. If the lines would contain more than one space between values, then some regex is in order [code=python] import re reObj = re.compile('\s+') for line in f.readlines(): print tuple(reObj.split(line)) [/code] | |
Re: I'm not sure that's possible either. You can take the factory class and replace its getNode method with your own custom function: [code="python"] def myFunc(self): pass #This is where you do something. Factory.getNode = myFunc [/code] I usually try to avoid these kinds of messy solutions, but I can't think … | |
Re: You don't need threading. In your main loop, use the pygame timer functions to tell you how much time has elapsed since the last loop, and when that time accumulates to 5 seconds you may redraw the circle. | |
Re: I'm confused, are you creating the icon in Python with code, or...? | |
Re: Actually I did a bit of research a while back on how Python allocated memory. For types like lists and dictionaries, once they are created (and the space allocated), Python doesn't free the memory for the remainder of the script's lifetime, but instead holds onto it for when newer ones … | |
Re: difflib is probably the better way to do this, seeing as this sort of thing is what diff was designed for. [url]http://docs.python.org/library/difflib.html#module-difflib[/url] | |
Re: If you have Python three, then this is easy: [code="python"] with open(filename, "rb") as fh: b = True while b: b = fh.read(1) #...do something with b [/code] | |
Re: Py2exe still stores your scripts (in pyc form I think). That said, byte compiled code can be difficult to reverse engineer (but still possible). You *can* .pyd modules in C\C++ (these are actually renamed .dll files with some extra definitions for python interop) if you'd like, but then that sort … | |
Re: The file may be encoded with a different codec than the one you're using. If this is the case, it's a simple matter of using [code]codecs.open(filename, "rb", "codec")[/code] If you don't know the codec, you may have to try a few until you get lucky. Start with the most common … | |
Re: PyQt and PyGTK work on linux. The latter may not be as customizable as the former though, since GTK rather uses the user's theme for customization. I hope when you go about making your "killer gui" you don't customize it to the extent that it becomes unusable. | |
Does anybody know a good way place to find developers for an open source project? ![]() | |
Re: Assuming each script has a function called run_test: [code="python"] import os, sys folder = os.path.abs("pathtoscriptsfolder") sys.path.append(folder) for script in os.listdir(folder): if script.endswith(".py"): mod = __import__(script) res = mod.run_test() fh = open("tests.res", "a") fh.writeline(str(res)) [/code] | |
Re: EDIT: Woops I misunderstood the link structure. Also when working with regex, it's probably a good idea to test them independently before incorporating them into code. For example, test the regular expression at idle with a couple of the links and make sure they work. | |
Re: [quote=zandiago;451778]From the caribbean...luving my sunshine[/quote] Which island? I'm from St Vincent | |
Re: One thing I've noticed is that Python often has a module to mundane tasks that we can sometimes waste time doing by ourselves. It's especially surprising if I've been programming in a language like C or C++ for a while. It really is batteries included. | |
Re: Actually those have modules for python 2.6 as well, which is the better choice if you're writing code that you someday would like to port to 3.0. | |
Re: [code=python] pieces = [] while len(message) > 600: pieces.append(message[:600]) # slice from the start up to (but not including) the 600th character. message= message[600:] #slice from the 600th character to the end. pieces.append(message) [/code] That should split the string up into pieces that are 600 characters long or less. The … | |
Re: There's also os.listdir. | |
I couldn't help but notice that everytime I create a window or control with Win32, the text on the window looks jagged, as though it isn't being 'clear-typed' or something. Does anybody know how I can get the text to appear normal? | |
Re: you can use a list comprehension: [code=python] new_list = [float(integral) for integral in old_list] [/code] | |
Re: Strip only remove spaces from eaither side You can loop through the string yourself and count each character that isn't a space (recommended if this is homework)(you can loop through strings just like you would loop through a list), or you can use S.count(" ") and subtract that from len(S) … | |
Re: This is a job for javascript. Something in the textbox onchange event: [code=Javascript](document.getElementsByName("sailing1")[0].value == "")? document.getElementsByName("sailingEx1")[0].style.visibility = "hidden" : document.getElementsByName("sailingEx1")[0].style.visibility = "visible"; ... [/code] You would need to hide the select boxes to be invisible when the page loads: [code=Javascript] document.getElementsByName("sailngEx1")[0].style.visibilty = "hidden"; ... [/code] This would only work if … | |
Re: We don't have separately defined arrays. Lists are the closest thing we got, I believe. There is a library called NumPy that implements C arrays for python. The only limitation ( I think ) is that they must be arrays of numbers. | |
Does Python have a concept of class properties (static properties if you may)? I know there are class attributes, but I can't just use one. It's very critical that I control what values can bet set as the class attribute, which I can use the property setter to do. | |
Re: Consider this: Say (just pretend) you have a objects called CD with the following attributes: shape size capacity [Actions/Methods] Spin Record Then you would have to implement all of those properties and actions. Now say you wanted an object called DVD with the exact same attributes. Ordinarily, you would have … | |
Re: Some will say yes, some will say no. This, I think, is a matter of opinion. My opinion is that it can't hurt to learn how to do it. Python is one of the languages that handles it well, so it won't be hard to learn with the right material. … | |
I know Python introspection feature are powerful, what I can't seem to figure out is how to get the name of the current class. Example: class Foo: def bar(self): print(classname) Then my output should be `Foo`. Bonus points if I can get which module it resides in too. Thanks! | |
Several things have led me to writing this post However, late last week I did some poking around in the Windows C API from ctypes (not using pywin32) for a project I was finishing up, and I [I]loved it[/I]! Since then I've been playing around with ctypes and Windows function … | |
Re: PyQt is by far the best gui toolkit for python. wxPython and pyGTK can't compare to it. It is a truly cross platform commercial grade library with excellent documentation. The only reason it doesn't have a broader user base is because the free version is under a gpl license (soon … | |
Re: What's happening is that you aren't adding the numbers; you're concatenating strings. In python, "hello" + "world" = "helloworld". To get what you want, convert the input to integers using int() | |
Re: I think the idea is that you use the vector objects to transform other objects. The calculations would be done for you. Makes life a little less tedious. | |
Re: [code=python] for f in arr: if f > 100: return f [/code] Is that what you wanted? | |
Re: Works fine for me too: [code=python] <__main__.Rational instance at 0x023A56E8> [/code] Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 | |
Re: Instead of all those print statements at the top, you can put [code="python"] print "\n" * (blank lines you desire - 1) [/code] | |
Re: The newline character in python is '\n'. [code=python] print "Hello\nGoodbye" [/code] or for python 3: [code=python] print("Hello\nGoodbye") [/code] The print statement in python (except python 3) automatically adds a newline at the end. | |
Re: Relax, it's not a stupid question. Here's the proper syntax: [code=python] if not something \ not somethineElse and \ not someOtherThing and \ not thisThing: print "asdf" [/code] You can use \ anywhere you need to continue a statement on the next line. | |
![]() | Re: del is a command not a method: [code=python] del lst[index] [/code] You can also do: [code=python] lst.remove(item) [/code] and [code=python] removed = lst.pop(index) [/code] The second seems to be the one you want. ![]() |
Re: I have a feeling he's already using that module. Look at the imports. | |
Re: Apart from what vegaseat said (you really do need to define before you call) it's a matter of personal taste. I use [url]http://www.python.org/dev/peps/pep-0008/[/url] because the resulting code is easy to understand. | |
Re: It's not that hard to do that with the example given, granted the resulting code is a little bit nasty: [code=python] spaces = [] position = 0 for c in text: if c == ' ': spaces.append(position) position += 1 [/code] Not so hard is it? | |
Re: Either you don't know what you're talking about, or I don't know what I'm talking about. IO operations are synchronous in python unless an asynchronous operation is explicitly requested. This means that the program will block (execution will stop and wait) until the operation has either completed or failed. When … | |
![]() | Re: Depends on what you mean by IDE. I wholeheartedly recommend Geany as generic choice. It's cross platform actually. I think of it as a hybrid between and IDE and a text-editor. It has some nice IDE oriented features, but few enough so that it's quite quick. ![]() |
This function is supposed to take an integer that contains an rgb value, extract the value of each channel, and then return that calculated luminance of the pixel. As it stands, the performance of this function is not fast enough. Looking at it, I can't think of anything else that … | |
Re: Microsoft has not yet announced any plans for a second service pack for Vista. | |
And please don't tell me it's not possible. | |
How can I install pygame against the 64 bit version of python for windows? I tried the regular win32 package but imports don't work. | |
Re: That code doesn't give a syntax error with python 2.5.4 or 2.6.1. And you should really consider upgrading. That version is over six years old! |
The End.