Posts
 
Reputation
Joined
Last Seen
Ranked #2K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
73% Quality Score
Upvotes Received
26
Posts with Upvotes
21
Upvoting Members
7
Downvotes Received
6
Posts with Downvotes
6
Downvoting Members
6
7 Commented Posts
~73.5K People Reached
About Me

Master's Degree in CS; Major in Automation Technology and Cybernetics; Passionate Pythoneer from the early days of Python; Former C++ nerd, but now clean.

Interests
making music, sci-fi
PC Specs
Python, Windows, Linux
Favorite Tags

45 Posted Topics

Member Avatar for keyoh

Arrr, too much code noise! ;-) If you know you have at least one file: [CODE]import os, glob largest = sorted( (os.path.getsize(s), s) for s in glob.glob('yourdir/*.avi') )[-1][1] [/CODE] If not, you split the code a bit: [CODE]import os, glob files = glob.glob('yourdir/*.avi') largest = sorted((os.path.getsize(s), s) for s in …

Member Avatar for The Geek Scope
0
5K
Member Avatar for KonkaNok

not even if it's mixed with such excellent features as Python's. ;) Sorry I'm not able to burst into enthusiasm. The statement alone, they would combine Python's development speed with the "safety of a compiled language like C or C++" is a farce. C++ is one of the unsafest languages …

Member Avatar for NETProgrammer
0
329
Member Avatar for AutoPython

