python

Get Root Domain of Link

I have a link such as http://www.techcrunch.com/ and I would like to get just the techcrunch.com part of the link. How do I go about this in python? ...

Using Python's isinstance

The following usage of isinstance doesn't seem to work in Python 2.5.2 or 2.6.2: class BananaCake: def __init__(self): print 'Banana Cake' class ChocolateCake: def __init__(self): print 'Chocolate Cake' class CakeFactory: @staticmethod def create(name): if name == 'banana': return Ba...

Close Python when Parent is closed

I have a Python program (PP) that loads another Program(AP) via COM, gets its window handle and sets it to be the PP parent. This works pretty well except that I can't control that AP still has their [X] button available in the top left corner. Since this is a pretty obvious place for the user to close when they are done with the progr...

How to prevent log file truncation with python logging module?

Hi there, I need to use python logging module to print debugging info to a file with statements like: logging.debug(something) The file is truncated (i am assuming - by the logging module) and the messages get deleted before I can see them - how can that be prevented? Here is my logging config: logging.basicConfig( level = loggi...

Cost of list functions in Python

Based on this older thread, it looks like the cost of list functions in Python is: Random access: O(1) Insertion/deletion to front: O(n) Insertion/deletion to back: O(1) Can anyone confirm whether this is still true in Python 2.6/3.x? ...

How to specify date and time in python?

Quite simple newbie question: What is the object used in python to specify date (and time) in Python? For instance, to create an object that holds a given date and time, (let's say '05/10/09 18:00'). EDIT As per S.Lott request, what I have so far is: class Some: date = I stop there, after the "=" sign for I realize I didn't kn...

How create jinja2 extension?

I try to make extension for jinja2. I has written such code: http://dumpz.org/12996/ But I receive exception: "'NoneType' object is not iterable" Where is a bug? That should return parse. Also what should accept and return _media? ...

How to fix such ClientForm bug?

Hello, the following code from mechanize import Browser br = Browser() page = br.open('http://wow.interzet.ru/news.php?readmore=23') br.form = br.forms().next() print br.form gives me the following error: Traceback (most recent call last): File "C:\Users\roddik\Desktop\mech.py", line 6, in <module> br.form = br.forms().next() ...

Could someone recommend video tutorial websites for beginners?

I'm not sure what it is about me but I seem to learn and retain information better through a classroom setting where what's being shown is explained clearly and easy to understand examples are presented. I rarely do my own reading or research, but I do occasionally stumble upon some neat things. Maybe I'm just used to the classroom set...

Put bar at the end of every line that includes foo

Hi, I have a list with a large number of lines, each taking the subject-verb-object form, eg: Jane likes Fred Chris dislikes Joe Nate knows Jill To plot a network graph that expresses the different relationships between the nodes in directed color-coded edges, I will need to replace the verb with an arrow and place a color code at ...

(Python) Passing a threading.Thread object through a function?

I have a timer function: # This is a class that schedules tasks. It will call it's ring() funtion # when the timer starts, and call it's running() function when within the # time limit, and call it's over() function when the time is up. # This class uses SYSTEM time. import time, threading import settings from object import Object c...

map string position to line number in regex output

I'm working on a "grep-like" utility in Python for searching Oracle source code files. Coding standards have changed over time, so trying to find something like "all deletes from table a.foo" could span multiple lines, or not, depending on the age of that piece of code: s = """-- multiline DDL statement DELETE a.foo f WHERE f.b...

Get partial stdout and stderr from Popen that runs indefinitely

I'm building a wrapper around a server cmd line script that should run indefinitely. What I need to do is to get the current stout without waiting for the subprocess to finish. I mean, if I run the following, everything works fine: ls = Popen(["ls"], stdout=PIPE) output = ls.stdout.read() But if I do the same with an indefinitelly ru...

How do I run a Python program?

So I'm starting like Python a bit, but I'm having trouble erm...running it. Lol I'm using IDLE for now, but its no use whatsoever because you can only run a couple of lines at a time. I'm also using Komodo Edit to create the actual .py files. My question is, how can I run the .py files to test out the actual program? I'm using Windo...

should I call close() after urllib.urlopen()?

new to python and reading someone else's code: should urllib.urlopen() be followed by urllib.close()? Otherwise, one would leak connections, correct? ...

How do I get the module instance for a class in Python?

I am learning Python, and as always, I'm being ambitious with my starter projects. I am working on a plugin system for a community site toolkit for App Engine. My plugin superclass has a method called install_path. I would like to obtain the __path__ for the __module__ for self (which in this case will be the subclass). Problem is, _...

Problem running a very simple Python program.

Why is my program giving me an error here? import random TheNumber = random.randrange(1,200,1) NotGuessed = True Tries = 0 GuessedNumber = int(input("Take a guess at the magic number!: ")) while NotGuessed == True: if GuessedNumber < TheNumber: print("Your guess is a bit too low.") Tries = Tries +...

how to apply "catch-all" exception clause to complex python web-scraping script?

Hi, I've got a list of 100 websites in CSV format. All of the sites have the same general format, including a large table with 7 columns. I wrote this script to extract the data from the 7th column of each of the websites and then write this data to file. The script below partially works, however: opening the output file (after running ...

flup/fastcgi cpu usage under no-load conditions

I'm running Django as threaded fastcgi via flup, served by lighttpd, communicating via sockets. What is the expected CPU usage for each fastcgi thread under no load? On startup, each thread runs at 3-4% cpu usage for a while, and then backs off to around .5% over the course of a couple of hours. It doesn't sink below this level. Is thi...

python: how do you setup your workspace on Ubuntu?

Lets say I have my workspace (on Eclipse) where I develop my Python modules and I would like to "link" my working files to system Python paths. I know I can drop .pth files etc. but I would like to get the community's wisdom as to the best practices. ...