python

same line behaves correctly or gives me an error message depending on file position

gives me an error message: class logger: session = web.ctx.session #this line doesn't give me an error message: class create: def GET(self): # loggedout() session = web.ctx.session #this line form = self.createform() return render.create(form) Why? ...

How make work import of python26.zip on windows

I need to deploy a embeded version of python26. I have it working under windows folowing the setup of http://www.portablepython.com/. However after read this I try to pack everything into a zip file, and left out python.exe, python26.dll. However, that not work if python is not pre-installed. Also, I try pre-compilling everything with...

In Python, how can I access the namespace of the main module from an imported module?

Specifically, I need to get at some objects and globals from the main module in an imported module. I know how to find those things when the parent module wants some particular thing from a child module, but I can't figure out how to go in the other direction. ...

Tooltips not showing up on Ubuntu using PyQt4

I'm getting started with PyQt4 and tested the following code... import sys from PyQt4 import QtGui from PyQt4 import QtCore class Tooltip(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Tooltip') self.s...

python: how to define a structure like in C

I am going to define a structure and pass it into a function: In C: struct stru { int a; int b; }; s = new stru() s->a = 10; func_a(s); How this can be done in Python? ...

Python: how to pass a reference to a function

IMO python is pass by value if the parameter is basic types, like number, boolean func_a(bool_value): bool_value = True Will not change the outside bool_value, right? So my question is how can I make the bool_value change takes effect in the outside one(pass by reference? ...

Sortable tables in Django

I read some of the other posts about this and some recommendations involved javascript and using other libraries. I did something quick by hand, but I'm new to Django and Python for that matter so I'm curious if this isn't a good way to do it. HTML <table> <tr> <td><a href="?sort=to">To</a></td> <td><a...

how to crawl a 403 forbidden SNS

i'm crawling an SNS with crawler written in python it works for a long time, but few days ago, the webpages got from my severs were ERROR 403 FORBIDDEN. i tried to change the cookie, change the browser, change the account, but all failed. and it seems that are the forbidden severs are in the same network segment. what can i do? steal...

python subclass access to class variable of parent

I was surprised to to learn that a class variable of a subclass can't access a class variable of the parent without specifically indicating the class name of the parent: >>> class A(object): ... x = 0 ... >>> class B(A): ... y = x+1 ... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", ...

Python: Nested for loops or "next" statement

I'm a rookie hobbyist and I nest for loops when I write python, like so: dict = { key1: {subkey/value1: value2} ... keyn: {subkeyn/valuen: valuen+1} } for key in dict: for subkey/value in key: do it to it I'm aware of a "next" keyword that would accomplish the same goal in one line (I asked a question abo...

Issue Replacing Already Existing Strings with ConfigParser

I am using ConfigParser to save simple settings to a .ini file, and one of these settings is a directory. Whenever I replace a directory string such as D:/Documents/Data, with a shorter directory string such as D:/, the remaining characters are placed two lines under the option. So the .ini file now looks like this: [Settings] director...

Python Lxml - Append a existing xml with new data

I am new to python/lxml After reading the lxml site and dive into python I could not find the solution to my n00b troubles. I have the below xml sample: --------------- <addressbook> <person> <name>Eric Idle</name> <phone type='fix'>999-999-999</phone> <phone type='mobile'>555-555-555</phone> <address...

SQLAlchemy context sesitive function for creating a composite value on insert and update

I'm trying to sort out how to add a context sensitive function (e.g. def get_user_full_name()) that will get triggered from the default and onupdate specifications on a column. I'm trying to set a composite field that combines the first and last names into a single full name value to avoid having to constantly concat the two fields in a...

python threadpool problem (wait for something)

I wrote simple web site crowler with threadpool. The problem is: then crawler is get all over site it must finish, but in real it wait for something in the end,and script dont finished, why this happend? from Queue import Queue from threading import Thread import sys from urllib import urlopen from BeautifulSoup import BeautifulSoup, S...

DB-API with Python

I just spent the better half of my day trying to figure this one out so please for the love of god, help me. I'm trying to insert some data into a local MySQL database by using MySQL Connector/Python -- apparently the only way to integrate MySQL into Python 3 without breaking out the C Compiler. I tried all the examples that come with ...

python - strange behavior question

>>> class S(object): ... def __init__(self): ... self.x = 1 ... def x(self): ... return self.x ... >>> s = S() >>> s.x 1 >>> s.x() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not callable Why, in this example, is s.x a method, but also an integer? I...

Why isn't web2py more readily adopted?

I have been playing with python and different web frameworks. I started with Django, but am not in so deep that I am entrenched. I really quite like python but have not found that "perfect" web solution. My qualifications of perfect would be: simple to learn/code simple to host (my webhost, Site5, isn't exactly python-friendly) wide...

How do I use an anonymous function within a class method in Python (closure) ?

class Test: def somemethod(self): def write(): print 'hello' write() x = Test() x.somemethod() write() is a function that will be used several times through somemethod(). somemethod() is the only function within the class that will require it's use so it seems silly to define it outside of somemethod(...

Broken Pipe when Using Python Multiprocessing Managers (BaseManager/SyncManager) to Share Queue with Remote Machines

In the last month, we've had a persistent problem with the Python 2.6.x multiprocessing package when we've tried to use it to share a queue among several different (linux) computers. I've posed this question directly to Jesse Noller as well since we haven't yet found anything that elucidates the issue on StackOverflow, Python docs, sour...

JPype compile problems

Hi, I'm having a right old nightmare with JPype. I have got my dev env on Windows and so tried installing it there with no luck. I then tried on Ubunto also with no luck. I'm getting a bit desperate now. I am using Mingw32 since I tried installing VS2008 but it told me I had to install XP SP2 but I am on Vista. I tried VS2010 but no luc...