939 Posted Topics

Member Avatar for breatheasier

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]

Member Avatar for breatheasier
0
179
Member Avatar for Z8934

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 …

Member Avatar for Gribouillis
0
159
Member Avatar for JeyC
Member Avatar for YoungCoder
Member Avatar for chriswellings
0
708
Member Avatar for harrykokil

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.

Member Avatar for scru
0
67
Member Avatar for mannclay
Member Avatar for daniwebnewbie

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 …

Member Avatar for paddy3118
0
261
Member Avatar for JeyC

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]

Member Avatar for JeyC
0
122
Member Avatar for alicem

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]

Member Avatar for jlm699
0
6K
Member Avatar for siddhant3s

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 …

Member Avatar for sneekula
0
773
Member Avatar for HatGuy

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 …

Member Avatar for HatGuy
0
145
Member Avatar for akshay.sulakhe

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.

Member Avatar for scru
0
130
Member Avatar for scru
Member Avatar for leegeorg07
0
156
Member Avatar for pythononmac

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]

Member Avatar for lllllIllIlllI
0
117
Member Avatar for katamole

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.

Member Avatar for katamole
0
678
Member Avatar for ProgrammersTalk

[quote=zandiago;451778]From the caribbean...luving my sunshine[/quote] Which island? I'm from St Vincent

Member Avatar for Ezzaral
0
602
Member Avatar for toadzky

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.

Member Avatar for scru
0
158
Member Avatar for vmars

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.

Member Avatar for vegaseat
0
225
Member Avatar for adam291086

[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 …

Member Avatar for scru
0
116
Member Avatar for mahela007
Member Avatar for 0wnage
Member Avatar for scru

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?

Member Avatar for WolfPack
0
127
Member Avatar for karthik.c

you can use a list comprehension: [code=python] new_list = [float(integral) for integral in old_list] [/code]

Member Avatar for scru
0
20K
Member Avatar for curiouskitten

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) …

Member Avatar for oldSoftDev
0
106
Member Avatar for l00pylou

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 …

Member Avatar for almostbob
0
128
Member Avatar for karthik.c

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.

Member Avatar for karthik.c
0
185
Member Avatar for scru

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.

Member Avatar for Ene Uran
0
102
Member Avatar for mahela007

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 …

Member Avatar for lllllIllIlllI
0
652
Member Avatar for mahela007

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. …

Member Avatar for jrcagle
0
80
Member Avatar for scru

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!

Member Avatar for Ene Uran
0
135
Member Avatar for scru

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 …

Member Avatar for lllllIllIlllI
0
215
Member Avatar for artemis_f

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 …

Member Avatar for Stefano Mtangoo
0
163
Member Avatar for mruane

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()

Member Avatar for gbrokaw
0
103
Member Avatar for lllllIllIlllI

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.

Member Avatar for Ene Uran
0
131
Member Avatar for MaxManus

[code=python] for f in arr: if f > 100: return f [/code] Is that what you wanted?

Member Avatar for scru
0
4K
Member Avatar for drone626

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

Member Avatar for drone626
0
126
Member Avatar for mruane

Instead of all those print statements at the top, you can put [code="python"] print "\n" * (blank lines you desire - 1) [/code]

Member Avatar for mruane
0
148
Member Avatar for darkfury18

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.

Member Avatar for scru
0
4K
Member Avatar for nclouse

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.

Member Avatar for nclouse
0
78
Member Avatar for leegeorg07

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.

Member Avatar for leegeorg07
0
96
Member Avatar for jworld2
Member Avatar for Stefano Mtangoo
0
588
Member Avatar for eyewirejets

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.

Member Avatar for Stefano Mtangoo
0
85
Member Avatar for wheatontrue

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?

Member Avatar for wheatontrue
0
143
Member Avatar for vjp08

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 …

Member Avatar for scru
0
166
Member Avatar for leegeorg07
Re: ides

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.

Member Avatar for leegeorg07
0
111
Member Avatar for scru

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 …

Member Avatar for vegaseat
0
153
Member Avatar for serendipity
Member Avatar for jbennet
0
360
Member Avatar for scru
Member Avatar for scru

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.

Member Avatar for Stefano Mtangoo
0
193
Member Avatar for whiteflags

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!

Member Avatar for Murtan
0
79

The End.