2,646 Posted Topics

Member Avatar for smohrchi

[url=http://diveintopython.org/]Dive into python[/url] has a good reputation. A good part of learning python is learning the standard library. Note that the library has been reorganized in python 3, so that some module names may differ, and some code may run with python 2.x and not python 3.x.

Member Avatar for jaux
0
92
Member Avatar for NicholasE

You don't even need the readlines(). You can iterate on the file object directly. On the other hand, after the file has been read, the file position is at the end of the file, so you must use seek to go to the beginning of the file [CODE]initFile = open( …

Member Avatar for Gribouillis
0
123
Member Avatar for lenfranc

I think the point is that directories have many other reasons to exist than being python packages. So if you write a python package named 'books' for example. You can create other 'books' directories here and there, python will still find the package 'books' because it has an __init__.py file.

Member Avatar for lenfranc
0
157
Member Avatar for Aiban

You can get a drive letter from a path like this [code=python] import os drive = os.path.splitdrive(mypath)[0] print(drive) [/code] Now for mypath, you could use either the current working dir [icode]os.getcwd()[/icode] or your module's file path [icode]__file__[/icode]. Then you can call the dos command using [icode]subprocess.Popen[/icode] (I normally work on …

Member Avatar for Stefano Mtangoo
0
299
Member Avatar for Tech B

Don't you think you could save some CPU usage if you replaced the "while 1" by a timer which would run the loop at a certain frequency ?

Member Avatar for fallopiano
0
526
Member Avatar for Prahaai

A similar problem has already been posted in this forum. For a multiplatform solution, I suggest that you try to use the class Popen in [url=http://code.activestate.com/recipes/440554/]this activestate recipe[/url]. It contains a very sophisticated solution. See if it applies to your problem.

Member Avatar for Gribouillis
0
346
Member Avatar for biotic.computer

I suggest the following replacement for Starter_AA: [code=python] from pprint import pprint mapping = """ Phe: UUU, UUC; Leu: UUA, UUG, CUU, CUC, CUA, CUG; Iso: AUU, AUC, AUA; Met: AUG; Val: GUU, GUC, GUA, GUG; Ser: UCU, UCC, UCA, UCG, AGU, AGC; Pro: CCU, CCC, CCA, CCG; Thr: ACU, …

Member Avatar for Gribouillis
0
112
Member Avatar for marcux

You must overwrite the __setitem__ method [code=python] class mydict(dict): def __setitem__(self, key, value): doStuff() return dict.__setitem__(self, key, value) [/code]

Member Avatar for Gribouillis
0
194
Member Avatar for sneek

I think it maintains the traditional distinction between allocation and initialization. When you use structures in C for example, you must first use malloc to allocate a structure and then you initialize the structure's content. These are 2 different kinds of operations. For example you can decide to change your …

Member Avatar for sneek
0
189
Member Avatar for NicholasE

There is nothing very clever here. You must learn to think about algorithms. You want to output a series of blocks of lines; each block is indexed by the the number k in file<k>.tcl. So the structure of your algorithm is (this is pseudo code, not python) [code=text] for k …

Member Avatar for NicholasE
0
111
Member Avatar for SoulMazer

You should also read the documentation of the standard lib module [b]atexit[/b] which gives example of how you can register functions to be executed at program termination.

Member Avatar for SoulMazer
0
103
Member Avatar for thesinik

[QUOTE=thesinik;1060404]I ended up figuring it out by breaking down sin into a function of series rather than using Taylor expansions. It was much simpler. This was my code for sin: [CODE] def sine(x): sum = 0.0 n = 0.0 term = 1.0 while (term > .0000000001): #loops until the iterations …

Member Avatar for thesinik
0
4K
Member Avatar for SoulMazer

I have a small collection of receipes found on the web a long time ago. See if one of them can help you [code=python] # linux, mac os.kill(pid, signal.SIGKILL) killedpid, stat = os.waitpid(pid, os.WNOHANG) if killedpid == 0: print >> sys.stderr, "ACK! PROCESS NOT KILLED?" # windows handle = subprocess.Popen("someprocess …

Member Avatar for SoulMazer
0
269
Member Avatar for ShadyTyrant

I prefer design 1. We don't know anything about the algorithms that you have in mind, so there is no obvious benefit for introducing the classes Search and Edit. With design 1, the Library object appears as a facade behind which you can implement arbitrary complex and flexible algorithms. Also …

Member Avatar for ShadyTyrant
2
262
Member Avatar for lewashby

The indentation is bad. The code should read [code=python] # Classy Critter # Demonstrates class attributes and static methods class Critter(object): """A virtual pet""" total = 0 def status(): print "\nThe total number of critters is", Critter.total status = staticmethod(status) def __init__(self, name): print "A critter has been born!" self.name …

Member Avatar for pythopian
0
550
Member Avatar for Kruptein

[QUOTE=Kruptein;1058422]I found out the launcher is actually called: localhost.desktop but if I do: [icode]os.system("~/localhost.desktop")[/icode] it just starts my standard editor and shows the script...[/QUOTE] I don't know ubuntu very well, but if your launcher is related to a bash script, the script must be somewhere in the filesystem, so locate …

Member Avatar for Kruptein
0
203
Member Avatar for bsod1

[QUOTE=vegaseat;1058172] Note (so you don't waste your time): bpython uses Linux's curses and does not work with Windows.[/QUOTE] bpython doesn't even work on my linux box. It could be the 64 bits chipset...

Member Avatar for AutoPython
-1
92
Member Avatar for MRWIGGLES

You can use the modules HTMLParser and collections.deque to implement the queue [code=python] from HTMLParser import HTMLParser from collections import deque # deque is a linked list which can be used as fifo or filo class MyHTMLParser(HTMLParser): def __init__(self): HTMLParser.__init__(self) self.tag_deque = deque() def handle_starttag(self, tag, attrs): self.tag_deque.append("<{t}>".format(t=tag)) def handle_endtag(self, …

Member Avatar for vegaseat
0
214
Member Avatar for ffs82defxp

You can write [code=python] webbrowser.get('firefox').open("http://www.google.com/") [/code] Sometimes it's better to open firefox with subprocess like this [code=python] import subprocess as sp child = sp.Popen(['firefox', '-p', 'myprofile', '-no-remote', "http://www.google.com/"]) [/code] this allows you to open firefox with a different profile, or to close firefox later from your program (with child.terminate()).

Member Avatar for Gribouillis
0
85
Member Avatar for Archenemie

I modified your code so that it prints the file name and the destination name instead of renaming the file. Run it and modifiy it until it gives the correct values, then uncomment the 'rename' line. [code=python] #!/usr/local/bin/python import re, os from os.path import join as pjoin, isdir while True: …

Member Avatar for Archenemie
0
197
Member Avatar for Mona1990

theIndex[124] is a list, so you can just write [code=python] theIndex[124].append("m") [/code]

Member Avatar for Mona1990
0
70
Member Avatar for ffs82defxp

Try to run the loop 1 000 000 times instead of 1000. On my machine, it takes 0.0818829536438 seconds for 1 million times. See also the module timeit.

Member Avatar for woooee
0
107
Member Avatar for sneek

Steal means that the item will be referenced in the tuple, but without increasing it's reference count. When the tuple is deleted, the object will be decrefed. For example if you create a python integer with PyInt_FromLong, you normally need to decref this integer before leaving the current function, otherwise …

Member Avatar for sneek
0
416
Member Avatar for mahela007
Member Avatar for Gribouillis
0
158
Member Avatar for python.noob

If your compile can't find Python.h, you must add an include directory. On my system, I get [code=python] >>> from distutils import sysconfig >>> sysconfig.get_python_inc() '/usr/include/python2.6' [/code] So for Python.h, I need the compiler option [icode]-I/usr/include/python2.6[/icode].

Member Avatar for python.noob
0
703
Member Avatar for Mattokun99

You could write something like [code=python] from time import sleep import os def wait_file(filename): cnt = 3 * 60 while cnt > 0: if os.path.isfile(filename): return cnt -= 1 sleep(1) raise SystemExit [/code]

Member Avatar for Mattokun99
0
83
Member Avatar for k1w1dad

You can write [code=python] from os.path import join as pjoin targetfolder = raw_input('enter a target folder:\n').strip() newname = raw_input('enter a new base name:\n') newname = pjoin(targetfolder, newname) ... [/code] If you don't want to nuke your jpegs, make a zip file with the whole folder before doing anything.

Member Avatar for Gribouillis
0
206
Member Avatar for lukerobi

[QUOTE=lukerobi;1053226]Sorry for the very slow reply, but for some reason this method is crashing my program... I guess i will have to try to figure out another solution :([/QUOTE] First, if it's crashing your program, there must be an exception traceback. Also why don't you simply create a normal class …

Member Avatar for Gribouillis
0
103
Member Avatar for Gribouillis

This snippet defines a context to execute a block of statements in a different working directory (with the help of the with statement). After the block is exited, the initial working directory is restored, even if an exception has occurred in the with block.

0
591
Member Avatar for col415

The str(d) in the argument doesn't work. I suggest that you use the subprocess module [code=python] import subprocess as SP SP.Popen(["c:\\program files\\webteh\\bsplayerpro\\bsplayer.exe", "-stime="+str(d), "d:\\rodin\\rodin.mp4"]) [/code]

Member Avatar for col415
0
142
Member Avatar for lewashby

Note that in python 3, there are no 'old style class', so that your class is implicitely a subclass of object. Here is a small experiment with python 2.6 and python 3.1 [code=python] Python 2.6.4 (r264:75706, Oct 27 2009, 15:50:27) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" …

Member Avatar for mn_kthompson
0
131
Member Avatar for lewashby

For a crash reference, there is [url=http://www.limsi.fr/Individu/pointal/python/pqrc/versions/PQRC-2.4-A4-latest.pdf]PQRC[/url]. There is also [url=http://home.uchicago.edu/~gan/file/python.pdf]another one[/url] here, probably less complete.

Member Avatar for python user
0
187
Member Avatar for kapcom01

Google found a patch for scapy.all..sniff, wich allows to stop the sniff function programmatically. You should try this [url=http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout]http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout[/url]

Member Avatar for kapcom01
0
1K
Member Avatar for jaison2

I modified your code to give you a first running version [code=python] from graphics import * def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def eyePicker(): colour = raw_input("Please enter the colour: ") return colour # <- return the picked colour def drawEye( #win, centre, radius, …

Member Avatar for Kobrakai
0
227
Member Avatar for lllllIllIlllI

You could go this way, assuming that you have a folder named 'mypackage' wich contains a file '__init__.py' [code=python] # tested with py 2.6 import os import mypackage def module_names(package): # This only finds python modules which name doesn't start with '__' folder = os.path.split(package.__file__)[0] for name in os.listdir(folder): if …

Member Avatar for pythopian
0
14K
Member Avatar for A_Dubbs

[QUOTE=jbennet;1045803]By using encapsulation you ensure fidelity of data, and provide a known interface to others who may extend or use your class, making refactoring much less painful.[/QUOTE] The author of the article meant that the "property" function replaces getters and setters. In fact python's "property" encapsulates the attribute, and also …

Member Avatar for bumsfeld
1
230
Member Avatar for sanchitgarg

You can make a list with your functions [code=python] import random funcs = [func0, func1,func2,func3,func4,func5,func6,func7,func8,func9,] funcs[random.randrange(10)]() # <- call a random function random.choice(funcs)() # <- another way [/code] edit: jlm699 was faster :)

Member Avatar for sanchitgarg
0
244
Member Avatar for leegeorg07

[url=http://blog.doughellmann.com/2007/07/pymotw-subprocess.html]This one[/url] perhaps ?

Member Avatar for leegeorg07
0
95
Member Avatar for zyrus001
Member Avatar for Gribouillis
0
266
Member Avatar for nirah_pooh

What they mean is that you must run these commands [code] patch-p1-i clammwin/patches/wxPython-2424.maskededit.patch patch-p1-i clamwin/patches/wxPython-2424.throbber.patch patch-p1-i clamwin/patches/wxPython-2424.timectrl.patch [/code] in a cygwin terminal. Perhaps you need to put a space before -p1 and before -i.

Member Avatar for Gribouillis
0
171
Member Avatar for vansoking

Notice [icode]getpass.getuser()[/icode] which finds your login name (does it work on mac ?).

Member Avatar for vansoking
1
399
Member Avatar for ihatehippies

[QUOTE=vegaseat;1044320]We wouldn't have this problem if Windows machines would ship with Python installed. The real problem is that MS wants to make money with their old VB interpreter.[/QUOTE] I think that Van Rossum prefers OSX, and he works for Google, which makes 2 other obstacles.

Member Avatar for vegaseat
0
110
Member Avatar for persianprez

[QUOTE=persianprez;1021594]Thanks a bunch! worked as usual. You can see my complete source code or download it here: [url]http://pedrumgolriz.com/index/?p=52[/url][/QUOTE] You should wrap you code in tags at your web site to preserve indentation.

Member Avatar for persianprez
0
125
Member Avatar for figved

[QUOTE=pythopian;1043157]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?[/QUOTE] When you …

Member Avatar for pythopian
0
318
Member Avatar for xm1014

You can use the 'key' argument to 'sort' or 'sorted'. Here, Data is a list. You can write [code=python] def my_key(item): return item[1][1] # this returns 3.1 if item is ('1023', ['Name', '3.1', 'SomeData']) Data.sort(key = my_key) [/code] Data is easily turned into a dictionary: [code] Data = dict(Data) L …

Member Avatar for vegaseat
0
444
Member Avatar for Yeen

You can try [code=python] while rounds > max(player_point, cpu_point) [/code]

Member Avatar for vegaseat
0
306
Member Avatar for mitsuevo

You can use [url=http://www.daniweb.com/code/snippet217237.html]this code snippet[/url].

Member Avatar for mitsuevo
0
223
Member Avatar for mitsuevo

In idle you can restart the shell in the shell menu. Normally, this kills your execution because idle starts a new process.

Member Avatar for jlm699
0
110
Member Avatar for gangster88

According to your previous post, I think that you are using the "graphics.py" module [url=http://mcsp.wartburg.edu/zelle/python/]like this one[/url]. In that case, since p1 and p2 are not numbers but Points, you must use first p1.getX() and p1.getY() to get the coordinates of the points.

Member Avatar for gangster88
0
177
Member Avatar for P00dle

[QUOTE=woooee;1038091] It takes a large amount of self control not to respond with Can Python do this? (Who are you, Steve Urkel) I need help (We all do but most of us can't afford a psychiatrist) Help (Have you fallen and can't get up?)[/QUOTE] The answer to "Can Python do …

Member Avatar for P00dle
0
163

The End.