This is not that new. [ICODE]msvcrt.getch()[/ICODE] was available on Windows with Python 2.5 already. Well, at least it was in the ActivePython distro. (Meaning: It's good news for pythoneers locked into older versions of Python.) That said, a good example of a finer grained keyboard/console control compared to the more …

Member Avatar for TrustyTony
0
7K
Member Avatar for vegaseat

If I may propose a semantically equivalent but much shorter alternative... [CODE]import re def analyzeText(text): sentences = re.findall(r'\s*(.+?)[.!?]\s*', text) wordsets = map(str.split, sentences) wordcounts = map(len, wordsets) charcounts = [ sum(len(word) for word in words) for words in wordsets ] return zip(sentences, wordcounts, charcounts)[/CODE] Test:[CODE] text = """\ Just a …

Member Avatar for snippsat
2
2K
Member Avatar for python.noob

Not all IDE's support code completion well. Of all IDE's I've tried, I found PyDev and Eric4 work best in this respect.

Member Avatar for MikaelHalen
0
1K
Member Avatar for lrh9

Sounds like your agents are plugins with no pre-defined interface. To load such modules, you can use [URL="http://www.daniweb.com/code/snippet238387.html"]this snippet[/URL]. Obviously, you can't just go [ICODE]modules[module_name].function()[/ICODE] in your case, because [ICODE]function[/ICODE] is not known in advance. I guess you'll have to inspect the module. Pythons [ICODE]inspect[/ICODE] module comes in handy: [CODE]import …

Member Avatar for lrh9
1
338
Member Avatar for lewashby

Better use a class method to access the class-level variables. Also, consider renaming "status" to "printStatus" as it more closely describes what the method does. [CODE]class Critter: ... @classmethod def printStatus(self, cls): print "\nThe total number of critters is", cls.total [/CODE]

Member Avatar for pythopian
0
550
Member Avatar for furblender

What you are trying to [ICODE]eval[/ICODE] is not valid python code. I'm not sure what all the curly braces are for, but your could either use [CODE]# wrap content in curly braces to make it valid dict syntax word_dic = eval('{%s}' % open("word.txt").read())[/CODE] or adapt your format to something like …

Member Avatar for furblender
0
3K
Member Avatar for MRWIGGLES

[QUOTE=MRWIGGLES;1057518]Is there a more simplistic way to do this [B]without having to import things[/B]? I'm a beginning at Python.[/QUOTE] You will always have to import stuff for anything but the most trivial tasks.

Member Avatar for vegaseat
0
214
Member Avatar for persianprez

[QUOTE=snippsat;1055838] [CODE]>>> sorted(d.items(), key=lambda (v,k): (v,k))[/CODE][/QUOTE] The above expression should read: [CODE]sorted(d.items(), key=lambda (k,v): (v,k)) # ^^^ k and v swapped[/CODE] Alternatively, one could just use [CODE]sorted(d.items(), key=lambda (k,v): v)[/CODE] Or for sorted printing: [CODE] for (k, v) in sorted(d.items(), key=lambda (k,v): v): print k, "%8s" % v[/CODE]

Member Avatar for persianprez
0
250
Member Avatar for rjmiller

[QUOTE=BearofNH;441029] The most expedient thing to do may be to just write the URL data to a local file and pass that handle to [B]loadtxt()[/B]...[/quote] If the amount of data is not huge, it's simpler to use StringIO as a temporary in-memory file: [code=Python] from cStringIO import StringIO e = …

Member Avatar for pythopian
0
213
Member Avatar for lewashby

I assume what you mean is to [B]execute[/B], not compile the code one line at a time. I don't use Wing IDE, but virtually all IDE's have a built-in debugger. (If it doesn't, it's not an IDE, but just an editor.) You need to set a [B]breakpoint[/B]t at the beginning …

Member Avatar for Mathhax0r
0
79
Member Avatar for lukerobi

The singleton concept is intependent of mutability. You can have singleton mutable object. Also, decorators are part of the language since (IMO) 2.4. I think your approach was principally correct, though I'd rather use an implementation like this (methods beyond construction skipped): [CODE]class MyList(list): __the_instance = None def __new__(cls, *elems): …

Member Avatar for Gribouillis
0
103
Member Avatar for dmcadidas15

[CODE]numbers = map(float, file('data.dat', 'rt').read().split()) average = sum(numbers) / len(numbers)[/CODE] For a case like masterofpuppets' above: [CODE]>>> average 4.0[/CODE] Note the use of [ICODE]float[/ICODE], not [ICODE]int[/ICODE], to cover floating point numbers in 'data.dat'.

Member Avatar for pythopian
0
108
Member Avatar for Fetch

[QUOTE=masterofpuppets;1047647]well, you need to put the .txt extension at the end of the newFile input to get a text file[/QUOTE] Sorry, but that's absolutely not true. The file type is *not* distinguished by extension. (It's more of a hint on Windows, and irrelevant on Linux. Don't know about Mac, but …

Member Avatar for vegaseat
0
96
Member Avatar for MRWIGGLES

[QUOTE=snippsat;1048442]You can do it like this. [CODE]def getValidNum(min, max): .... elif num == '0': break # instead of exit() .... [/CODE][/QUOTE] Rather use [ICODE]break[/ICODE] instead of [ICODE]exit()[/ICODE]. You don't probably want to abort the whole program at that point.

Member Avatar for pythopian
0
105
Member Avatar for sentinel123

[QUOTE=sentinel123;1047214]//Edit: If I limit the range to (0, columns - 1) it seems to work perfectly //Edit2: Is it because the list index starts with 0 (and not with 1)? I guess this is it...[/QUOTE] [CODE=text]>>> import random >>> help(random.randint) Help on method randint in module random: randint(self, a, b) …

Member Avatar for pythopian
0
149
Member Avatar for gunbuster363

[QUOTE=gunbuster363;1046900]problem solved....... I found out how to Navigate it.......[/QUOTE] And are you going to share your insights, [B]so that others could benefit from them[/B], or keep them to yourself?

Member Avatar for gunbuster363
0
2K
Member Avatar for pythopian

PlugIns in their simplest form can be just python modules that are dropped into some designated directory and dynamically loaded by the main application. This snippet can be used to do just that. [B][U]Usage[/U][/B] To load plugin modules: [CODE]>>> plugins = importPluginModulesIn('mypackage') >>> plugins {'foo': <module 'foo' from 'mypackage\foo.py'>, 'bar': …

Member Avatar for pythopian
2
826
Member Avatar for lllllIllIlllI

to import all modules of a package at once is to list the modules you want imported in the package's __init__.py file like this [CODE]__all__ = ['foo', 'bar'][/CODE] Then [CODE]from mypackage import *[/CODE] will import foo and bar. However if you need to import modules not known in advance (i.e. …

Member Avatar for pythopian
0
14K
Member Avatar for Mona1990

I'm not going to solve this for you, but I'm going to give you some hints. You can use the string method [CODE]join[/CODE] to combine a list of strings with a separator to one string. [CODE] [/CODE]

Member Avatar for Mona1990
0
300
Member Avatar for mahela007

[QUOTE=mahela007;1045210]So I tell something to tkinter and tkinter tells a translated version of that "something" to windows? If that's so, how come tkinter is cross platform? I mean, Linux and Windows do things quite differently so how would tkinter know what functions to call on each operating system?[/QUOTE] When they …

Member Avatar for mahela007
0
261
Member Avatar for XLL

[QUOTE=XLL;1045605]Hi all,I got a issue that how can I run several functions at same time? say [CODE] a=1 def function1(a) a+1 return a def function2(b) b+2 return b def plotGraph(a,b) return graph [/code] how can I just run plotGraph function here?..I am totally newb..hope anyone can help..thanks[/QUOTE] That code does …

Member Avatar for pythopian
0
114
Member Avatar for jex89

[LIST=1] [*]Unpickle the XML document into memory [*]Save it as a plain text file [*]Edit that file in a text or XML editor [*]Load that file's contents back in Python [*]Pickle them again. [/LIST] I am assuming you know how to pickle and unpickle files, and how to load and …

Member Avatar for pythopian
0
3K
Member Avatar for leegeorg07

I wonder you haven't got exceptions. Use [B]import cgitb; cgitb.enable()[/B] at the beginning of your scripts to display them. After obtaining [B]b = a['b'][/B], [B]b[/B] is a string, and [B]range(1, b)[/B] will crash. You need to convert it to int first. [B]range(1, b)[/B] is probably not quite what you want. …

Member Avatar for leegeorg07
0
255
Member Avatar for Danman290

[QUOTE=Danman290;1044460]I assume that the lists are immutable inside the "step" method, but why would this be[/QUOTE] You are right to doubt that - they aren't. Look at your lines 24 and 26, there you will find [CODE] self.mouse_c = 1 else: self.mouse_c = 0[/CODE] whereas it should have been [CODE] …

Member Avatar for Danman290
0
16K
Member Avatar for lookatmills

[CODE]smallest = min(numbers)[/CODE] Say: [CODE]text = '''\ Alabama 3200 Denver 4500 Chicago 3200 Atlanta 2000 ''' def parseLine(line): s, t = line.split() return int(t), s items = [ parseLine(line) for line in text.splitlines() ] >>> print min(items) (2000, 'Atlanta') [/CODE]

Member Avatar for pythopian
0
71
Member Avatar for figved

I see that this is about "scraping a website". Do we not care if that would infringe someone's copyright? Or at least if it be ethically questionable? I don't want to sound straitlaced, but wouldn't it be better we knew more about it before offering help with this?

Member Avatar for pythopian
0
316
Member Avatar for pythopian

This is one simple way to emulate a singleton class on behalf of a normal class. (A singleton class is a class with at most one instance.) The implementation does not emulate a class 100% (for example it lacks the special attributes lile __dict__ or __bases__), but it should be …

2
234
Member Avatar for pyprog

[B]dict.setdefault[/B] is the way to go: [CODE]import re def parse(text): items = re.findall('^(\w+)\s+(\d+)\s*$', text, re.M) data = {} for key, val in items: # data.setdefault(key, []).append(val) #<= add string values data.setdefault(key, []).append(int(val)) #<= add int values return data [/CODE] Test: [CODE]#text = file('data.txt', 'rt').read() text = '''\ a 1 a …

Member Avatar for pythopian
0
1K
Member Avatar for LB22

Your post does not provide many details, but I think what you are looking for is a generator function., Instead of returning an URL, [B]yield[/B] each URL, like this: [CODE] def generateURLs(startingURL): url = startingURL ... while url: yield url url = getNextURL(url) ... for url in generateURLs(http://click.someurl.net/script?query=somedata): print url …

Member Avatar for pythopian
0
151
Member Avatar for plzhelp

If you want to search sequences with more than 2 levels of nesting, you could do this: [CODE]def deepfind(obj, test=lambda value: True): if not isinstance(obj, (list, tuple)): if test(obj): yield obj else: for each in obj: for found in deepfind(each, test): yield found def test(): data = [ ['abc', 'def', …

Member Avatar for pythopian
0
93
Member Avatar for masterinex

[CODE]def writeListsToFile(filename, l1, l2, l3, separator='\t'): assert len(l1) == len(l2) == len(l3) output = '\n'.join(map(lambda *items: separator.join(items), l1, l2, l3)) file(filename, 'wt').write(output) [/CODE]

Member Avatar for masterinex
0
290
Member Avatar for CurtisEClark

Quick hint: Instead of the condition cascade [CODE]if z == "circle": ... elif ...[/CODE] consider a more pythonically succinct approach: [CODE]assert n in ('circle', 'line', 'rect') draw = getattr(pygame.draw, n) draw(screen, (random.randrange(255), random.randrange(255), random.randrange(255)), (random.randrange(640), random.randrange(480)), 50 ) [/CODE]

Member Avatar for CurtisEClark
0
491
Member Avatar for mitsuevo

Instead of mixing string with floats, consider [CODE]myarr = [0.0] * full_length[/CODE] I don't know if that's the case here, but often you don't need all the slots in the array in one session, but only a few. Instead of allocating the full size, you may consider storing (index, value) …

Member Avatar for mitsuevo
0
10K
Member Avatar for mitsuevo

... but you've made some mistakes with regex flags and pattern details. Also, your data contains only one DHCP Offer and one DHCP Request. If you need both IP's, you can use this: [CODE]>>> print re.findall(r'DHCP\s+.*?Internet Protocol,\s+Src:\s*(.+?)\s*\(.*?Bootstrap', text, re.M|re.S) ['192.168.110.33', '0.0.0.0'][/CODE] To get offer and request IP's individually, use: [CODE]>>> …

Member Avatar for mitsuevo
0
223
Member Avatar for pyprog

You need to distinguish between a function definition [CODE]def func(filename): ... # d something with filename[/CODE] and a function call: [CODE]func("something.txt")[/CODE]

Member Avatar for pythopian
0
115
Member Avatar for pyprog

Resort to regular expressions. Begin with: [CODE]import re s = file('something.txt', 'rt').read() [/CODE] Then, if it's OK for the dictionary values to be strings, use: [CODE]d = dict( re.findall(r'^(\S),\S,(\d)$', s, re.M) )[/CODE] Otherwise use: [CODE]d = dict( (key, int(val)) for (key, val) in re.findall(r'^(\S),\S,(\d)$', s, re.M) )[/CODE] In both cases, …

Member Avatar for pythopian
0
131
Member Avatar for lewashby

Python is an excellent choice for web programming (as it is for any other type of programming). There are myriads of web frameworks to choose from, some of which are [B]really good[/B]. But [B]Python is not mainstream[/B]. PHP is. A random choice of project or company is likely to dictate …

Member Avatar for pythopian
0
634
Member Avatar for saikeraku
Member Avatar for trihaitran

[URL="http://pythonsimple.noucleus.net/python-install/python-site-packages-what-they-are-and-where-to-put-them"]This article describes where to put shared python site-packages[/URL]. It provides instructions how to separate version-specific from version-independent python packages and avoid the burden of maintaining multiple redundant module sets.

Member Avatar for pythopian
0
190
Member Avatar for sneek

[QUOTE]why should I use the python implementation if the result is the same but the performance is worse?[/QUOTE] For portability, for instance. Sometimes a C version is not available on all platforms, or not at the same time at least, so what you do is [CODE] try: import cFoo as …

Member Avatar for pythopian
0
138
Member Avatar for sravan953

Note that the way you use try/except is not very wise. [CODE] try: self.s.sendmail(self.user,self.to,self.msg) wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') self.s.quit() except: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red') [/CODE] You should do something like this instead: [CODE] try: self.s.sendmail(self.user,self.to,self.msg) except LoginError: wx.StaticText(self.panel,-1,"Mail not sent",pos = (120,435)).SetForegroundColour('red') else: wx.StaticText(self.panel,-1,"Mail send successfully",pos = (120,435)).SetForegroundColour('blue') …

Member Avatar for pythopian
0
618
Member Avatar for shaan07

Use any of the known markup languages to write the text file (reStructuredText, MarkDown, Kiwi ...) and use the corresponding tool to convert it to HTML (Docutils, MarkDown for Python, [url]http://www.ivy.fr/kiwi/[/url]). You can also use those tools' API to integrate them in your own app. You don't need no XML …

Member Avatar for pythopian
0
131
Member Avatar for simpatar
Member Avatar for pythopian
0
178

The End.